download_tv 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd060f362bcaa6f8150f6e766ff4f8d882666b8d
4
- data.tar.gz: ddc3287c2df8cfb98d5bc5b39b8e559099721bee
3
+ metadata.gz: f8dda689a52414ffbba9c500ddd35c559726b77e
4
+ data.tar.gz: 34a781bc82bde130397290dc0038bbb3e842198d
5
5
  SHA512:
6
- metadata.gz: 68b70848a669d493ec77c5e12d5d82acb4627161cc5ca975d8c0650d5ea17a82bce1c56657ad278bfff903680e0c0b11f668d7ce3c2031e51abfc1452fc44859
7
- data.tar.gz: 8cd0a1e1732d280c842c867c0f6ae5227fb8fd7d495481b5e7a147cf3c06956a96100ce31c25be734143cd498c4ebdc89f645d028eedf43095e4375dfcdf950a
6
+ metadata.gz: ab18d3786f2b7ca4b7a5757355f50a7e1cfcfb871e375dc165841e8212a2518b48d64970a0a069699fecbf6b6b422880bf15704d53b8f87b68b168790d72d8b6
7
+ data.tar.gz: c5cbe9275f0174e56da29fa4ba3f90054e663b05f1dc2633b36dc05254af3c3cf74dec11f3db5f80996975f27add8e1d1f231525d0556ff796dc37f214b875ec
data/README.md CHANGED
@@ -37,7 +37,7 @@ Specific options:
37
37
 
38
38
  By default, it fetches the list of episodes from MyEpisodes.com that have aired since the program was run for the last time and tries to download them. The -o flag can be used in order to re-download the episodes from previous days. The --dry-run option is useful to prevent download_tv from updating the date (for example, when running the application shortly after an episode airs)
39
39
 
40
- In order to download a single episode, use the -d flag: *tv -d Breaking Bad S04E01*
40
+ In order to download a single episode, use the -d flag, quoting the string when it contains spaces: *tv -d "Breaking Bad S04E01"*
41
41
 
42
42
  The -f flag can be used to read the list of episodes to download from a file. Each line of the file is interpreted as a episode to download: *tv -f /path/to/listofeps*
43
43
 
data/bin/tv CHANGED
@@ -74,13 +74,13 @@ opt_parser.parse!(ARGV)
74
74
  begin
75
75
  case options[:cmd]
76
76
  when 'run'
77
- dl = DownloadTV::Downloader.new(options[:offset], config)
78
- dl.run(options[:dry])
77
+ dl = DownloadTV::Downloader.new(config)
78
+ dl.run(options[:dry], options[:offset].abs)
79
79
  when 'dl'
80
- dl = DownloadTV::Downloader.new(options[:offset], config)
80
+ dl = DownloadTV::Downloader.new(config)
81
81
  dl.download_single_show(options[:arg])
82
82
  when 'file'
83
- dl = DownloadTV::Downloader.new(options[:offset], config)
83
+ dl = DownloadTV::Downloader.new(config)
84
84
  dl.download_from_file(options[:arg])
85
85
  when 'config'
86
86
  DownloadTV::Configuration.new(config, true)
@@ -90,4 +90,7 @@ begin
90
90
  rescue Interrupt
91
91
  puts 'Interrupt signal detected. Exiting...'
92
92
  exit 1
93
+ rescue SocketError, Errno::ECONNRESET, Net::OpenTimeout
94
+ warn 'Connection error.'
95
+ exit 1
93
96
  end
@@ -1,11 +1,13 @@
1
1
  module DownloadTV
2
+ ##
3
+ # Class used for managing the configuration of the application
2
4
  class Configuration
3
5
  attr_reader :content, :config_path
4
-
5
- def initialize(content={}, force_change=false)
6
- FileUtils.mkdir_p(File.join(ENV["HOME"], ".config", "download_tv"))
7
- @config_path = content[:path] || File.join(ENV["HOME"], ".config", "download_tv", "config")
8
-
6
+
7
+ def initialize(content = {}, force_change = false)
8
+ FileUtils.mkdir_p(File.join(ENV['HOME'], '.config', 'download_tv'))
9
+ @config_path = content[:path] || File.join(ENV['HOME'], '.config', 'download_tv', 'config')
10
+
9
11
  if File.exist? @config_path
10
12
  load_config
11
13
  @content.merge!(content) unless content.empty?
@@ -17,48 +19,52 @@ module DownloadTV
17
19
  end
18
20
  end
19
21
 
20
-
21
22
  def change_configuration
22
23
  if @content[:myepisodes_user]
23
24
  print "Enter your MyEpisodes username (#{@content[:myepisodes_user]}) : "
24
25
  else
25
- print "Enter your MyEpisodes username: "
26
+ print 'Enter your MyEpisodes username: '
26
27
  end
27
28
  @content[:myepisodes_user] = STDIN.gets.chomp
28
29
 
29
- print "Save cookie? (y)/n: "
30
- @content[:cookie] = STDIN.gets.chomp.downcase != "n"
30
+ print 'Save cookie? (y)/n: '
31
+ @content[:cookie] = !(STDIN.gets.chomp.casecmp? 'n')
31
32
 
32
33
  if @content[:ignored]
33
34
  puts "Enter a comma-separated list of shows to ignore: (#{@content[:ignored]})"
34
35
  else
35
- puts "Enter a comma-separated list of shows to ignore: "
36
+ puts 'Enter a comma-separated list of shows to ignore: '
36
37
  end
37
-
38
- @content[:ignored] = STDIN.gets.chomp.split(",").map(&:strip).map(&:downcase)
38
+
39
+ @content[:ignored] = STDIN.gets.chomp.split(',').map(&:strip).map(&:downcase)
39
40
  STDOUT.flush
40
41
 
41
42
  # When modifying existing config, keeps previous values
42
43
  # When creating new one, sets defaults
43
44
  @content[:auto] ||= true
44
45
  @content[:subs] ||= true
45
- @content[:grabber] ||= "TorrentAPI"
46
- @content[:date] ||= Date.today-1
46
+ @content[:grabber] ||= 'TorrentAPI'
47
+ @content[:date] ||= Date.today - 1
47
48
  @content[:version] = DownloadTV::VERSION
48
49
 
49
50
  serialize
50
51
  end
51
52
 
52
-
53
53
  def serialize
54
- File.open(@config_path, "wb") { |f| Marshal.dump(@content, f) }
54
+ File.write(@config_path, JSON.generate(@content))
55
55
  end
56
56
 
57
57
  def load_config
58
- @content = File.open(@config_path, "rb") { |f| Marshal.load(f) }
59
- if !@content[:version] || breaking_changes?(@content[:version])
60
- change_configuration
61
- end
58
+ source = File.read(@config_path)
59
+ @content = JSON.parse(source, symbolize_names: true)
60
+
61
+ @content[:date] = Date.parse(@content[:date]) if @content[:date]
62
+
63
+ change_configuration if !@content[:version] || breaking_changes?(@content[:version])
64
+ rescue JSON::ParserError
65
+ @content = {}
66
+ change_configuration
67
+ retry
62
68
  end
63
69
 
64
70
  ##
@@ -66,12 +72,11 @@ module DownloadTV
66
72
  # Returns false if a patch has been detected
67
73
  # Returns nil if it's the same version
68
74
  def breaking_changes?(version)
69
- DownloadTV::VERSION.split(".").zip(version.split(".")).find_index { |x, y| y > x }&.< 2
75
+ DownloadTV::VERSION.split('.').zip(version.split('.')).find_index { |x, y| y > x }&.< 2
70
76
  end
71
-
72
77
 
73
78
  def print_config
74
- @content.each {|k, v| puts "#{k}: #{v}"}
79
+ @content.each { |k, v| puts "#{k}: #{v}" }
75
80
  end
76
81
  end
77
- end
82
+ end
@@ -4,8 +4,7 @@ module DownloadTV
4
4
  class Downloader
5
5
  attr_reader :offset, :config
6
6
 
7
- def initialize(offset = 0, config = {})
8
- @offset = offset.abs
7
+ def initialize(config = {})
9
8
  @config = Configuration.new(config) # Load configuration
10
9
 
11
10
  @filters = [
@@ -39,8 +38,8 @@ module DownloadTV
39
38
  ##
40
39
  # Finds download links for all new episodes aired since the last run of the program
41
40
  # It connects to MyEpisodes in order to find which shows to track and which new episodes aired.
42
- def run(dont_update_last_run)
43
- date = check_date
41
+ def run(dont_update_last_run, offset = 0)
42
+ date = check_date(offset)
44
43
 
45
44
  myepisodes = MyEpisodes.new(@config.content[:myepisodes_user], @config.content[:cookie])
46
45
  # Log in using cookie by default
@@ -120,10 +119,10 @@ module DownloadTV
120
119
  end
121
120
  end
122
121
 
123
- def check_date
122
+ def check_date(offset)
124
123
  last = @config.content[:date]
125
- if last - @offset != Date.today
126
- last - @offset
124
+ if last - offset != Date.today
125
+ last - offset
127
126
  else
128
127
  puts 'Everything up to date'
129
128
  exit
@@ -10,6 +10,16 @@ module DownloadTV
10
10
  @wait = 2.1
11
11
  end
12
12
 
13
+ ##
14
+ # Specific implementation for TorrentAPI (requires token)
15
+ def online?
16
+ @agent.read_timeout = 2
17
+ @agent.get(format(@url, 'test', 'test'))
18
+ true
19
+ rescue Mechanize::ResponseCodeError, Net::HTTP::Persistent::Error
20
+ false
21
+ end
22
+
13
23
  ##
14
24
  # Connects to Torrentapi.org and requests a token.
15
25
  # Returns said token.
@@ -54,9 +64,6 @@ module DownloadTV
54
64
  links = obj['torrent_results'].collect { |i| i['download'] }
55
65
 
56
66
  names.zip(links)
57
- # Temporary solution for Cloudflare being obnoxious
58
- rescue Mechanize::ResponseCodeError
59
- raise NoTorrentsError
60
67
  end
61
68
  end
62
69
  end
@@ -2,7 +2,7 @@ module DownloadTV
2
2
  ##
3
3
  # ThePirateBay grabber
4
4
  class ThePirateBay < LinkGrabber
5
- def initialize(tpb_proxy = 'https://pirateproxy.cc')
5
+ def initialize(tpb_proxy = 'https://thepiratebay.cr')
6
6
  proxy = tpb_proxy.gsub(%r{/+$}, '') || 'https://thepiratebay.cr'
7
7
 
8
8
  super("#{proxy}/search/%s/0/7/0")
@@ -7,20 +7,19 @@ module DownloadTV
7
7
  def initialize(url)
8
8
  @url = url
9
9
  @agent = Mechanize.new
10
+ @agent.user_agent = DownloadTV::USER_AGENT
10
11
  end
11
12
 
12
- def test_connection
13
- agent = Mechanize.new
14
- agent.read_timeout = 2
15
- agent.get(@url)
13
+ def online?
14
+ @agent.read_timeout = 2
15
+ @agent.get(format(@url, 'test'))
16
+ true
17
+ rescue Mechanize::ResponseCodeError, Net::HTTP::Persistent::Error
18
+ false
16
19
  end
17
20
 
18
21
  def get_links(_s)
19
22
  raise NotImplementedError
20
23
  end
21
24
  end
22
-
23
- class NoTorrentsError < StandardError; end
24
-
25
- class NoSubtitlesError < StandardError; end
26
25
  end
@@ -4,6 +4,7 @@ module DownloadTV
4
4
  class MyEpisodes
5
5
  def initialize(user, save_cookie)
6
6
  @agent = Mechanize.new
7
+ @agent.user_agent = DownloadTV::USER_AGENT
7
8
  @user = user
8
9
  @save_cookie = save_cookie
9
10
  @cookie_path = File.join(ENV['HOME'], '.config', 'download_tv', 'cookie')
@@ -2,7 +2,7 @@ module DownloadTV
2
2
  ##
3
3
  # Class in charge of managing the link grabbers
4
4
  class Torrent
5
- attr_reader :g_names, :g_instances, :n_grabbers
5
+ attr_reader :g_names, :g_instances, :tries
6
6
 
7
7
  def grabbers
8
8
  %w[Eztv KAT ThePirateBay TorrentAPI]
@@ -11,11 +11,11 @@ module DownloadTV
11
11
  def initialize(default_grabber = nil)
12
12
  @g_names = grabbers
13
13
  @g_instances = []
14
- @n_grabbers = @g_names.size # Initial size
15
- @tries = @n_grabbers - 1
14
+ reset_tries
16
15
 
17
16
  # Silently ignores bad names
18
- @g_names.rotate! @g_names.find_index(default_grabber).to_i + 1
17
+ found = @g_names.find_index(default_grabber)
18
+ @g_names.rotate! found + 1 if found
19
19
 
20
20
  change_grabbers
21
21
  end
@@ -24,47 +24,43 @@ module DownloadTV
24
24
  if !@g_names.empty?
25
25
  # Instantiates the last element from g_names, popping it
26
26
  newt = (DownloadTV.const_get @g_names.pop).new
27
- newt.test_connection
28
27
 
29
- @g_instances.unshift newt
30
-
31
- else
32
- # Rotates the instantiated grabbers
28
+ if newt.online?
29
+ @g_instances.unshift newt
30
+ else
31
+ warn "Problem accessing #{newt.class.name}"
32
+ @tries -= 1 # We won't be using this grabber
33
+ change_grabbers
34
+ end
35
+ else # Rotates the instantiated grabbers
33
36
  @g_instances.rotate!
34
37
  end
35
- rescue Mechanize::ResponseCodeError, Net::HTTP::Persistent::Error
36
- warn "Problem accessing #{newt.class.name}"
37
- # We won't be using this grabber
38
- @n_grabbers -= 1
39
- @tries = @n_grabbers - 1
40
-
41
- change_grabbers
42
- rescue SocketError, Errno::ECONNRESET, Net::OpenTimeout
43
- warn 'Connection error.'
44
- exit 1
45
38
  end
46
39
 
47
40
  def get_links(show)
48
41
  links = @g_instances.first.get_links(show)
49
42
 
50
- # Reset the counter
51
- @tries = @n_grabbers - 1
43
+ reset_tries
52
44
 
53
45
  links
54
46
  rescue NoTorrentsError
55
47
  puts "No torrents found for #{show} using #{@g_instances.first.class.name}"
56
48
 
57
49
  # Use next grabber
58
- if @tries > 0
50
+ if @tries.positive?
59
51
  @tries -= 1
60
52
  change_grabbers
61
53
  retry
62
54
 
63
- else # Reset the counter
64
- @tries = @n_grabbers - 1
55
+ else
56
+ reset_tries
65
57
  # Handle show not found here!!
66
58
  return []
67
59
  end
68
60
  end
61
+
62
+ def reset_tries
63
+ @tries = @g_names.size + @g_instances.size - 1
64
+ end
69
65
  end
70
66
  end
@@ -1,3 +1,3 @@
1
1
  module DownloadTV
2
- VERSION = '2.2.2'.freeze
2
+ VERSION = '2.3.0'.freeze
3
3
  end
data/lib/download_tv.rb CHANGED
@@ -11,4 +11,13 @@ require 'download_tv/torrent'
11
11
  require 'download_tv/myepisodes'
12
12
  require 'download_tv/linkgrabber'
13
13
  require 'download_tv/subtitles'
14
+
15
+ module DownloadTV
16
+ USER_AGENT = "DownloadTV #{DownloadTV::VERSION}".freeze
17
+
18
+ class NoTorrentsError < StandardError; end
19
+
20
+ class NoSubtitlesError < StandardError; end
21
+ end
22
+
14
23
  Dir[File.join(__dir__, 'download_tv', 'grabbers', '*.rb')].each { |file| require file }
data/test/config_test.rb CHANGED
@@ -132,14 +132,17 @@ describe DownloadTV::Configuration do
132
132
  end
133
133
 
134
134
  describe 'the serialize method' do
135
- it 'stores the configuration in a Marshalled file' do
135
+ it 'stores the configuration in a JSON file' do
136
136
  # Calls serialize
137
137
  run_silently do
138
138
  STDIN.stub :gets, 'anything' do
139
139
  DownloadTV::Configuration.new(path: config_path)
140
140
  end
141
141
  end
142
- content = File.open(config_path, 'rb') { |f| Marshal.load(f) }
142
+ # content = File.open(config_path, 'rb') { |f| Marshal.load(f) }
143
+ source = File.read(config_path)
144
+ content = JSON.parse(source, symbolize_names: true)
145
+ content[:date] = Date.parse(content[:date])
143
146
 
144
147
  content[:cookie].must_equal true
145
148
  content[:myepisodes_user].must_equal 'anything'
@@ -147,7 +150,7 @@ describe DownloadTV::Configuration do
147
150
  content[:auto].must_equal true
148
151
  content[:subs].must_equal true
149
152
  content[:grabber].must_equal 'TorrentAPI'
150
- content[:date].must_equal(Date.today - 1)
153
+ content[:date].must_equal Date.today - 1
151
154
  content[:version].must_equal DownloadTV::VERSION
152
155
  end
153
156
  end
@@ -13,19 +13,10 @@ describe DownloadTV::Downloader do
13
13
  end
14
14
 
15
15
  describe 'when creating the object' do
16
- it 'should store the first argument as @offset' do
17
- DownloadTV::Downloader.new(3, path: config_path).offset.must_equal 3
18
- DownloadTV::Downloader.new(-3, path: config_path).offset.must_equal 3
19
- end
20
-
21
- it 'should receive an integer for the offset' do
22
- -> { DownloadTV::Downloader.new('foo') }.must_raise NoMethodError
23
- end
24
-
25
16
  it 'can receive an optional configuration hash' do
26
- dl = DownloadTV::Downloader.new(0, auto: true, grabber: 'KAT', path: config_path)
27
- dl.config[:auto].must_equal true
28
- dl.config[:grabber].must_equal 'KAT'
17
+ dl = DownloadTV::Downloader.new(auto: true, grabber: 'KAT', path: config_path)
18
+ dl.config.content[:auto].must_equal true
19
+ dl.config.content[:grabber].must_equal 'KAT'
29
20
  end
30
21
  end
31
22
 
@@ -34,7 +25,7 @@ describe DownloadTV::Downloader do
34
25
  shows = ['Mr. Foo S01E02', 'Bar (UK) S00E22', "Let's S05E03", 'Baz: The Story S05E22']
35
26
  result = ['Mr. Foo S01E02', 'Bar S00E22', 'Lets S05E03', 'Baz The Story S05E22']
36
27
 
37
- dl = DownloadTV::Downloader.new(0, ignored: [], path: config_path)
28
+ dl = DownloadTV::Downloader.new(ignored: [], path: config_path)
38
29
  dl.fix_names(shows).must_equal result
39
30
  end
40
31
 
@@ -42,67 +33,67 @@ describe DownloadTV::Downloader do
42
33
  shows = ['Mr. Foo S01E02', 'Bar (UK) S00E22', 'Ignored S20E22', "Let's S05E03"]
43
34
  result = ['Mr. Foo S01E02', 'Bar S00E22', 'Lets S05E03']
44
35
 
45
- dl = DownloadTV::Downloader.new(0, ignored: ['ignored'], path: config_path)
36
+ dl = DownloadTV::Downloader.new(ignored: ['ignored'], path: config_path)
46
37
  dl.fix_names(shows).must_equal result
47
38
  end
48
39
  end
49
40
 
50
41
  describe 'the check_date method' do
51
42
  it 'exits the script when up to date' do
52
- dl = DownloadTV::Downloader.new(0, date: Date.today, path: config_path)
53
- to_run = -> { run_silently { dl.check_date } }
43
+ dl = DownloadTV::Downloader.new(date: Date.today, path: config_path)
44
+ to_run = -> { run_silently { dl.check_date(0) } }
54
45
  to_run.must_raise SystemExit
55
46
  end
56
47
 
57
48
  it 'uses the offset to adjust the date' do
58
49
  # Would exit with offset 0
59
- dl = DownloadTV::Downloader.new(1, date: Date.today, path: config_path)
50
+ dl = DownloadTV::Downloader.new(date: Date.today, path: config_path)
60
51
 
61
- date = dl.check_date
52
+ date = dl.check_date(1)
62
53
 
63
54
  date.must_equal(Date.today - 1)
64
- dl.config[:date].must_equal Date.today
55
+ dl.config.content[:date].must_equal Date.today
65
56
  end
66
57
  end
67
58
 
68
59
  describe 'the filter_shows method' do
69
60
  it 'removes names with 2160p in them' do
70
- dl = DownloadTV::Downloader.new(0, path: config_path)
61
+ dl = DownloadTV::Downloader.new(path: config_path)
71
62
  links = [['Link 1', ''], ['Link 2 2160p', ''], ['Link 3', '']]
72
63
  res = [['Link 1', ''], ['Link 3', '']]
73
64
  dl.filter_shows(links).must_equal res
74
65
  end
75
66
 
76
67
  it 'removes names with 1080p in them' do
77
- dl = DownloadTV::Downloader.new(0, path: config_path)
68
+ dl = DownloadTV::Downloader.new(path: config_path)
78
69
  links = [['Link.1080p', ''], ['Link 2 2160p', ''], ['Link 3', '']]
79
70
  res = [['Link 3', '']]
80
71
  dl.filter_shows(links).must_equal res
81
72
  end
82
73
 
83
74
  it 'removes names with 720p in them' do
84
- dl = DownloadTV::Downloader.new(0, path: config_path)
75
+ dl = DownloadTV::Downloader.new(path: config_path)
85
76
  links = [['Link 1', ''], ['Link 2 720p', ''], ['Link.720p.rip', '']]
86
77
  res = [['Link 1', '']]
87
78
  dl.filter_shows(links).must_equal res
88
79
  end
89
80
 
90
81
  it 'removes names with WEB in them' do
91
- dl = DownloadTV::Downloader.new(0, path: config_path)
82
+ dl = DownloadTV::Downloader.new(path: config_path)
92
83
  links = [['Link 1 WEBRIP', ''], ['Link 2 rip', ''], ['Link.720p.rip', '']]
93
84
  res = [['Link 2 rip', '']]
94
85
  dl.filter_shows(links).must_equal res
95
86
  end
96
87
 
97
88
  it 'removes names without PROPER or REPACK in them' do
98
- dl = DownloadTV::Downloader.new(0, path: config_path)
89
+ dl = DownloadTV::Downloader.new(path: config_path)
99
90
  links = [['Link 1', ''], ['Link 2 2160p', ''], ['Link 3', ''], ['Link 4 PROPER', ''], ['Link REPACK 5', '']]
100
91
  res = [['Link 4 PROPER', ''], ['Link REPACK 5', '']]
101
92
  dl.filter_shows(links).must_equal res
102
93
  end
103
94
 
104
95
  it "doesn't apply a filter if it would reject every option" do
105
- dl = DownloadTV::Downloader.new(0, path: config_path)
96
+ dl = DownloadTV::Downloader.new(path: config_path)
106
97
  links = [['Link 1 720p', ''], ['Link 2 2160p', ''], ['Link 720p 3', '']]
107
98
  res = [['Link 1 720p', ''], ['Link 720p 3', '']]
108
99
  dl.filter_shows(links).must_equal res
@@ -115,11 +106,12 @@ describe DownloadTV::Downloader do
115
106
  show = 'Example Show S01E01'
116
107
 
117
108
  t.expect(:get_links, [], [show])
118
- dl = DownloadTV::Downloader.new(0, auto: true, path: config_path)
109
+ dl = DownloadTV::Downloader.new(auto: true, path: config_path)
119
110
  dl.get_link(t, show).must_equal ''
120
111
  t.expect(:get_links, [], [show])
121
- dl = DownloadTV::Downloader.new(0, auto: false, path: config_path)
112
+ dl = DownloadTV::Downloader.new(auto: false, path: config_path)
122
113
  dl.get_link(t, show).must_equal ''
114
+ t.verify
123
115
  end
124
116
 
125
117
  it 'returns the first link when auto is set to true' do
@@ -127,8 +119,9 @@ describe DownloadTV::Downloader do
127
119
  show = 'Example Show S01E01'
128
120
 
129
121
  t.expect(:get_links, [['Name 1', 'Link 1'], ['Name 2', 'Link 2']], [show])
130
- dl = DownloadTV::Downloader.new(0, auto: true, path: config_path)
122
+ dl = DownloadTV::Downloader.new(auto: true, path: config_path)
131
123
  dl.get_link(t, show).must_equal 'Link 1'
124
+ t.verify
132
125
  end
133
126
  end
134
127
 
@@ -137,7 +130,7 @@ describe DownloadTV::Downloader do
137
130
  prev = RbConfig::CONFIG['host_os']
138
131
  RbConfig::CONFIG['host_os'] = 'linux-gnu'
139
132
 
140
- dl = DownloadTV::Downloader.new(0, path: config_path)
133
+ dl = DownloadTV::Downloader.new(path: config_path)
141
134
  dl.detect_os.must_equal 'xdg-open'
142
135
 
143
136
  RbConfig::CONFIG['host_os'] = prev
@@ -147,7 +140,7 @@ describe DownloadTV::Downloader do
147
140
  prev = RbConfig::CONFIG['host_os']
148
141
  RbConfig::CONFIG['host_os'] = 'darwin15.6.0'
149
142
 
150
- dl = DownloadTV::Downloader.new(0, path: config_path)
143
+ dl = DownloadTV::Downloader.new(path: config_path)
151
144
  dl.detect_os.must_equal 'open'
152
145
 
153
146
  RbConfig::CONFIG['host_os'] = prev
@@ -157,7 +150,7 @@ describe DownloadTV::Downloader do
157
150
  prev = RbConfig::CONFIG['host_os']
158
151
  RbConfig::CONFIG['host_os'] = 'dummy'
159
152
 
160
- dl = DownloadTV::Downloader.new(0, path: config_path)
153
+ dl = DownloadTV::Downloader.new(path: config_path)
161
154
 
162
155
  to_run = -> { run_silently { dl.detect_os.must_equal 'xdg-open' } }
163
156
  to_run.must_raise SystemExit
@@ -6,14 +6,12 @@ describe DownloadTV::LinkGrabber do
6
6
 
7
7
  instances.each do |grabber|
8
8
  describe grabber do
9
+ next unless grabber.online?
10
+
9
11
  it 'will have a url attribute on creation' do
10
12
  grabber.url.wont_be_nil
11
13
  end
12
14
 
13
- it 'should get a 200 code response' do
14
- grabber.test_connection.code.must_equal '200'
15
- end
16
-
17
15
  it "will raise NoTorrentsError when torrent can't be found" do
18
16
  notfound = -> { grabber.get_links('Totally Fake Show askjdgsaudas') }
19
17
  notfound.must_raise DownloadTV::NoTorrentsError
data/test/test_helper.rb CHANGED
@@ -4,7 +4,7 @@ require 'minitest/autorun'
4
4
 
5
5
  def create_dummy_config(in_path, config = {})
6
6
  config[:version] = DownloadTV::VERSION unless config[:version]
7
- File.open(in_path, 'wb') { |f| Marshal.dump(config, f) }
7
+ File.write(in_path, JSON.generate(config))
8
8
  end
9
9
 
10
10
  def run_silently
data/test/torrent_test.rb CHANGED
@@ -1,28 +1,44 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe DownloadTV::Torrent do
4
- before do
5
- @t = DownloadTV::Torrent.new
6
- end
7
-
8
4
  describe 'when creating the object' do
9
- it 'will have some grabbers' do
10
- @t.g_names.empty?.must_equal false
11
- @t.g_instances.empty?.must_equal false
12
- @t.n_grabbers.must_be :>, 0
5
+ before do
6
+ @t = DownloadTV::Torrent.new
13
7
  end
14
8
 
15
9
  it 'will have the right amount of grabbers' do
16
- # Initiakize calls change_grabbers
17
- @t.n_grabbers.must_equal @t.g_names.size + 1
10
+ @t.g_names.size.must_equal @t.grabbers.size - 1
18
11
  @t.g_instances.size.must_equal 1
19
12
  end
20
13
 
21
14
  it 'will populate the instances' do
22
- @t.n_grabbers.times.each { @t.change_grabbers }
15
+ @t.grabbers.size.times.each { @t.change_grabbers }
23
16
  @t.g_names.empty?.must_equal true
24
- @t.g_instances.empty?.must_equal false
25
- @t.g_instances.size.must_equal @t.n_grabbers
17
+ @t.g_instances.size.must_equal @t.grabbers.size
18
+ end
19
+
20
+ it 'will start with all tries available' do
21
+ @t.tries.must_equal @t.grabbers.size - 1
22
+ end
23
+
24
+ it 'will call get_links on its grabber' do
25
+ @t.g_instances.first.stub :get_links, %w[test result] do
26
+ @t.get_links('test show').must_equal %w[test result]
27
+ end
28
+ end
29
+ end
30
+
31
+ describe 'when giving it a default grabber' do
32
+ it 'has a default order' do
33
+ t = DownloadTV::Torrent.new(nil)
34
+ t.g_instances.first.class.name.must_equal 'DownloadTV::TorrentAPI'
35
+ end
36
+
37
+ %w[Eztv KAT ThePirateBay TorrentAPI].each do |g|
38
+ it 'correctly uses the given grabber first' do
39
+ t = DownloadTV::Torrent.new(g)
40
+ t.g_instances.first.class.name.must_equal "DownloadTV::#{g}"
41
+ end
26
42
  end
27
43
  end
28
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: download_tv
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - guille
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-06 00:00:00.000000000 Z
11
+ date: 2017-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.6.12
137
+ rubygems_version: 2.6.13
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: DownloadTV is a tool that allows the user to find magnet links for tv show