Class: MyShows::Episode

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

Constant Summary collapse

@@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.



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

#episodeObject

Returns the value of attribute episode.



8
9
10
# File 'lib/my_shows/episode.rb', line 8

def episode
  @episode
end

Returns the value of attribute magnet_link.



8
9
10
# File 'lib/my_shows/episode.rb', line 8

def magnet_link
  @magnet_link
end

#seasonObject

Returns the value of attribute season.



8
9
10
# File 'lib/my_shows/episode.rb', line 8

def season
  @season
end

#showObject

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_sObject



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!
  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
end


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.message
    nil
  end
end