Class: MyShows::Episode
- Inherits:
-
Object
- Object
- MyShows::Episode
- Defined in:
- lib/my_shows/episode.rb
Constant Summary collapse
- @@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.
10 11 12 13 14 |
# File 'lib/my_shows/episode.rb', line 10 def initialize(attributes = {}) attributes.each do |name, value| send("#{name}=", value) end end |
Instance Attribute Details
#episode ⇒ Object
Returns the value of attribute episode.
8 9 10 |
# File 'lib/my_shows/episode.rb', line 8 def episode @episode end |
#magnet_link ⇒ Object
Returns the value of attribute magnet_link.
8 9 10 |
# File 'lib/my_shows/episode.rb', line 8 def magnet_link @magnet_link end |
#season ⇒ Object
Returns the value of attribute season.
8 9 10 |
# File 'lib/my_shows/episode.rb', line 8 def season @season end |
#show ⇒ Object
Returns the value of attribute show.
8 9 10 |
# File 'lib/my_shows/episode.rb', line 8 def show @show end |
Instance Method Details
#to_s ⇒ Object
46 47 48 |
# File 'lib/my_shows/episode.rb', line 46 def to_s '%s s%02de%02d' % [show.name, season, episode] end |
#torrent_link! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/my_shows/episode.rb', line 16 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 end |
#torrent_link_with_ext_keyword(keyword) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/my_shows/episode.rb', line 28 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 |