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
@@ -1,87 +1,79 @@
|
|
1
1
|
module DownloadTV
|
2
|
-
|
3
|
-
|
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
|
-
end
|
82
|
-
|
83
|
-
class InvalidLoginError < StandardError
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
2
|
+
##
|
3
|
+
# API wrapper for MyEpisodes
|
4
|
+
class MyEpisodes
|
5
|
+
def initialize(user, save_cookie)
|
6
|
+
@agent = Mechanize.new
|
7
|
+
@user = user
|
8
|
+
@save_cookie = save_cookie
|
9
|
+
@cookie_path = File.join(ENV['HOME'], '.config', 'download_tv', 'cookie')
|
10
|
+
end
|
11
|
+
|
12
|
+
def login
|
13
|
+
if !@user || @user == ''
|
14
|
+
print 'Enter your MyEpisodes username: '
|
15
|
+
@user = STDIN.gets.chomp
|
16
|
+
end
|
17
|
+
|
18
|
+
print 'Enter your MyEpisodes password: '
|
19
|
+
pass = STDIN.noecho(&:gets).chomp
|
20
|
+
puts
|
21
|
+
|
22
|
+
page = @agent.get 'https://www.myepisodes.com/login.php'
|
23
|
+
|
24
|
+
login_form = page.forms[1]
|
25
|
+
login_form.username = @user
|
26
|
+
login_form.password = pass
|
27
|
+
|
28
|
+
page = @agent.submit(login_form, login_form.buttons.first)
|
29
|
+
|
30
|
+
raise InvalidLoginError if page.filename == 'login.php'
|
31
|
+
|
32
|
+
save_cookie if @save_cookie
|
33
|
+
|
34
|
+
@agent
|
35
|
+
end
|
36
|
+
|
37
|
+
def load_cookie
|
38
|
+
if File.exist? @cookie_path
|
39
|
+
@agent.cookie_jar.load @cookie_path
|
40
|
+
page = @agent.get 'https://www.myepisodes.com/login.php'
|
41
|
+
if page.links[1].text == 'Register'
|
42
|
+
puts 'The cookie is invalid/has expired.'
|
43
|
+
login
|
44
|
+
end
|
45
|
+
@agent
|
46
|
+
else
|
47
|
+
puts 'Cookie file not found'
|
48
|
+
login
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def save_cookie
|
53
|
+
@agent.cookie_jar.save(@cookie_path, session: true)
|
54
|
+
@agent
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_shows(last)
|
58
|
+
page = @agent.get 'https://www.myepisodes.com/ajax/service.php?mode=view_privatelist'
|
59
|
+
shows = page.parser.css('tr.past')
|
60
|
+
|
61
|
+
s = shows.select do |i|
|
62
|
+
airdate = i.css('td.date')[0].text
|
63
|
+
Date.parse(airdate) >= last
|
64
|
+
end
|
65
|
+
|
66
|
+
s.map do |i|
|
67
|
+
name = i.css('td.showname').text
|
68
|
+
ep = i.css('td.longnumber').text
|
69
|
+
|
70
|
+
ep.insert(0, 'S')
|
71
|
+
ep.sub!('x', 'E')
|
72
|
+
|
73
|
+
"#{name} #{ep}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class InvalidLoginError < StandardError; end
|
79
|
+
end
|
@@ -1,20 +1,15 @@
|
|
1
1
|
module DownloadTV
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
2
|
+
##
|
3
|
+
# Manages the subtitles (WIP)
|
4
|
+
class Subtitles
|
5
|
+
def initialize
|
6
|
+
@a = Addic7ed.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_subs(show)
|
10
|
+
@a.get_subs(show)
|
11
|
+
rescue NoSubtitlesError
|
12
|
+
puts "No subtitles found for #{show}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/download_tv/torrent.rb
CHANGED
@@ -1,84 +1,70 @@
|
|
1
1
|
module DownloadTV
|
2
|
-
|
3
|
-
|
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
|
-
else # Reset the counter
|
73
|
-
@tries = @n_grabbers - 1
|
74
|
-
# Handle show not found here!!
|
75
|
-
return []
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
2
|
+
##
|
3
|
+
# Class in charge of managing the link grabbers
|
4
|
+
class Torrent
|
5
|
+
attr_reader :g_names, :g_instances, :n_grabbers
|
6
|
+
|
7
|
+
def grabbers
|
8
|
+
%w[Eztv KAT ThePirateBay TorrentAPI]
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(default_grabber = nil)
|
12
|
+
@g_names = grabbers
|
13
|
+
@g_instances = []
|
14
|
+
@n_grabbers = @g_names.size # Initial size
|
15
|
+
@tries = @n_grabbers - 1
|
16
|
+
|
17
|
+
# Silently ignores bad names
|
18
|
+
@g_names.rotate! @g_names.find_index(default_grabber).to_i + 1
|
19
|
+
|
20
|
+
change_grabbers
|
21
|
+
end
|
22
|
+
|
23
|
+
def change_grabbers
|
24
|
+
if !@g_names.empty?
|
25
|
+
# Instantiates the last element from g_names, popping it
|
26
|
+
newt = (DownloadTV.const_get @g_names.pop).new
|
27
|
+
newt.test_connection
|
28
|
+
|
29
|
+
@g_instances.unshift newt
|
30
|
+
|
31
|
+
else
|
32
|
+
# Rotates the instantiated grabbers
|
33
|
+
@g_instances.rotate!
|
34
|
+
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
|
+
end
|
46
|
+
|
47
|
+
def get_links(show)
|
48
|
+
links = @g_instances.first.get_links(show)
|
49
|
+
|
50
|
+
# Reset the counter
|
51
|
+
@tries = @n_grabbers - 1
|
52
|
+
|
53
|
+
links
|
54
|
+
rescue NoTorrentsError
|
55
|
+
puts "No torrents found for #{show} using #{@g_instances.first.class.name}"
|
56
|
+
|
57
|
+
# Use next grabber
|
58
|
+
if @tries > 0
|
59
|
+
@tries -= 1
|
60
|
+
change_grabbers
|
61
|
+
retry
|
62
|
+
|
63
|
+
else # Reset the counter
|
64
|
+
@tries = @n_grabbers - 1
|
65
|
+
# Handle show not found here!!
|
66
|
+
return []
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/download_tv/version.rb
CHANGED
data/test/config_test.rb
CHANGED
@@ -1,172 +1,170 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
describe DownloadTV::Configuration 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
|
-
|
170
|
-
|
171
|
-
|
172
|
-
end
|
4
|
+
config_path = File.realdirpath("#{__dir__}/test_config")
|
5
|
+
|
6
|
+
before do
|
7
|
+
Dir.chdir(__dir__)
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
File.delete(config_path) if File.exist?(config_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'when the file already exists' do
|
15
|
+
it 'will load the existing configuration (blank)' do
|
16
|
+
create_dummy_config(config_path)
|
17
|
+
|
18
|
+
c = DownloadTV::Configuration.new(path: config_path)
|
19
|
+
c.content.must_equal(path: config_path, version: DownloadTV::VERSION)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'will load the existing configuration (existing)' do
|
23
|
+
create_dummy_config(config_path, auto: false, myepisodes_user: 'dummy')
|
24
|
+
|
25
|
+
c = DownloadTV::Configuration.new(path: config_path)
|
26
|
+
c.content.must_equal(path: config_path, auto: false, myepisodes_user: 'dummy', version: DownloadTV::VERSION)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'will get overwritten by the parameters given' do
|
30
|
+
create_dummy_config(config_path, myepisodes_user: 'dummy')
|
31
|
+
|
32
|
+
c = DownloadTV::Configuration.new(path: config_path, myepisodes_user: 'fake')
|
33
|
+
c.content.must_equal(path: config_path, myepisodes_user: 'fake', version: DownloadTV::VERSION)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'will downcase ignored shows' do
|
37
|
+
create_dummy_config(config_path, ignored: %w[duMMy String])
|
38
|
+
|
39
|
+
c = DownloadTV::Configuration.new(path: config_path)
|
40
|
+
c.content[:ignored].must_equal %w[dummy string]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'the breaking_changes method' do
|
45
|
+
it 'returns nil when both versions are equal' do
|
46
|
+
create_dummy_config(config_path)
|
47
|
+
|
48
|
+
c = DownloadTV::Configuration.new(path: config_path)
|
49
|
+
c.breaking_changes?(DownloadTV::VERSION).must_be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns true when there's been a major update" do
|
53
|
+
create_dummy_config(config_path)
|
54
|
+
|
55
|
+
split = DownloadTV::VERSION.split('.')
|
56
|
+
split[0] = (split[0].to_i + 1).to_s
|
57
|
+
new_version = split.join('.')
|
58
|
+
c = DownloadTV::Configuration.new(path: config_path)
|
59
|
+
c.breaking_changes?(new_version).must_equal true
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns true when there's been a minor update" do
|
63
|
+
create_dummy_config(config_path)
|
64
|
+
|
65
|
+
split = DownloadTV::VERSION.split('.')
|
66
|
+
split[1] = (split[1].to_i + 1).to_s
|
67
|
+
new_version = split.join('.')
|
68
|
+
c = DownloadTV::Configuration.new(path: config_path)
|
69
|
+
c.breaking_changes?(new_version).must_equal true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns false when it's a small patch" do
|
73
|
+
create_dummy_config(config_path)
|
74
|
+
|
75
|
+
split = DownloadTV::VERSION.split('.')
|
76
|
+
split[2] = (split[2].to_i + 1).to_s
|
77
|
+
new_version = split.join('.')
|
78
|
+
c = DownloadTV::Configuration.new(path: config_path)
|
79
|
+
c.breaking_changes?(new_version).must_equal false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "when the file doesn't exist" do
|
84
|
+
it 'will create a new one' do
|
85
|
+
run_silently do
|
86
|
+
STDIN.stub :gets, 'myepisodes\ncookie\nignored' do
|
87
|
+
DownloadTV::Configuration.new(path: config_path)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
File.exist?(config_path).must_equal true
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'will have the right values' do
|
95
|
+
c = nil
|
96
|
+
run_silently do
|
97
|
+
STDIN.stub :gets, 'anything' do
|
98
|
+
c = DownloadTV::Configuration.new(path: config_path)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
c.content[:myepisodes_user].must_equal 'anything'
|
103
|
+
c.content[:cookie].must_equal true
|
104
|
+
c.content[:ignored].must_equal ['anything']
|
105
|
+
c.content[:auto].must_equal true
|
106
|
+
c.content[:subs].must_equal true
|
107
|
+
c.content[:grabber].must_equal 'TorrentAPI'
|
108
|
+
c.content[:date].must_equal(Date.today - 1)
|
109
|
+
c.content[:version].must_equal DownloadTV::VERSION
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'will set the cookie value to false when explicitly told so' do
|
113
|
+
c = nil
|
114
|
+
run_silently do
|
115
|
+
STDIN.stub :gets, 'n' do
|
116
|
+
c = DownloadTV::Configuration.new(path: config_path)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
c.content[:cookie].must_equal false
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'will separate the ignored values by commas' do
|
124
|
+
c = nil
|
125
|
+
run_silently do
|
126
|
+
STDIN.stub :gets, 'ignored1, itsgone, ignored 2' do
|
127
|
+
c = DownloadTV::Configuration.new(path: config_path)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
c.content[:ignored].must_equal ['ignored1', 'itsgone', 'ignored 2']
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'the serialize method' do
|
135
|
+
it 'stores the configuration in a Marshalled file' do
|
136
|
+
# Calls serialize
|
137
|
+
run_silently do
|
138
|
+
STDIN.stub :gets, 'anything' do
|
139
|
+
DownloadTV::Configuration.new(path: config_path)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
content = File.open(config_path, 'rb') { |f| Marshal.load(f) }
|
143
|
+
|
144
|
+
content[:cookie].must_equal true
|
145
|
+
content[:myepisodes_user].must_equal 'anything'
|
146
|
+
content[:ignored].must_equal ['anything']
|
147
|
+
content[:auto].must_equal true
|
148
|
+
content[:subs].must_equal true
|
149
|
+
content[:grabber].must_equal 'TorrentAPI'
|
150
|
+
content[:date].must_equal(Date.today - 1)
|
151
|
+
content[:version].must_equal DownloadTV::VERSION
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe 'the constructor' do
|
156
|
+
it 'will trigger a configuration change when asked to' do
|
157
|
+
create_dummy_config(config_path, auto: false)
|
158
|
+
File.exist?(config_path).must_equal true
|
159
|
+
c = nil
|
160
|
+
|
161
|
+
run_silently do
|
162
|
+
STDIN.stub :gets, 'anything' do
|
163
|
+
c = DownloadTV::Configuration.new(path: config_path)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
c.content[:auto].must_equal false
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|