Sha256: dddc29ccbc4c00e8039c520582f509ae1f8ff250b4ee9a3cb0e06ebb1f6d91f8

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

# encoding: utf-8
module Nokaya

  class TVShow < Basic

    require 'tvdb_party'

    NOKAYA_TVDB_API_KEY = 'C9493DA27231C706'

    attr_accessor :language, :poster_url, :banner_url, :plot, :title

    def initialize(args, options = {})
      super(args, options)
      @type = :tvshow
      @language = 'en'
      begin
        @tvdb = TvdbParty::Search.new(NOKAYA_TVDB_API_KEY)
      rescue SocketError
        Logs.rec.error Status.no_cnx
        return nil
      end
      terms = args.join(' ')
      show_obj = find(terms, options)
      return nil if show_obj.nil?
      create_details(show_obj)
      @urls = [@poster_url, @banner_url]
      @filenames = name_files()
    end

    private

    def name_files
      @urls.map do |url|
        "#{@type.to_s}-#{name}-#{File.basename(url)}"
      end
    end

    def find(title, options)
      res = @tvdb.search(title)
      unless options[:alt]
        if !res[0].nil?
          return @tvdb.get_series_by_id(res[0]['seriesid'])
        elsif !res[1].nil?
          return @tvdb.get_series_by_id(res[1]['seriesid'])
        end
      else
        if !res[1].nil?
          return @tvdb.get_series_by_id(res[1]['seriesid'])
        elsif !res[2].nil?
          return @tvdb.get_series_by_id(res[2]['seriesid'])
        end
      end
      return nil
    end

    def create_details(show_obj)
      @title = show_obj.name
      @name = @workers.sanitize(@title)
      @poster_url = find_poster_url(show_obj)
      @banner_url = find_banner_url(show_obj)
      @plot = find_plot(show_obj)
      @year = show_obj.first_aired.year
      @ref_url = "http://imdb.com/title/#{show_obj.imdb_id}/"
    end

    def find_poster_url(show_obj)
      poster = show_obj.posters(@language).first
      return poster.url
    end

    def find_banner_url(show_obj)
      banner = show_obj.series_banners(@language).first
      return banner.url
    end

    def find_plot(show_obj)
      show_obj.overview
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nokaya-0.1.6 lib/nokaya/tvshow.rb
nokaya-0.1.5 lib/nokaya/tvshow.rb