download_tv 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -2
- data/Rakefile +8 -8
- data/bin/tv +76 -76
- data/download_tv.gemspec +18 -17
- data/lib/download_tv.rb +13 -13
- data/lib/download_tv/configuration.rb +64 -64
- data/lib/download_tv/downloader.rb +184 -191
- data/lib/download_tv/grabbers/addic7ed.rb +48 -53
- data/lib/download_tv/grabbers/eztv.rb +19 -22
- data/lib/download_tv/grabbers/kat.rb +21 -25
- data/lib/download_tv/grabbers/torrentapi.rb +60 -66
- data/lib/download_tv/grabbers/tpb.rb +22 -26
- data/lib/download_tv/linkgrabber.rb +25 -31
- data/lib/download_tv/myepisodes.rb +78 -86
- data/lib/download_tv/subtitles.rb +14 -19
- data/lib/download_tv/torrent.rb +69 -83
- data/lib/download_tv/version.rb +1 -1
- data/test/config_test.rb +168 -170
- data/test/downloader_test.rb +166 -182
- data/test/grabbers_test.rb +38 -44
- data/test/test_helper.rb +15 -15
- data/test/torrent_test.rb +22 -25
- metadata +2 -2
data/test/downloader_test.rb
CHANGED
@@ -1,184 +1,168 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
describe DownloadTV::Downloader do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
RbConfig::CONFIG['host_os'] = "dummy"
|
170
|
-
|
171
|
-
dl = DownloadTV::Downloader.new(0, path: config_path)
|
172
|
-
|
173
|
-
begin
|
174
|
-
run_silently { dl.detect_os.must_equal "xdg-open" }
|
175
|
-
flunk
|
176
|
-
rescue SystemExit
|
177
|
-
|
178
|
-
end
|
179
|
-
|
180
|
-
RbConfig::CONFIG['host_os'] = prev
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
end
|
4
|
+
config_path = File.realdirpath("#{__dir__}/test_config")
|
5
|
+
|
6
|
+
before do
|
7
|
+
Dir.chdir(__dir__)
|
8
|
+
create_dummy_config(config_path) unless File.exist?(config_path)
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
File.delete(config_path) if File.exist?(config_path)
|
13
|
+
end
|
14
|
+
|
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
|
+
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'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'the fix_names method' do
|
33
|
+
it 'should remove apostrophes, colons and parens' do
|
34
|
+
shows = ['Mr. Foo S01E02', 'Bar (UK) S00E22', "Let's S05E03", 'Baz: The Story S05E22']
|
35
|
+
result = ['Mr. Foo S01E02', 'Bar S00E22', 'Lets S05E03', 'Baz The Story S05E22']
|
36
|
+
|
37
|
+
dl = DownloadTV::Downloader.new(0, ignored: [], path: config_path)
|
38
|
+
dl.fix_names(shows).must_equal result
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should remove ignored shows' do
|
42
|
+
shows = ['Mr. Foo S01E02', 'Bar (UK) S00E22', 'Ignored S20E22', "Let's S05E03"]
|
43
|
+
result = ['Mr. Foo S01E02', 'Bar S00E22', 'Lets S05E03']
|
44
|
+
|
45
|
+
dl = DownloadTV::Downloader.new(0, ignored: ['ignored'], path: config_path)
|
46
|
+
dl.fix_names(shows).must_equal result
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'the check_date method' do
|
51
|
+
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 } }
|
54
|
+
to_run.must_raise SystemExit
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'uses the offset to adjust the date' do
|
58
|
+
# Would exit with offset 0
|
59
|
+
dl = DownloadTV::Downloader.new(1, date: Date.today, path: config_path)
|
60
|
+
|
61
|
+
date = dl.check_date
|
62
|
+
|
63
|
+
date.must_equal(Date.today - 1)
|
64
|
+
dl.config[:date].must_equal Date.today
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'the filter_shows method' do
|
69
|
+
it 'removes names with 2160p in them' do
|
70
|
+
dl = DownloadTV::Downloader.new(0, path: config_path)
|
71
|
+
links = [['Link 1', ''], ['Link 2 2160p', ''], ['Link 3', '']]
|
72
|
+
res = [['Link 1', ''], ['Link 3', '']]
|
73
|
+
dl.filter_shows(links).must_equal res
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'removes names with 1080p in them' do
|
77
|
+
dl = DownloadTV::Downloader.new(0, path: config_path)
|
78
|
+
links = [['Link.1080p', ''], ['Link 2 2160p', ''], ['Link 3', '']]
|
79
|
+
res = [['Link 3', '']]
|
80
|
+
dl.filter_shows(links).must_equal res
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'removes names with 720p in them' do
|
84
|
+
dl = DownloadTV::Downloader.new(0, path: config_path)
|
85
|
+
links = [['Link 1', ''], ['Link 2 720p', ''], ['Link.720p.rip', '']]
|
86
|
+
res = [['Link 1', '']]
|
87
|
+
dl.filter_shows(links).must_equal res
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'removes names with WEB in them' do
|
91
|
+
dl = DownloadTV::Downloader.new(0, path: config_path)
|
92
|
+
links = [['Link 1 WEBRIP', ''], ['Link 2 rip', ''], ['Link.720p.rip', '']]
|
93
|
+
res = [['Link 2 rip', '']]
|
94
|
+
dl.filter_shows(links).must_equal res
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'removes names without PROPER or REPACK in them' do
|
98
|
+
dl = DownloadTV::Downloader.new(0, path: config_path)
|
99
|
+
links = [['Link 1', ''], ['Link 2 2160p', ''], ['Link 3', ''], ['Link 4 PROPER', ''], ['Link REPACK 5', '']]
|
100
|
+
res = [['Link 4 PROPER', ''], ['Link REPACK 5', '']]
|
101
|
+
dl.filter_shows(links).must_equal res
|
102
|
+
end
|
103
|
+
|
104
|
+
it "doesn't apply a filter if it would reject every option" do
|
105
|
+
dl = DownloadTV::Downloader.new(0, path: config_path)
|
106
|
+
links = [['Link 1 720p', ''], ['Link 2 2160p', ''], ['Link 720p 3', '']]
|
107
|
+
res = [['Link 1 720p', ''], ['Link 720p 3', '']]
|
108
|
+
dl.filter_shows(links).must_equal res
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'the get_link method' do
|
113
|
+
it "returns an empty string when it can't find links" do
|
114
|
+
t = Minitest::Mock.new
|
115
|
+
show = 'Example Show S01E01'
|
116
|
+
|
117
|
+
t.expect(:get_links, [], [show])
|
118
|
+
dl = DownloadTV::Downloader.new(0, auto: true, path: config_path)
|
119
|
+
dl.get_link(t, show).must_equal ''
|
120
|
+
t.expect(:get_links, [], [show])
|
121
|
+
dl = DownloadTV::Downloader.new(0, auto: false, path: config_path)
|
122
|
+
dl.get_link(t, show).must_equal ''
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'returns the first link when auto is set to true' do
|
126
|
+
t = Minitest::Mock.new
|
127
|
+
show = 'Example Show S01E01'
|
128
|
+
|
129
|
+
t.expect(:get_links, [['Name 1', 'Link 1'], ['Name 2', 'Link 2']], [show])
|
130
|
+
dl = DownloadTV::Downloader.new(0, auto: true, path: config_path)
|
131
|
+
dl.get_link(t, show).must_equal 'Link 1'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe 'the detect_os method' do
|
136
|
+
it 'returns xdg open for linux' do
|
137
|
+
prev = RbConfig::CONFIG['host_os']
|
138
|
+
RbConfig::CONFIG['host_os'] = 'linux-gnu'
|
139
|
+
|
140
|
+
dl = DownloadTV::Downloader.new(0, path: config_path)
|
141
|
+
dl.detect_os.must_equal 'xdg-open'
|
142
|
+
|
143
|
+
RbConfig::CONFIG['host_os'] = prev
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'returns open for mac' do
|
147
|
+
prev = RbConfig::CONFIG['host_os']
|
148
|
+
RbConfig::CONFIG['host_os'] = 'darwin15.6.0'
|
149
|
+
|
150
|
+
dl = DownloadTV::Downloader.new(0, path: config_path)
|
151
|
+
dl.detect_os.must_equal 'open'
|
152
|
+
|
153
|
+
RbConfig::CONFIG['host_os'] = prev
|
154
|
+
end
|
155
|
+
|
156
|
+
it "exits when it can't detect the platform" do
|
157
|
+
prev = RbConfig::CONFIG['host_os']
|
158
|
+
RbConfig::CONFIG['host_os'] = 'dummy'
|
159
|
+
|
160
|
+
dl = DownloadTV::Downloader.new(0, path: config_path)
|
161
|
+
|
162
|
+
to_run = -> { run_silently { dl.detect_os.must_equal 'xdg-open' } }
|
163
|
+
to_run.must_raise SystemExit
|
164
|
+
|
165
|
+
RbConfig::CONFIG['host_os'] = prev
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
data/test/grabbers_test.rb
CHANGED
@@ -1,46 +1,40 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
describe DownloadTV::LinkGrabber do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
->{ DownloadTV::LinkGrabber.new("").get_links("test") }.must_raise NotImplementedError
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
end
|
4
|
+
grabbers = DownloadTV::Torrent.new.grabbers
|
5
|
+
instances = grabbers.map { |g| (DownloadTV.const_get g).new }
|
6
|
+
|
7
|
+
instances.each do |grabber|
|
8
|
+
describe grabber do
|
9
|
+
it 'will have a url attribute on creation' do
|
10
|
+
grabber.url.wont_be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should get a 200 code response' do
|
14
|
+
grabber.test_connection.code.must_equal '200'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "will raise NoTorrentsError when torrent can't be found" do
|
18
|
+
notfound = -> { grabber.get_links('Totally Fake Show askjdgsaudas') }
|
19
|
+
notfound.must_raise DownloadTV::NoTorrentsError
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'will return an array with names and links of results when a torrent can be found' do
|
23
|
+
result = grabber.get_links('Game Of Thrones S04E01')
|
24
|
+
result.must_be_instance_of Array
|
25
|
+
result.wont_be :empty?
|
26
|
+
result.each do |r|
|
27
|
+
r.size.must_equal 2
|
28
|
+
r[0].must_be_instance_of String
|
29
|
+
r[0].upcase.must_include 'THRONES'
|
30
|
+
r[1].must_be_instance_of String
|
31
|
+
r[1].must_include 'magnet:'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "raises an error if the instance doesn't implement get_links" do
|
38
|
+
-> { DownloadTV::LinkGrabber.new('').get_links('test') }.must_raise NotImplementedError
|
39
|
+
end
|
40
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(
|
2
|
-
require
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'download_tv'
|
3
|
+
require 'minitest/autorun'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def create_dummy_config(in_path, config={})
|
8
|
-
config[:version] = DownloadTV::VERSION if !config[:version]
|
9
|
-
File.open(in_path, "wb") { |f| Marshal.dump(config, f) }
|
5
|
+
def create_dummy_config(in_path, config = {})
|
6
|
+
config[:version] = DownloadTV::VERSION unless config[:version]
|
7
|
+
File.open(in_path, 'wb') { |f| Marshal.dump(config, f) }
|
10
8
|
end
|
11
9
|
|
12
10
|
def run_silently
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
previous_stdout = $stdout
|
12
|
+
$stdout = StringIO.new
|
13
|
+
previous_stderr = $stderr
|
14
|
+
$stderr = StringIO.new
|
15
|
+
yield
|
16
|
+
$stdout.string
|
17
17
|
ensure
|
18
|
-
|
19
|
-
|
20
|
-
end
|
18
|
+
$stdout = previous_stdout
|
19
|
+
$stderr = previous_stderr
|
20
|
+
end
|