download_tv 2.6.3 → 2.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +203 -0
- data/README.md +20 -16
- data/bin/tv +1 -1
- data/lib/download_tv/configuration.rb +18 -37
- data/lib/download_tv/downloader.rb +25 -20
- data/lib/download_tv/grabbers/eztv.rb +5 -19
- data/lib/download_tv/grabbers/torrentapi.rb +9 -13
- data/lib/download_tv/grabbers/torrentz2.rb +27 -0
- data/lib/download_tv/linkgrabber.rb +4 -3
- data/lib/download_tv/torrent.rb +9 -17
- data/lib/download_tv/version.rb +1 -1
- data/test/config_test.rb +0 -2
- data/test/downloader_test.rb +3 -3
- data/test/grabbers_test.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53e1d00a4065208736271ec9235dd6ed88e0d20c75f2b2b9c012efe8dc5483a4
|
4
|
+
data.tar.gz: 43acaa5871b39a7f26e0a52327f120c2f444b9c8d1418a5df7822cb107b38b23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 818ecba45c5ae4c8b7a81ac81938e5b224a09b0d6b57e85bc4056f48061eecfddc1777fcbe956917d2ea2f406902951d7b594df5915385dd1bf4f36f9d078b7d
|
7
|
+
data.tar.gz: 95941352f0583ff70b163bc0e5bc318d5237996064fa85a4048713eb4cff919497fc7755c410bfbd69b33f9c6d129792c2eafcf879894ba302f30d04161aa613
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
# download_tv CHANGELOG
|
2
|
+
|
3
|
+
## 2.6.4 (2021-06-07)
|
4
|
+
|
5
|
+
* Grabbers
|
6
|
+
* Torrentz: added Torrentz2 grabber.
|
7
|
+
|
8
|
+
## 2.6.3 (2021-05-24)
|
9
|
+
|
10
|
+
* Fixes
|
11
|
+
* Fix download full season feature (`-s/--season`), inadvertently broken in 2.6.2.
|
12
|
+
|
13
|
+
## 2.6.2 (2021-05-20)
|
14
|
+
|
15
|
+
* Fixes
|
16
|
+
* Avoid duplicate downloads when using `-t` and `-o` together.
|
17
|
+
|
18
|
+
* Improvements
|
19
|
+
* Add `-s` shorthand to the `--season` flag.
|
20
|
+
|
21
|
+
## 2.6.1 (2020-09-22)
|
22
|
+
|
23
|
+
* Features
|
24
|
+
* Add `-q/--queue` to manually add an episode to the pending list.
|
25
|
+
|
26
|
+
* Improvements
|
27
|
+
* Gracefully exits after option parsing errors.
|
28
|
+
|
29
|
+
* Grabbers
|
30
|
+
* EZTV: now sorts torrents by number of seeders.
|
31
|
+
* ThePirateBay: disable grabber.
|
32
|
+
|
33
|
+
## 2.5.5 (2019-04-06)
|
34
|
+
|
35
|
+
* Features
|
36
|
+
* Allow user to configure include/exclude filters of the results.
|
37
|
+
|
38
|
+
* Improvements
|
39
|
+
* The `-t/--tomorrow` flag now also performs a normal run if needed.
|
40
|
+
|
41
|
+
## 2.5.4 (2019-01-19)
|
42
|
+
|
43
|
+
* Features
|
44
|
+
* Add `--season` to try and sequentially download all episodes of the given show, for the given season.
|
45
|
+
* Add `-t/--tomorrow` to download the shows airing in the current day.
|
46
|
+
|
47
|
+
## 2.5.3 (2018-12-14)
|
48
|
+
|
49
|
+
* Fixes
|
50
|
+
* Fix bug preventing clearing pending shows from working properly.
|
51
|
+
|
52
|
+
## 2.5.2 (2018-12-10)
|
53
|
+
|
54
|
+
* Fixes
|
55
|
+
* Changing the configuration no longer resets the list of pending downloads.
|
56
|
+
|
57
|
+
## 2.5.1 (2018-12-03)
|
58
|
+
|
59
|
+
* Fixes
|
60
|
+
* Fix pending shows handling.
|
61
|
+
|
62
|
+
## 2.5.0 (2018-12-02)
|
63
|
+
|
64
|
+
* Fixes
|
65
|
+
* Fix not detecting successful MyEpisodes login.
|
66
|
+
* Fix not detecting non-backwards compatible version changes.
|
67
|
+
* Fix names not being sanitised when downloading through `-d/--download`
|
68
|
+
* Fix names not being sanitised when downloading through `-f/--file`
|
69
|
+
|
70
|
+
* Features
|
71
|
+
* Persist list of episodes not found in the configuration.
|
72
|
+
* Add `-p/--pending` to show the list of pending downloads.
|
73
|
+
* Add `--clear-pending` to empty the list of pending downloads.
|
74
|
+
|
75
|
+
* Grabbers
|
76
|
+
* KAT: disable grabber.
|
77
|
+
|
78
|
+
## 2.4.7 (2018-10-05)
|
79
|
+
|
80
|
+
* Grabbers
|
81
|
+
* KAT: re-enable grabber, updating rules for new CSS structure.
|
82
|
+
|
83
|
+
## 2.4.6 (2018-07-19)
|
84
|
+
|
85
|
+
* Grabbers
|
86
|
+
* KAT: disable grabber.
|
87
|
+
|
88
|
+
## 2.4.5 (2018-05-04)
|
89
|
+
|
90
|
+
* Grabbers
|
91
|
+
* TorrentAPI: now sorts by seeders.
|
92
|
+
|
93
|
+
## 2.4.4 (2018-03-22)
|
94
|
+
|
95
|
+
* Grabbers
|
96
|
+
* TorrentAPI: fix timeouts.
|
97
|
+
|
98
|
+
## 2.4.3 (2018-03-22)
|
99
|
+
|
100
|
+
* Fixes
|
101
|
+
* Fix new trackers' availability not being checked before attempting to use them.
|
102
|
+
|
103
|
+
## 2.4.2 (2018-03-14)
|
104
|
+
|
105
|
+
* Fixes
|
106
|
+
* Fix bug where the wrong grabber was being removed when offline.
|
107
|
+
|
108
|
+
## 2.4.1 (2018-03-12)
|
109
|
+
|
110
|
+
* Fixes
|
111
|
+
* Fix bug accessing wrong variable when a grabber was offline.
|
112
|
+
|
113
|
+
## 2.4.0 (2018-03-04)
|
114
|
+
|
115
|
+
* Fixes
|
116
|
+
* Fix not reporting "Nothing to download" when it was due to ignored shows.
|
117
|
+
* Fix downloading from file not handling newlines well.
|
118
|
+
|
119
|
+
* Improvements
|
120
|
+
* Reset grabber order after every download.
|
121
|
+
|
122
|
+
* Grabbers
|
123
|
+
* KAT: fix parsing rules.
|
124
|
+
* ThePirateBay: change proxy URL.
|
125
|
+
|
126
|
+
## 2.3.0 (2017-09-24)
|
127
|
+
|
128
|
+
* Improvements
|
129
|
+
* Store configuration file as JSON instead of Marshaling the hash.
|
130
|
+
* Use custom User-Agent for all connections.
|
131
|
+
|
132
|
+
* Grabbers
|
133
|
+
* ThePirateBay: change proxy URL.
|
134
|
+
|
135
|
+
## 2.2.2 (2017-08-06)
|
136
|
+
|
137
|
+
* Fixes
|
138
|
+
* Fix date not being saved in the configuration.
|
139
|
+
|
140
|
+
## 2.2.1 (2017-08-03)
|
141
|
+
|
142
|
+
* Add LICENSE.md to repo
|
143
|
+
|
144
|
+
* Fixes
|
145
|
+
* Fix default grabber not being properly selected.
|
146
|
+
|
147
|
+
* Improvements
|
148
|
+
* Add support for OS X.
|
149
|
+
|
150
|
+
* Grabbers
|
151
|
+
* TorrentAPI: add temporary workaround for CloudFlare errors.
|
152
|
+
|
153
|
+
## 2.2.0 (2017-08-01)
|
154
|
+
|
155
|
+
* Add LICENSE information to Gemfile
|
156
|
+
* Move default path to configuration file to `~/.config/download_tv/config`
|
157
|
+
|
158
|
+
* Improvements
|
159
|
+
* Improve detection of ignored shows.
|
160
|
+
|
161
|
+
## 2.1.1 (2017-07-31)
|
162
|
+
|
163
|
+
* Improvements
|
164
|
+
* Minor improvements to configuration file handling.
|
165
|
+
|
166
|
+
## 2.1.0 (2017-07-21)
|
167
|
+
|
168
|
+
* Features
|
169
|
+
* Add `-g/--grabber` to select which grabber to use for finding links.
|
170
|
+
* Add `--show-grabbers` to list available options.
|
171
|
+
* Add `-v` to print gem version.
|
172
|
+
|
173
|
+
* Grabbers
|
174
|
+
* KAT: added KickAssTorrents grabber.
|
175
|
+
|
176
|
+
## 2.0.6 (2017-07-11)
|
177
|
+
|
178
|
+
* Improvements
|
179
|
+
* Remove colons from the show name for searching.
|
180
|
+
|
181
|
+
## 2.0.5 (2017-06-17)
|
182
|
+
|
183
|
+
* Features
|
184
|
+
* Add `--show-config` to print contents of the configuration file in a readable way.
|
185
|
+
|
186
|
+
* Fixes
|
187
|
+
* Fix download from file not properly finding the path.
|
188
|
+
|
189
|
+
## 2.0.3 (2017-06-07)
|
190
|
+
|
191
|
+
* Fixes
|
192
|
+
* Fix missing arguments breaking the main entrypoint.
|
193
|
+
* Fix ignored shows list not handling multiple comma-separated shows.
|
194
|
+
* Minor fixes on configuration file.
|
195
|
+
|
196
|
+
## 2.0.0 (2017-06-07)
|
197
|
+
|
198
|
+
* Features
|
199
|
+
* Add new configuration system.
|
200
|
+
|
201
|
+
## 1.0.0 (2017-06-07)
|
202
|
+
|
203
|
+
Initial published version.
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# download_tv
|
2
2
|
|
3
|
-
![
|
3
|
+
[![Ruby](https://github.com/guille/download_tv/actions/workflows/ruby.yml/badge.svg?branch=master)](https://github.com/guille/download_tv/actions/workflows/ruby.yml)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/download_tv.svg)](https://badge.fury.io/rb/download_tv)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/guille/download_tv.svg)](https://codeclimate.com/github/guille/download_tv)
|
6
6
|
|
7
|
-
download_tv is a tool that allows the user to find magnet links for TV show episodes. It accepts shows as arguments, from a file or it can integrate with your MyEpisodes account.
|
7
|
+
**download_tv** is a tool that allows the user to find magnet links for TV show episodes. It accepts shows as arguments, from a file or it can integrate with your MyEpisodes account.
|
8
8
|
|
9
9
|
### Installation
|
10
10
|
|
@@ -38,49 +38,53 @@ Specific options:
|
|
38
38
|
|
39
39
|
### MyEpisodes integration
|
40
40
|
|
41
|
-
By default, download_tv connects to your MyEpisodes.com account and fetches the list of episodes that have aired since the program was run for the last time. It then tries to find magnet links to download each of these shows, using the link grabbers available. You can see the grabbers with the
|
41
|
+
By default, **download_tv** connects to your [MyEpisodes.com](https://www.myepisodes.com/) account and fetches the list of episodes that have aired since the program was run for the last time. It then tries to find magnet links to download each of these shows, using the link grabbers available. You can see the grabbers with the `--show-grabbers` option. These magnet links will be executed with whatever program you have configured to handle magnet:// files.
|
42
42
|
|
43
|
-
The
|
43
|
+
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).
|
44
44
|
|
45
|
-
|
45
|
+
The application also includes the `-t/--tomorrow` flag. By default, an execution of **download_tv** will download shows airing from the last execution of the program up to a day prior to the current day. This flag can be used to include in the search the episodes airing in the same day. This can be useful depending on your timezone or on the airtime of the shows you follow.
|
46
46
|
|
47
47
|
**Note**: Due to API limitations, the gem won't find shows aired more than 14 days prior to the execution of the script.
|
48
48
|
|
49
|
-
The options
|
49
|
+
The options `-c` and `--show-config` allow the user to change or view the current configuration values, respectively. These options include your MyEpisodes username, whether to save cookies or ask for password on each run and the list of ignored shows among other things. The gem (mostly) follows semver to track configuration file changes. It will automatically trigger a configuration update when it detects an older non-compatible version.
|
50
50
|
|
51
|
-
The
|
51
|
+
The `--auto` flag toggles whether all the results for each show are prompted to the user for him to choose or if the application should try to choose the download link automatically (see Section Filters). By default, all grabbers try to sort by number of seeders.
|
52
52
|
|
53
53
|
### Single torrent download
|
54
54
|
|
55
|
-
In order to download a single episode, use the
|
55
|
+
In order to download a single episode, use the `-d` flag, quoting the string when it contains spaces:
|
56
|
+
|
57
|
+
```
|
58
|
+
tv -d "Breaking Bad S04E01"
|
59
|
+
```
|
56
60
|
|
57
61
|
Although it uses some settings and grabbers specific for TV shows, this option can also be used as a quick way to find and download any torrent.
|
58
62
|
|
59
|
-
It can be used with the
|
63
|
+
It can be optionally used in conjunction with the `--season` flag to try to find and download a whole season of the given show: `tv -d "Breaking Bad" --season 4`. It will start searching from episode 1 and continue upwards until it can't find any torrent for an episode.
|
60
64
|
|
61
65
|
### Multi torrent download
|
62
66
|
|
63
|
-
The
|
67
|
+
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.
|
64
68
|
|
65
69
|
### Available link grabbers
|
66
70
|
|
67
|
-
With
|
71
|
+
With `-g` and `--show-grabbers`, the user can see what grabbers are available and choose one of these as their preferred option. By default, the application searches for torrents using TorrentAPI. When a grabber doesn't have a torrent for said episode, is offline, or causes any error to appear, it skips to the next grabber until exhausting the list.
|
68
72
|
|
69
73
|
I usually publish a patch update to the gem when I detect one of them isn't working, disabling it or fixing it altogether. If a specific grabber is giving you problems, check whether you're running the latest version of the gem before opening an issue here.
|
70
74
|
|
71
75
|
### Pending shows
|
72
76
|
|
73
|
-
download_tv
|
77
|
+
**download_tv** persists the list of shows it can't find on a given execution (when connecting to MyEpisodes, not for single show or file downloads) and it will try to find them again on following executions. This list can be viewed by passing the -p flag to the tv binary. The list can be cleared with the --clear-pending option.
|
74
78
|
|
75
|
-
|
79
|
+
It also has the functionality to queue an episode by running `tv --queue "show name"`. The --queue parameter cannot be used in conjunction with any other parameters.
|
76
80
|
|
77
81
|
### Filters
|
78
82
|
|
79
|
-
download_tv
|
83
|
+
**download_tv** allows setting include/exclude filters for the automatic download of shows.
|
80
84
|
|
81
|
-
|
85
|
+
Upon installation, the default filters exclude 2060p, 1080p or 720p, and include PROPER or REPACK releases when available. The user can specify in their configuration (`tv -c`) a list of words to include or exclude from their results that will override these defaults.
|
82
86
|
|
83
|
-
|
87
|
+
Keep in mind that this is not a hard filter. The application will sequentially apply as many user-defined filters as possible **while still returning at least one result**.
|
84
88
|
|
85
89
|
### License
|
86
90
|
|
data/bin/tv
CHANGED
@@ -115,7 +115,7 @@ begin
|
|
115
115
|
dl = DownloadTV::Downloader.new(config)
|
116
116
|
dl.run(options[:dry], options[:offset].abs, include_tomorrow: true)
|
117
117
|
when 'config'
|
118
|
-
DownloadTV::Configuration.new(config
|
118
|
+
DownloadTV::Configuration.new(config).change_configuration
|
119
119
|
when 'showconfig'
|
120
120
|
DownloadTV::Configuration.new(config).print_config
|
121
121
|
when 'showpending'
|
@@ -6,15 +6,14 @@ module DownloadTV
|
|
6
6
|
class Configuration
|
7
7
|
attr_reader :content, :config_path
|
8
8
|
|
9
|
-
def initialize(content = {}
|
10
|
-
FileUtils.mkdir_p(File.join(ENV['HOME'], '.config', 'download_tv'))
|
9
|
+
def initialize(content = {})
|
11
10
|
@config_path = content[:path] || default_config_path
|
11
|
+
FileUtils.mkdir_p(File.expand_path('..', @config_path))
|
12
12
|
|
13
13
|
if File.exist? @config_path
|
14
14
|
load_config
|
15
15
|
@content.merge!(content) unless content.empty?
|
16
16
|
@content[:ignored]&.map!(&:downcase)
|
17
|
-
change_configuration if force_change
|
18
17
|
else
|
19
18
|
@content = content
|
20
19
|
change_configuration
|
@@ -33,11 +32,8 @@ module DownloadTV
|
|
33
32
|
end
|
34
33
|
|
35
34
|
def prompt_for_myep_user
|
36
|
-
if @content[:myepisodes_user]
|
37
|
-
|
38
|
-
else
|
39
|
-
print 'Enter your MyEpisodes username: '
|
40
|
-
end
|
35
|
+
existing = "(#{@content[:myepisodes_user]}) " if @content[:myepisodes_user]
|
36
|
+
print "Enter your MyEpisodes username #{existing}: "
|
41
37
|
input = $stdin.gets.chomp
|
42
38
|
@content[:myepisodes_user] = input if input
|
43
39
|
end
|
@@ -48,39 +44,27 @@ module DownloadTV
|
|
48
44
|
end
|
49
45
|
|
50
46
|
def prompt_for_ignored
|
51
|
-
if @content[:ignored]
|
52
|
-
|
53
|
-
else
|
54
|
-
puts 'Enter a comma-separated list of shows to ignore: '
|
55
|
-
end
|
47
|
+
existing = "(#{@content[:ignored]})" if @content[:ignored]
|
48
|
+
puts "Enter a comma-separated list of shows to ignore: #{existing}"
|
56
49
|
|
57
|
-
@content[:ignored] =
|
58
|
-
.chomp
|
59
|
-
.split(',')
|
60
|
-
.map(&:strip)
|
61
|
-
.map(&:downcase)
|
50
|
+
@content[:ignored] = read_and_split_list :downcase
|
62
51
|
end
|
63
52
|
|
64
53
|
def prompt_for_filters
|
65
54
|
puts "Current filters: (#{@content[:filters]})" if @content[:filters]
|
66
|
-
|
67
55
|
@content[:filters] = {}
|
68
56
|
|
69
57
|
puts 'Enter a comma-separated list of terms to include: '
|
70
|
-
|
71
|
-
@content[:filters][:includes] = $stdin.gets
|
72
|
-
.chomp
|
73
|
-
.split(',')
|
74
|
-
.map(&:strip)
|
75
|
-
.map(&:upcase)
|
58
|
+
@content[:filters][:includes] = read_and_split_list :upcase
|
76
59
|
|
77
60
|
puts 'Enter a comma-separated list of terms to exclude: '
|
61
|
+
@content[:filters][:excludes] = read_and_split_list :upcase
|
62
|
+
end
|
78
63
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
.map(&:upcase)
|
64
|
+
def read_and_split_list(case_method)
|
65
|
+
$stdin.gets.chomp.split(',')
|
66
|
+
.map(&:strip)
|
67
|
+
.map(&case_method)
|
84
68
|
end
|
85
69
|
|
86
70
|
def default_filters
|
@@ -90,11 +74,11 @@ module DownloadTV
|
|
90
74
|
}
|
91
75
|
end
|
92
76
|
|
77
|
+
##
|
78
|
+
# Update the +content+ attribute with the defaults, if needed.
|
79
|
+
# Maintains the previous values, in case it's an update from an existing file.
|
93
80
|
def set_default_values
|
94
|
-
# When modifying existing config, keeps previous values
|
95
|
-
# When creating new one, sets defaults
|
96
81
|
@content[:auto] ||= true
|
97
|
-
@content[:subs] ||= true
|
98
82
|
@content[:grabber] ||= 'TorrentAPI'
|
99
83
|
@content[:date] ||= Date.today - 1
|
100
84
|
@content[:filters] ||= default_filters
|
@@ -117,7 +101,6 @@ module DownloadTV
|
|
117
101
|
rescue JSON::ParserError
|
118
102
|
@content = {}
|
119
103
|
change_configuration
|
120
|
-
retry
|
121
104
|
end
|
122
105
|
|
123
106
|
def default_config_path
|
@@ -125,9 +108,7 @@ module DownloadTV
|
|
125
108
|
end
|
126
109
|
|
127
110
|
##
|
128
|
-
# Returns true if a major or minor update has been detected
|
129
|
-
# Returns false if a patch has been detected
|
130
|
-
# Returns nil if it's the same version
|
111
|
+
# Returns true if a major or minor update has been detected, something falsy otherwise
|
131
112
|
def breaking_changes?(version)
|
132
113
|
DownloadTV::VERSION.split('.')
|
133
114
|
.zip(version.split('.'))
|
@@ -97,24 +97,30 @@ module DownloadTV
|
|
97
97
|
warn 'Wrong username/password combination'
|
98
98
|
end
|
99
99
|
|
100
|
+
def find_links(torrent, shows, queue)
|
101
|
+
Thread.new do
|
102
|
+
shows.each { |show| queue << get_link(torrent, show, save_pending: true) }
|
103
|
+
queue.close
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def download_from_queue(queue)
|
108
|
+
Thread.new do
|
109
|
+
until queue.closed?
|
110
|
+
magnet = queue.pop
|
111
|
+
download(magnet) if magnet # Doesn't download if no torrents are found
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
100
116
|
def find_and_download(shows)
|
101
117
|
t = Torrent.new
|
102
118
|
queue = Queue.new
|
103
119
|
|
104
|
-
|
105
|
-
link_t = Thread.new do
|
106
|
-
shows.each { |show| queue << get_link(t, show, save_pending: true) }
|
107
|
-
end
|
120
|
+
link_t = find_links(t, shows, queue)
|
108
121
|
|
109
122
|
# Downloads the links as they are added
|
110
|
-
download_t =
|
111
|
-
shows.size.times do
|
112
|
-
magnet = queue.pop
|
113
|
-
next if magnet == '' # Doesn't download if no torrents are found
|
114
|
-
|
115
|
-
download(magnet)
|
116
|
-
end
|
117
|
-
end
|
123
|
+
download_t = download_from_queue(queue)
|
118
124
|
|
119
125
|
link_t.join
|
120
126
|
download_t.join
|
@@ -143,18 +149,17 @@ module DownloadTV
|
|
143
149
|
# When :auto is true it will try to find the best match
|
144
150
|
# based on a set of filters.
|
145
151
|
# When it's false it will prompt the user to select the preferred result
|
146
|
-
# Returns either a magnet link or
|
152
|
+
# Returns either a magnet link or nil
|
147
153
|
def get_link(torrent, show, save_pending: false)
|
148
154
|
links = torrent.get_links(show)
|
149
155
|
|
150
156
|
if links.empty?
|
151
157
|
@config.content[:pending] << show if save_pending
|
152
|
-
return
|
158
|
+
return
|
153
159
|
end
|
154
160
|
|
155
161
|
if @config.content[:auto]
|
156
|
-
|
157
|
-
links.first[1]
|
162
|
+
filter_shows(links).first[1]
|
158
163
|
else
|
159
164
|
prompt_links(links)
|
160
165
|
get_link_from_user(links)
|
@@ -169,7 +174,7 @@ module DownloadTV
|
|
169
174
|
i = $stdin.gets.chomp.to_i
|
170
175
|
end
|
171
176
|
|
172
|
-
i == -1 ?
|
177
|
+
i == -1 ? nil : links[i][1]
|
173
178
|
end
|
174
179
|
|
175
180
|
def prompt_links(links)
|
@@ -204,8 +209,8 @@ module DownloadTV
|
|
204
209
|
# Runs until no filters are left to be applied or applying
|
205
210
|
# a filter would leave no results
|
206
211
|
def filter_shows(links)
|
207
|
-
|
208
|
-
|
212
|
+
@filterer ||= Filterer.new(@config.content[:filters])
|
213
|
+
@filterer.filter(links)
|
209
214
|
end
|
210
215
|
|
211
216
|
##
|
@@ -225,7 +230,7 @@ module DownloadTV
|
|
225
230
|
when /darwin/
|
226
231
|
'open'
|
227
232
|
else
|
228
|
-
warn "You're using an unsupported platform."
|
233
|
+
warn "You're using an unsupported platform (#{RbConfig::CONFIG['host_os']})."
|
229
234
|
exit 1
|
230
235
|
end
|
231
236
|
end
|
@@ -9,31 +9,17 @@ module DownloadTV
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def get_links(show)
|
12
|
-
|
13
|
-
search = format(@url, show)
|
14
|
-
|
15
|
-
raw_data = @agent.get(search)
|
16
|
-
raw_links = raw_data.search('a.magnet')
|
12
|
+
raw_data = @agent.get(format(@url, show))
|
17
13
|
raw_seeders = raw_data.search('td.forum_thread_post_end').map { |e| e.children[0].text.to_i }
|
18
|
-
raw_links =
|
19
|
-
|
20
|
-
# Torrent name in raw_links[i].attribute 'title'
|
21
|
-
# 'Suits S04E01 HDTV x264-LOL Torrent: Magnet Link'
|
14
|
+
raw_links = raw_data.search('a.magnet').sort_by.with_index { |_, index| raw_seeders[index] }.reverse
|
22
15
|
|
23
16
|
# EZTV shows 50 latest releases if it can't find the torrent
|
24
17
|
raise NoTorrentsError if raw_links.size == 50
|
25
18
|
|
26
|
-
|
27
|
-
i.attribute('title')
|
28
|
-
.text
|
29
|
-
.chomp(' Magnet Link')
|
19
|
+
raw_links.collect do |i|
|
20
|
+
[i.attribute('title').text.chomp(' Magnet Link'),
|
21
|
+
i.attribute('href').text]
|
30
22
|
end
|
31
|
-
links = raw_links.collect do |i|
|
32
|
-
i.attribute('href')
|
33
|
-
.text
|
34
|
-
end
|
35
|
-
|
36
|
-
names.zip(links)
|
37
23
|
end
|
38
24
|
end
|
39
25
|
end
|
@@ -5,30 +5,29 @@ module DownloadTV
|
|
5
5
|
# TorrentAPI.org grabber
|
6
6
|
# Interfaces with http://torrentapi.org/apidocs_v2.txt
|
7
7
|
class TorrentAPI < LinkGrabber
|
8
|
-
|
9
|
-
|
8
|
+
TOKEN_EXPIRED_ERROR = 4
|
9
|
+
TOO_MANY_REQUESTS_ERROR = 5 # 1req/2s
|
10
10
|
|
11
11
|
def initialize
|
12
12
|
super('https://torrentapi.org/pubapi_v2.php?'\
|
13
13
|
'mode=search&search_string=%s&token=%s&'\
|
14
14
|
'app_id=DownloadTV&sort=seeders')
|
15
|
-
@wait = 0.
|
15
|
+
@wait = 0.5
|
16
|
+
@token = nil
|
16
17
|
end
|
17
18
|
|
18
19
|
##
|
19
20
|
# Specific implementation for TorrentAPI (requires token)
|
20
21
|
def online?
|
21
|
-
@agent.read_timeout = 2
|
22
22
|
renew_token
|
23
23
|
true
|
24
24
|
rescue Mechanize::ResponseCodeError => e
|
25
25
|
if e.response_code == '429'
|
26
26
|
sleep(@wait)
|
27
27
|
retry
|
28
|
-
else
|
29
|
-
false
|
30
28
|
end
|
31
|
-
|
29
|
+
false
|
30
|
+
rescue Net::HTTP::Persistent::Error
|
32
31
|
false
|
33
32
|
end
|
34
33
|
|
@@ -52,19 +51,19 @@ module DownloadTV
|
|
52
51
|
end
|
53
52
|
|
54
53
|
def get_links(show)
|
55
|
-
@token
|
54
|
+
renew_token if @token.nil?
|
56
55
|
|
57
56
|
search = format(@url, show, @token)
|
58
57
|
|
59
58
|
obj = request_and_parse(search)
|
60
59
|
|
61
|
-
if obj['error_code'] ==
|
60
|
+
if obj['error_code'] == TOKEN_EXPIRED_ERROR
|
62
61
|
renew_token
|
63
62
|
search = format(@url, show, @token)
|
64
63
|
obj = request_and_parse(search)
|
65
64
|
end
|
66
65
|
|
67
|
-
while obj['error_code'] ==
|
66
|
+
while obj['error_code'] == TOO_MANY_REQUESTS_ERROR
|
68
67
|
sleep(@wait)
|
69
68
|
obj = request_and_parse(search)
|
70
69
|
end
|
@@ -79,9 +78,6 @@ module DownloadTV
|
|
79
78
|
if e.response_code == '429'
|
80
79
|
sleep(@wait)
|
81
80
|
retry
|
82
|
-
else
|
83
|
-
warn 'An unexpected error has occurred. Try updating the gem.'
|
84
|
-
exit 1
|
85
81
|
end
|
86
82
|
end
|
87
83
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DownloadTV
|
4
|
+
##
|
5
|
+
# EZTV.ag grabber
|
6
|
+
class Torrentz < LinkGrabber
|
7
|
+
def initialize
|
8
|
+
super('https://torrentzeu.org/kick.php?q=%s')
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_links(show)
|
12
|
+
raw_data = @agent.get(format(@url, show))
|
13
|
+
results = raw_data.search('tbody tr')
|
14
|
+
|
15
|
+
# require 'byebug'; byebug
|
16
|
+
|
17
|
+
raise NoTorrentsError if results.empty?
|
18
|
+
|
19
|
+
data = results.sort_by { |e| e.search('td[data-title="Last Updated"]')[1].text.to_i }.reverse
|
20
|
+
|
21
|
+
data.collect do |i|
|
22
|
+
[i.children[1].text.strip,
|
23
|
+
i.children[11].children[1].attribute('href').text]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -8,12 +8,13 @@ module DownloadTV
|
|
8
8
|
|
9
9
|
def initialize(url)
|
10
10
|
@url = url
|
11
|
-
@agent = Mechanize.new
|
12
|
-
|
11
|
+
@agent = Mechanize.new do |a|
|
12
|
+
a.user_agent = DownloadTV::USER_AGENT
|
13
|
+
a.read_timeout = 2
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
17
|
def online?
|
16
|
-
@agent.read_timeout = 2
|
17
18
|
url = if @url.include? '%s'
|
18
19
|
format(@url, 'test')
|
19
20
|
else
|
data/lib/download_tv/torrent.rb
CHANGED
@@ -7,8 +7,7 @@ module DownloadTV
|
|
7
7
|
attr_reader :g_instances, :tries
|
8
8
|
|
9
9
|
def grabbers
|
10
|
-
|
11
|
-
%w[TorrentAPI Eztv]
|
10
|
+
%w[TorrentAPI Torrentz Eztv]
|
12
11
|
end
|
13
12
|
|
14
13
|
def initialize(default_grabber = nil)
|
@@ -39,31 +38,23 @@ module DownloadTV
|
|
39
38
|
end
|
40
39
|
|
41
40
|
def change_grabbers
|
42
|
-
|
41
|
+
@tries -= 1
|
43
42
|
@g_instances.rotate!
|
44
43
|
check_grabber_online
|
45
44
|
end
|
46
45
|
|
47
46
|
def get_links(show)
|
48
|
-
|
49
|
-
|
50
|
-
reset_grabbers_order
|
51
|
-
reset_tries
|
52
|
-
|
53
|
-
links
|
47
|
+
@g_instances.first.get_links(show)
|
54
48
|
rescue NoTorrentsError
|
55
|
-
# Use next grabber
|
56
49
|
if @tries.positive?
|
57
|
-
@tries -= 1
|
58
50
|
change_grabbers
|
59
51
|
retry
|
60
|
-
|
61
|
-
else
|
62
|
-
reset_grabbers_order
|
63
|
-
reset_tries
|
64
|
-
puts "No torrents found for #{show}"
|
65
|
-
[]
|
66
52
|
end
|
53
|
+
# We're out of grabbers to try
|
54
|
+
puts "No torrents found for #{show}"
|
55
|
+
[]
|
56
|
+
ensure
|
57
|
+
reset_grabbers_order
|
67
58
|
end
|
68
59
|
|
69
60
|
def reset_tries
|
@@ -72,6 +63,7 @@ module DownloadTV
|
|
72
63
|
|
73
64
|
def reset_grabbers_order
|
74
65
|
@g_instances.rotate!(@tries + 1)
|
66
|
+
reset_tries
|
75
67
|
end
|
76
68
|
end
|
77
69
|
end
|
data/lib/download_tv/version.rb
CHANGED
data/test/config_test.rb
CHANGED
@@ -105,7 +105,6 @@ describe DownloadTV::Configuration do
|
|
105
105
|
_(c.content[:cookie]).must_equal true
|
106
106
|
_(c.content[:ignored]).must_equal ['anything']
|
107
107
|
_(c.content[:auto]).must_equal true
|
108
|
-
_(c.content[:subs]).must_equal true
|
109
108
|
_(c.content[:pending]).must_equal []
|
110
109
|
_(c.content[:grabber]).must_equal 'TorrentAPI'
|
111
110
|
_(c.content[:date]).must_equal(Date.today - 1)
|
@@ -151,7 +150,6 @@ describe DownloadTV::Configuration do
|
|
151
150
|
_(content[:myepisodes_user]).must_equal 'anything'
|
152
151
|
_(content[:ignored]).must_equal ['anything']
|
153
152
|
_(content[:auto]).must_equal true
|
154
|
-
_(content[:subs]).must_equal true
|
155
153
|
_(content[:pending]).must_equal []
|
156
154
|
_(content[:grabber]).must_equal 'TorrentAPI'
|
157
155
|
_(content[:date]).must_equal Date.today - 1
|
data/test/downloader_test.rb
CHANGED
@@ -89,18 +89,18 @@ describe DownloadTV::Downloader do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
describe 'the get_link method' do
|
92
|
-
it "returns
|
92
|
+
it "returns nil when it can't find links" do
|
93
93
|
t = Minitest::Mock.new
|
94
94
|
show = 'Example Show S01E01'
|
95
95
|
|
96
96
|
t.expect(:get_links, [], [show])
|
97
97
|
dl = DownloadTV::Downloader.new(auto: true, path: config_path, pending: ['show 11'])
|
98
|
-
_(dl.get_link(t, show, save_pending: true)).
|
98
|
+
_(dl.get_link(t, show, save_pending: true)).must_be_nil
|
99
99
|
_(dl.config.content[:pending]).must_equal ['show 11', show]
|
100
100
|
|
101
101
|
t.expect(:get_links, [], [show])
|
102
102
|
dl = DownloadTV::Downloader.new(auto: false, path: config_path, pending: [])
|
103
|
-
_(dl.get_link(t, show, save_pending: true)).
|
103
|
+
_(dl.get_link(t, show, save_pending: true)).must_be_nil
|
104
104
|
_(dl.config.content[:pending]).must_include show
|
105
105
|
|
106
106
|
t.verify
|
data/test/grabbers_test.rb
CHANGED
@@ -20,7 +20,7 @@ describe DownloadTV::LinkGrabber do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'will return an array with names and links of results when a torrent can be found' do
|
23
|
-
result = grabber.get_links('The Boys
|
23
|
+
result = grabber.get_links('The Boys S02E01')
|
24
24
|
_(result).must_be_instance_of Array
|
25
25
|
_(result).wont_be :empty?
|
26
26
|
result.each do |r|
|
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.6.
|
4
|
+
version: 2.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- guille
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- ".github/workflows/ruby.yml"
|
120
120
|
- ".gitignore"
|
121
121
|
- ".travis.yml"
|
122
|
+
- CHANGELOG.md
|
122
123
|
- Gemfile
|
123
124
|
- LICENSE.md
|
124
125
|
- README.md
|
@@ -133,6 +134,7 @@ files:
|
|
133
134
|
- lib/download_tv/grabbers/eztv.rb
|
134
135
|
- lib/download_tv/grabbers/kat.rb
|
135
136
|
- lib/download_tv/grabbers/torrentapi.rb
|
137
|
+
- lib/download_tv/grabbers/torrentz2.rb
|
136
138
|
- lib/download_tv/grabbers/tpb.rb
|
137
139
|
- lib/download_tv/linkgrabber.rb
|
138
140
|
- lib/download_tv/myepisodes.rb
|