download_tv 2.5.3 → 2.5.4

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
  SHA256:
3
- metadata.gz: 5ee5a753ef1f164e3be414b4dc72bd25f0ee067aabb50f213da09655e5ec6e3a
4
- data.tar.gz: 50ba6c3f7641ac1b36b3b63a1a34528d6d5645f69364416e756e126f951be95e
3
+ metadata.gz: 14480f4df75d1bd924641e70896710bdbaadbd61e7cdc2988c802f094c5841e1
4
+ data.tar.gz: cdee66d0f1c699e56b2b48c3376d4654ded93d17d6ea5851acf79e728e1b792e
5
5
  SHA512:
6
- metadata.gz: 7bbbbcdfd925e8afc3857f4160a4f0dd7d6094163b43421117465fbc38acfe890d9ce27af62d400cdf9018732f6a6868d72f1ea5d796682254dd535ff83b33a6
7
- data.tar.gz: c4df241a888c8248c356640e89d45aa1d961aaa00232321037601cf312f65c6721e5bd68d62aed8a018a335cca192fd4d3a0619d6b71fdf19bcecab9587209fa
6
+ metadata.gz: e65a989bc27f5741d656ea853f660fc50e2c2fd46fcb03794e50afd03f47b698b354d73845b940b03f6809d31cd5bf84108627ebb09410bb76c924cc36964730
7
+ data.tar.gz: 27afaf52a2aa2c699d7f95333aefcb8c3c622e3c9b2a1e1cce801fb9705f4f5824d9e16a5e6b01585960f9f0f3b4fd464e64e5ecafab2b5ed6e2ed9242e9e897
data/README.md CHANGED
@@ -21,6 +21,8 @@ Specific options:
21
21
  -o, --offset OFFSET Move back the last run offset
22
22
  -f, --file PATH Download shows from a file
23
23
  -d, --download SHOW Downloads given show
24
+ --season SEASON Limit the show download to a specific season
25
+ -t, --tomorrow Download shows airing today
24
26
  -c, --configure Configures defaults
25
27
  --show-config Show current configuration values
26
28
  --dry-run Don't write to the date file
@@ -30,9 +32,8 @@ Specific options:
30
32
  --show-grabbers List available grabbers
31
33
  -p, --pending Show list of pending downloads
32
34
  --clear-pending Clear list of pending downloads
33
- -v Print version
35
+ -v, --version Print version
34
36
  -h, --help Show this message
35
-
36
37
  ```
37
38
 
38
39
  ### MyEpisodes integration
@@ -53,6 +54,8 @@ In order to download a single episode, use the -d flag, quoting the string when
53
54
 
54
55
  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.
55
56
 
57
+ It can be used 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 until it can't find any torrent for the episode.
58
+
56
59
  ### Multi torrent download
57
60
 
58
61
  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*
@@ -65,7 +68,7 @@ I usually publish a patch update to the gem when I detect one of them isn't work
65
68
 
66
69
  ### Pending shows
67
70
 
68
- download_tv version 2.5.0 persists the list of shows it can't find on a given execution (when connecting to MyEpisodes, not for single show or file downloads). This list can be viewed by passing the -p flag to the tv binary. The list can be cleared with the --clear-pending option.
71
+ download_tv version 2.5.0 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.
69
72
 
70
73
  ### License
71
74
 
data/bin/tv CHANGED
@@ -30,6 +30,15 @@ opt_parser = OptionParser.new do |opts|
30
30
  options[:arg] = s
31
31
  end
32
32
 
33
+ opts.on('--season SEASON', 'Limit the show download to a specific season') do |s|
34
+ options[:cmd] = 'dl'
35
+ options[:season] = s
36
+ end
37
+
38
+ opts.on('-t', '--tomorrow', 'Download shows airing today') do |s|
39
+ options[:cmd] = 'tomorrow'
40
+ end
41
+
33
42
  opts.on('-c', '--configure', 'Configures defaults') do
34
43
  options[:cmd] = 'config'
35
44
  end
@@ -86,11 +95,18 @@ begin
86
95
  dl = DownloadTV::Downloader.new(config)
87
96
  dl.run(options[:dry], options[:offset].abs)
88
97
  when 'dl'
89
- dl = DownloadTV::Downloader.new(config)
90
- dl.download_single_show(options[:arg])
98
+ if options[:arg]
99
+ dl = DownloadTV::Downloader.new(config)
100
+ dl.download_single_show(options[:arg], options[:season])
101
+ else
102
+ warn 'You must use the season option with the -d option'
103
+ end
91
104
  when 'file'
92
105
  dl = DownloadTV::Downloader.new(config)
93
106
  dl.download_from_file(options[:arg])
107
+ when 'tomorrow'
108
+ dl = DownloadTV::Downloader.new(config)
109
+ dl.run_ahead(options[:dry])
94
110
  when 'config'
95
111
  DownloadTV::Configuration.new(config, true)
96
112
  when 'showconfig'
data/lib/download_tv.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'set'
3
4
  require 'json'
4
5
  require 'mechanize'
5
6
  require 'date'
@@ -71,6 +71,7 @@ module DownloadTV
71
71
  end
72
72
 
73
73
  def serialize
74
+ @content[:pending] = @content[:pending].uniq
74
75
  File.write(@config_path, JSON.generate(@content))
75
76
  end
76
77
 
@@ -20,10 +20,21 @@ module DownloadTV
20
20
  Thread.abort_on_exception = true
21
21
  end
22
22
 
23
- def download_single_show(show)
23
+ def download_single_show(show, season = nil)
24
24
  t = Torrent.new(@config.content[:grabber])
25
25
  show = fix_names([show]).first
26
- download(get_link(t, show))
26
+ if season
27
+ season.insert(0, '0') if season.size == 1
28
+ episode = "#{show} s#{season}e01"
29
+ loop do
30
+ link = get_link(t, episode)
31
+ break if link.empty?
32
+ download(link)
33
+ episode = episode.next
34
+ end
35
+ else
36
+ download(get_link(t, show))
37
+ end
27
38
  end
28
39
 
29
40
  ##
@@ -51,61 +62,92 @@ module DownloadTV
51
62
  @config.content[:pending].clear
52
63
  pending ||= []
53
64
  date = check_date(offset)
54
- if pending.empty? && date.nil?
55
- puts 'Everything up to date'
56
- exit
57
- end
58
65
 
59
- to_download = shows_to_download(date)
60
- to_download.concat pending
66
+ pending.concat shows_to_download(date) if date
61
67
 
62
- if to_download.empty?
68
+ if pending.empty?
63
69
  puts 'Nothing to download'
64
-
65
70
  else
66
- t = Torrent.new
67
-
68
- queue = Queue.new
69
-
70
- # Adds a link (or empty string to the queue)
71
- link_t = Thread.new do
72
- to_download.each { |show| queue << get_link(t, show, true) }
73
- end
74
-
75
- # Downloads the links as they are added
76
- download_t = Thread.new do
77
- to_download.size.times do
78
- magnet = queue.pop
79
- next if magnet == '' # Doesn't download if no torrents are found
71
+ find_and_download(pending)
72
+ puts 'Completed. Exiting...'
73
+ end
80
74
 
81
- download(magnet)
82
- end
83
- end
75
+ @config.content[:date] = [Date.today, @config.content[:date]].max unless dont_update_last_run
76
+ @config.serialize
77
+ rescue InvalidLoginError
78
+ warn 'Wrong username/password combination'
79
+ end
84
80
 
85
- # Downloading the subtitles
86
- # subs_t = @config.content[:subs] and Thread.new do
87
- # to_download.each { |show| @s.get_subs(show) }
88
- # end
81
+ ##
82
+ # Finds download links for all the episodes set to air today.
83
+ # TODO: Refactor with #run()
84
+ def run_ahead(dont_update_last_run)
85
+ pending = @config.content[:pending].clone
86
+ @config.content[:pending].clear
87
+ pending ||= []
89
88
 
90
- link_t.join
91
- download_t.join
92
- # subs_t.join
89
+ # Has the program already been run with --tomorrow
90
+ if @config.content[:date] < Date.today.next
91
+ pending.concat today_shows_to_download
92
+ end
93
93
 
94
+ if pending.empty?
95
+ puts 'Nothing to download'
96
+ else
97
+ find_and_download(pending)
94
98
  puts 'Completed. Exiting...'
95
99
  end
96
100
 
97
- @config.content[:date] = Date.today unless dont_update_last_run
101
+ @config.content[:date] = Date.today.next unless dont_update_last_run
98
102
  @config.serialize
99
103
  rescue InvalidLoginError
100
104
  warn 'Wrong username/password combination'
101
105
  end
102
106
 
107
+ def find_and_download(shows)
108
+ t = Torrent.new
109
+ queue = Queue.new
110
+
111
+ # Adds a link (or empty string to the queue)
112
+ link_t = Thread.new do
113
+ shows.each { |show| queue << get_link(t, show, true) }
114
+ end
115
+
116
+ # Downloads the links as they are added
117
+ download_t = Thread.new do
118
+ shows.size.times do
119
+ magnet = queue.pop
120
+ next if magnet == '' # Doesn't download if no torrents are found
121
+
122
+ download(magnet)
123
+ end
124
+ end
125
+
126
+ # Downloading the subtitles
127
+ # subs_t = @config.content[:subs] and Thread.new do
128
+ # shows.each { |show| @s.get_subs(show) }
129
+ # end
130
+
131
+ link_t.join
132
+ download_t.join
133
+ # subs_t.join
134
+ end
135
+
103
136
  def shows_to_download(date)
104
137
  myepisodes = MyEpisodes.new(@config.content[:myepisodes_user],
105
138
  @config.content[:cookie])
106
139
  # Log in using cookie by default
107
140
  myepisodes.load_cookie
108
- shows = myepisodes.get_shows(date)
141
+ shows = myepisodes.get_shows_since(date)
142
+ shows = reject_ignored(shows)
143
+ fix_names(shows)
144
+ end
145
+
146
+ def today_shows_to_download
147
+ myepisodes = MyEpisodes.new(@config.content[:myepisodes_user],
148
+ @config.content[:cookie])
149
+ myepisodes.load_cookie
150
+ shows = myepisodes.today_shows
109
151
  shows = reject_ignored(shows)
110
152
  fix_names(shows)
111
153
  end
@@ -152,12 +194,16 @@ module DownloadTV
152
194
  end
153
195
 
154
196
  ##
155
- # Returns the date from which to check for shows
156
- # Or nil if the date is today
197
+ # Returns the date from which to check shows
198
+ # or nil if the program was already ran today
199
+ # Passing an offset skips this check
157
200
  def check_date(offset)
158
- last = @config.content[:date]
159
- last -= offset
160
- last if last != Date.today
201
+ if offset.zero?
202
+ last = @config.content[:date]
203
+ last if last < Date.today
204
+ else
205
+ Date.today - offset
206
+ end
161
207
  end
162
208
 
163
209
  ##
@@ -64,17 +64,20 @@ module DownloadTV
64
64
  @agent
65
65
  end
66
66
 
67
- def get_shows(last)
68
- return [] if last.nil?
69
-
67
+ def get_shows_since(last)
70
68
  page = @agent.get 'https://www.myepisodes.com/ajax/service.php?mode=view_privatelist'
71
69
  shows = page.parser.css('tr.past')
72
-
73
70
  shows = filter_newer_shows(shows, last)
71
+ build_show_strings(shows)
72
+ end
74
73
 
74
+ def today_shows
75
+ page = @agent.get 'https://www.myepisodes.com/ajax/service.php?mode=view_privatelist'
76
+ shows = page.parser.css('tr.today')
75
77
  build_show_strings(shows)
76
78
  end
77
79
 
80
+ # Only keep the shows that have aired since the given date
78
81
  def filter_newer_shows(shows, date)
79
82
  shows.select do |i|
80
83
  airdate = i.css('td.date')[0].text
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DownloadTV
4
- VERSION = '2.5.3'
4
+ VERSION = '2.5.4'
5
5
  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.5.3
4
+ version: 2.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - guille
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-14 00:00:00.000000000 Z
11
+ date: 2019-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler