Class: MyShows::Episode

Inherits:
Object
  • Object
show all
Defined in:
lib/my_shows/episode.rb

Constant Summary collapse

MAPPING_SHOW_NAMES =
Hash.new { |hash, key| hash[key] = key }
@@jarow =
FuzzyStringMatch::JaroWinkler.create(:native)
@@tracker =
ThePirateBayClient.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Episode

Returns a new instance of Episode.



13
14
15
16
17
# File 'lib/my_shows/episode.rb', line 13

def initialize(attributes = {})
  attributes.each do |name, value|
    send("#{name}=", value)
  end
end

Instance Attribute Details

#episodeObject

Returns the value of attribute episode.



11
12
13
# File 'lib/my_shows/episode.rb', line 11

def episode
  @episode
end

Returns the value of attribute magnet_link.



11
12
13
# File 'lib/my_shows/episode.rb', line 11

def magnet_link
  @magnet_link
end

#seasonObject

Returns the value of attribute season.



11
12
13
# File 'lib/my_shows/episode.rb', line 11

def season
  @season
end

#showObject

Returns the value of attribute show.



11
12
13
# File 'lib/my_shows/episode.rb', line 11

def show
  @show
end

Instance Method Details

#to_sObject



51
52
53
# File 'lib/my_shows/episode.rb', line 51

def to_s
  '%s s%02de%02d' % [MAPPING_SHOW_NAMES[show.name], season, episode]
end

#torrent_link!Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/my_shows/episode.rb', line 19

def torrent_link!
  special_authors = %w(PublicHD DIMENSION eztv \ )
  sizes           = %w(1080p 720p \ )

  special_authors.each do |author|
    sizes.each do |size|
      keyword = [author, size].join(' ')
      return self.magnet_link if torrent_link_with_ext_keyword(keyword)
    end
  end

  nil
end


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/my_shows/episode.rb', line 33

def torrent_link_with_ext_keyword(keyword)
  episode_search_query = "#{self.to_s} #{keyword}"
  MyShows.logger.info "Looking for '#{episode_search_query}' ..."

  begin
    torrents = @@tracker.search(episode_search_query)
    torrent  = torrents.sort_by do |t|
      @@jarow.getDistance(episode_search_query, t.name)
    end.reverse.first

    self.magnet_link = torrent && torrent.magnet_link
  rescue => e
    MyShows.logger.warn "Problem with looking torrent link for '#{episode_search_query}'"
    MyShows.logger.debug e.message
    nil
  end
end