Class: Videoinfo::Videos::Tv

Inherits:
Videoinfo::Video show all
Defined in:
lib/videoinfo/videos/tv.rb

Instance Attribute Summary collapse

Attributes inherited from Videoinfo::Video

#file, #name, #screenshots

Instance Method Summary collapse

Methods inherited from Videoinfo::Video

#capture_screenshots, #initialize, #read_mediainfo

Constructor Details

This class inherits a constructor from Videoinfo::Video

Instance Attribute Details

#episode_numberObject (readonly)

Returns the value of attribute episode_number.



5
6
7
# File 'lib/videoinfo/videos/tv.rb', line 5

def episode_number
  @episode_number
end

#episode_stringObject (readonly)

Returns the value of attribute episode_string.



5
6
7
# File 'lib/videoinfo/videos/tv.rb', line 5

def episode_string
  @episode_string
end

#season_numberObject (readonly)

Returns the value of attribute season_number.



5
6
7
# File 'lib/videoinfo/videos/tv.rb', line 5

def season_number
  @season_number
end

Instance Method Details

#name=(n) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/videoinfo/videos/tv.rb', line 66

def name=(n)
  @episode_string = n.slice!(/(\AS\d{2,3}E\d{2,3}\ |\ S\d{2,3}E\d{2,3}\z|\AS\d{2,3}\ |\ S\d{2,3}\z)/i)
  @name           = n

  if @episode_string
    @episode_string.strip!
    @season_number, @episode_number = @episode_string.gsub(/[SE]/i, ' ').split
  end

  @name
end

#populate_result!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/videoinfo/videos/tv.rb', line 11

def populate_result!
  result.mediainfo = read_mediainfo

  serie = search_imdb.first
  if serie
    result.imdb_id   = serie.id
    result.title     = serie.title
    result.plot      = serie.plot
    result.rating    = serie.rating
    result.genres    = serie.genres
    result.country   = serie.countries.first
    result.premiered = serie.year

    if season_number
      season = serie.season(season_number.to_i)
      if season
        result.season_number = season.season_number
        if episode_number
          episode = season.episode(episode_number.to_i)
          if episode
            result.episode_number  = episode.episode
            result.episode_imdb_id = episode.id
            result.episode_title   = episode.title
            result.episode_url     = episode.url
            result.episode_rating  = episode.rating
            result.air_date        = episode.air_date
          end
        end
      end
    end
  end

  result.screenshot_urls = capture_screenshots.map { |ss| Videoinfo.upload_screenshot(ss) }

  result
end

#resultObject



7
8
9
# File 'lib/videoinfo/videos/tv.rb', line 7

def result
  @result ||= Results::TvResult.new
end

#search_imdbObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/videoinfo/videos/tv.rb', line 48

def search_imdb
  series = []
  begin
    series = Imdb::Search.new(name, :tv).movies
  rescue => e
    raise Error, "could not search IMDB. #{e.message}"
  end

  return series.map { |s| Imdb::Serie.new(s.id) } unless Videoinfo.interactive?

  series.each do |s|
    STDERR.print "Is your series \"#{s.title}\" (tt#{s.id})? [Y/n] "
    return [Imdb::Serie.new(s.id)] if STDIN.gets.strip !~ /^(n|no)$/i
  end

  []
end