Class: MyShows::Episode
- Inherits:
-
Object
- Object
- MyShows::Episode
- 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
-
#episode ⇒ Object
Returns the value of attribute episode.
-
#magnet_link ⇒ Object
Returns the value of attribute magnet_link.
-
#season ⇒ Object
Returns the value of attribute season.
-
#show ⇒ Object
Returns the value of attribute show.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Episode
constructor
A new instance of Episode.
- #to_s ⇒ Object
- #torrent_link! ⇒ Object
- #torrent_link_with_ext_keyword(keyword) ⇒ Object
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
#episode ⇒ Object
Returns the value of attribute episode.
11 12 13 |
# File 'lib/my_shows/episode.rb', line 11 def episode @episode end |
#magnet_link ⇒ Object
Returns the value of attribute magnet_link.
11 12 13 |
# File 'lib/my_shows/episode.rb', line 11 def magnet_link @magnet_link end |
#season ⇒ Object
Returns the value of attribute season.
11 12 13 |
# File 'lib/my_shows/episode.rb', line 11 def season @season end |
#show ⇒ Object
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_s ⇒ Object
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! = %w(PublicHD DIMENSION eztv \ ) sizes = %w(1080p 720p \ ) .each do || sizes.each do |size| keyword = [, size].join(' ') return self.magnet_link if torrent_link_with_ext_keyword(keyword) end end nil end |
#torrent_link_with_ext_keyword(keyword) ⇒ Object
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. nil end end |