my_shows 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  require 'my_shows'
4
4
 
5
5
  # Output message to $stderr, prefixed with the program name
6
- def pute(message="")
6
+ def pute(message = '')
7
7
  $stderr.puts "#{$0}: #{message}"
8
8
  end
9
9
 
@@ -12,6 +12,6 @@ begin
12
12
 
13
13
  MyShows::CLI.start(ARGV)
14
14
  rescue Interrupt
15
- pute "Quitting..."
15
+ pute 'Quitting...'
16
16
  exit 1
17
17
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'my_shows/version'
5
5
 
6
- require "bundler/setup"
6
+ require 'bundler/setup'
7
7
 
8
8
  require 'netrc'
9
9
  require 'fuzzystringmatch'
@@ -29,21 +29,21 @@ module MyShows
29
29
  MyShows::Show.client = SidereelClient.new(*self.credentials)
30
30
  end
31
31
 
32
- def lookup_magnet_links shows
32
+ def lookup_magnet_links(shows)
33
33
  shows.map { |show|
34
34
  show.episode.torrent_link!
35
35
  }.compact
36
36
  end
37
37
 
38
- def enque_to_download links
38
+ def enque_to_download(links)
39
39
  links.each do |link|
40
- logger.debug "Enque #{link}"
40
+ logger.info "Enque #{URI(link).to_s}"
41
41
  sleep 5
42
- Launchy::Application::General.new.open(["#{URI(link).to_s}"])
42
+ Launchy::Application::General.new.open([URI(link).to_s])
43
43
  end
44
44
  end
45
45
 
46
- def start *args
46
+ def start(*args)
47
47
  print_header
48
48
  configure_client
49
49
  shows = Show.next_episodes
@@ -58,7 +58,7 @@ module MyShows
58
58
  end
59
59
 
60
60
  def print_episodes episodes
61
- puts "Next episodes:"
61
+ puts 'Next episodes:'
62
62
  episodes.each do |show|
63
63
  episode = show.episode
64
64
  puts "#{episode} [#{episode.magnet_link ? '✓'.colorize(:green) : '✗'.colorize(:red)}]"
@@ -2,7 +2,7 @@ require 'my_shows/the_pirate_bay_client'
2
2
 
3
3
  module MyShows
4
4
  class Episode
5
- @@jarow = FuzzyStringMatch::JaroWinkler.create(:native)
5
+ @@jarow = FuzzyStringMatch::JaroWinkler.create(:native)
6
6
  @@tracker = ThePirateBayClient.new
7
7
 
8
8
  attr_accessor :season, :episode, :show, :magnet_link
@@ -14,23 +14,37 @@ module MyShows
14
14
  end
15
15
 
16
16
  def torrent_link!
17
- episode_search_query = "#{self.to_s} PublicHD"
17
+ special_authors = %w(PublicHD DIMENSION eztv \ )
18
+ sizes = %w(1080p 720p \ )
19
+
20
+ special_authors.each do |author|
21
+ sizes.each do |size|
22
+ keyword = [author, size].join(' ')
23
+ return self.magnet_link if torrent_link_with_ext_keyword(keyword)
24
+ end
25
+ end
26
+ end
27
+
28
+ def torrent_link_with_ext_keyword(keyword)
29
+ episode_search_query = "#{self.to_s} #{keyword}"
18
30
  MyShows.logger.info "Looking for '#{episode_search_query}' ..."
19
31
 
20
32
  begin
21
33
  torrents = @@tracker.search(episode_search_query)
22
- torrent = torrents.sort_by { |t| @@jarow.getDistance(episode_search_query, t.name) }.reverse.first
34
+ torrent = torrents.sort_by do |t|
35
+ @@jarow.getDistance(episode_search_query, t.name)
36
+ end.reverse.first
23
37
 
24
38
  self.magnet_link = torrent && torrent.magnet_link
25
39
  rescue => e
26
- MyShows.logger.warn "Problem with looking torrent link"
40
+ MyShows.logger.warn "Problem with looking torrent link for '#{episode_search_query}'"
27
41
  MyShows.logger.debug e.message
28
42
  nil
29
43
  end
30
44
  end
31
45
 
32
46
  def to_s
33
- "%s s%02de%02d" % [show.name, season, episode]
47
+ '%s s%02de%02d' % [show.name, season, episode]
34
48
  end
35
49
  end
36
50
  end
@@ -4,7 +4,7 @@ require 'hashie'
4
4
 
5
5
  class ThePirateBayClient
6
6
  def connection
7
- @connection ||= Faraday.new url: 'http://thepiratebay.se' do |conn|
7
+ @connection ||= Faraday.new url: 'http://thepiratebay.is' do |conn|
8
8
  conn.headers[:user_agent] = 'libcurl-agent/1.0'
9
9
  conn.request :url_encoded
10
10
  conn.response :logger, MyShows.logger
@@ -12,14 +12,18 @@ class ThePirateBayClient
12
12
  end
13
13
  end
14
14
 
15
- def search query
15
+ def search(query)
16
16
  response = connection.get URI.escape("/search/#{query}/0/99/200")
17
- Nokogiri::HTML(response.body).css('#searchResult > tr td:nth-child(2)').map do |row|
18
- Hashie::Mash.new(name: row.at_css('.detName a').content, magnet_link: row.at_css('a[href^=magnet]')['href'])
17
+ html = Nokogiri::HTML(response.body)
18
+ html.css('#searchResult > tr').map do |row|
19
+ Hashie::Mash.new(name: row.at_css('.detName a').content,
20
+ magnet_link: row.at_css('a[href^=magnet]')['href'],
21
+ seeders: row.css('td')[-2].content.to_i)
19
22
  end
20
23
  end
21
24
  end
22
25
 
23
26
  if __FILE__ == $0
24
- p ThePirateBayClient.new.search('mike and molly')
27
+ require 'my_shows'
28
+ p ThePirateBayClient.new.search('The Mentalist s05e20 PublicHD')
25
29
  end
@@ -1,3 +1,3 @@
1
1
  module MyShows
2
- VERSION = "0.0.3"
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_shows
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-15 00:00:00.000000000 Z
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
@@ -162,12 +162,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
162
  - - ! '>='
163
163
  - !ruby/object:Gem::Version
164
164
  version: '0'
165
+ segments:
166
+ - 0
167
+ hash: 3563414062259935485
165
168
  required_rubygems_version: !ruby/object:Gem::Requirement
166
169
  none: false
167
170
  requirements:
168
171
  - - ! '>='
169
172
  - !ruby/object:Gem::Version
170
173
  version: '0'
174
+ segments:
175
+ - 0
176
+ hash: 3563414062259935485
171
177
  requirements: []
172
178
  rubyforge_project:
173
179
  rubygems_version: 1.8.25