download_tv 2.2.0 → 2.2.1

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: 01776f973e2d3bab1f88189cbf4315fc0f33923e
4
- data.tar.gz: bf5057e5fbda8bb6724dd69f9d3633abe2fc2f98
3
+ metadata.gz: b52ab943213458fa9781f6aa6fc332f80eb42f11
4
+ data.tar.gz: 12187f1e431cbb5be09725f6439bb2a27681972d
5
5
  SHA512:
6
- metadata.gz: d6dc22d8625510cf9f1a6aac9198d6f95d6bb4953fd43e175f6ec09b3a397a3ed28239bcc20ff2dd1025cdbe83e20fbc0930febaf42a190e93758c6e1687910a
7
- data.tar.gz: b60c1b8b52b9c74a1328afb6da8ee3011eb975d187553c5b4f947fce6c07d3c228aa45e45202be21f38f6a3d491b7e24da88980b8136052388ec78b3ba6b3a66
6
+ metadata.gz: de173925b0f49d9bc22d76de843c2c86a3d12bb65cffe0613a91ea637f4caac154bae4db652a5a787e449b24b47a626880937d0d1aa980be95fa4c8070d33386
7
+ data.tar.gz: 95b903ada7b90ff403347e0a51a4686f332137e4e684ce0a595519e110bf61e56b5d71980bbda1f0794313c6649a92425e84debbdae9fb57e1d2d191b8edbba7
data/LICENSE.md ADDED
@@ -0,0 +1,10 @@
1
+ MIT License
2
+ ===================
3
+
4
+ Copyright © 2017 Guillermo Rodríguez
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -8,10 +8,4 @@ Rake::TestTask.new do |t|
8
8
  t.libs << "test"
9
9
  t.test_files = FileList["test/**/*_test.rb"]
10
10
  t.verbose = false
11
- end
12
-
13
- task :clean do
14
- rm_rf "config.rb"
15
- rm_rf "cookie"
16
- rm_rf "date"
17
- end
11
+ end
data/download_tv.gemspec CHANGED
@@ -28,9 +28,6 @@ Gem::Specification.new do |s|
28
28
 
29
29
  s.add_dependency("json")
30
30
  s.add_dependency("mechanize")
31
- s.add_dependency("date")
32
- s.add_dependency("io-console")
33
- s.add_dependency("fileutils")
34
31
 
35
32
  s.has_rdoc = false
36
33
  s.license = "MIT"
data/lib/download_tv.rb CHANGED
@@ -2,6 +2,7 @@ require "json"
2
2
  require "mechanize"
3
3
  require "date"
4
4
  require "io/console"
5
+ require "fileutils"
5
6
 
6
7
  require "download_tv/version"
7
8
  require "download_tv/configuration"
@@ -5,9 +5,6 @@ module DownloadTV
5
5
  attr_reader :offset, :config
6
6
 
7
7
  def initialize(offset=0, config={})
8
- # Change to installation directory
9
- Dir.chdir(__dir__)
10
-
11
8
  @offset = offset.abs
12
9
  @config = Configuration.new(config).content # Load configuration
13
10
 
@@ -173,10 +170,24 @@ module DownloadTV
173
170
  # Spawns a silent process to download a given magnet link
174
171
  # Uses xdg-open (not portable)
175
172
  def download(link)
176
- exec = "xdg-open \"#{link}\""
173
+ @cmd ||= detect_os
174
+
175
+ exec = "#{@cmd} \"#{link}\""
177
176
 
178
177
  Process.detach(Process.spawn(exec, [:out, :err]=>"/dev/null"))
179
178
 
180
179
  end
180
+
181
+ def detect_os
182
+ case RbConfig::CONFIG['host_os']
183
+ when /linux/
184
+ "xdg-open"
185
+ when /darwin/
186
+ "open"
187
+ else
188
+ warn "You're using an unsupported platform."
189
+ exit 1
190
+ end
191
+ end
181
192
  end
182
193
  end
@@ -6,8 +6,7 @@ module DownloadTV
6
6
  attr_reader :wait
7
7
 
8
8
  def initialize
9
- super("https://torrentapi.org/pubapi_v2.php?mode=search&search_string=%s&token=%s")
10
- @token = get_token
9
+ super("https://torrentapi.org/pubapi_v2.php?mode=search&search_string=%s&token=%s&app_id=DownloadTV")
11
10
  @wait = 2.1
12
11
 
13
12
  end
@@ -16,7 +15,7 @@ module DownloadTV
16
15
  # Connects to Torrentapi.org and requests a token.
17
16
  # Returns said token.
18
17
  def get_token
19
- page = @agent.get("https://torrentapi.org/pubapi_v2.php?get_token=get_token").content
18
+ page = @agent.get("https://torrentapi.org/pubapi_v2.php?get_token=get_token&app_id=DownloadTV").content
20
19
 
21
20
  obj = JSON.parse(page)
22
21
 
@@ -25,6 +24,7 @@ module DownloadTV
25
24
  end
26
25
 
27
26
  def get_links(s)
27
+ @token ||= get_token
28
28
 
29
29
  # Format the url
30
30
  search = @url % [s, @token]
@@ -54,6 +54,9 @@ module DownloadTV
54
54
 
55
55
  names.zip(links)
56
56
 
57
+ rescue Mechanize::ResponseCodeError
58
+ # Temporary solution for Cloudflare being obnoxious
59
+ raise NoTorrentsError
57
60
  end
58
61
 
59
62
  end
@@ -15,7 +15,7 @@ module DownloadTV
15
15
  @tries = @n_grabbers - 1
16
16
 
17
17
  # Silently ignores bad names
18
- @g_names.rotate! @g_names.find_index(default_grabber).to_i
18
+ @g_names.rotate! @g_names.find_index(default_grabber).to_i+1
19
19
 
20
20
  change_grabbers
21
21
 
@@ -41,7 +41,7 @@ module DownloadTV
41
41
  warn "Problem accessing #{newt.class.name}"
42
42
  # We won't be using this grabber
43
43
  @n_grabbers = @n_grabbers-1
44
- @tries = @tries - 1
44
+ @tries = @n_grabbers - 1
45
45
 
46
46
  change_grabbers
47
47
 
@@ -1,3 +1,3 @@
1
1
  module DownloadTV
2
- VERSION = "2.2.0"
2
+ VERSION = "2.2.1"
3
3
  end
@@ -143,4 +143,42 @@ describe DownloadTV::Downloader do
143
143
  end
144
144
  end
145
145
 
146
+ describe "the detect_os method" do
147
+ it "returns xdg open for linux" do
148
+ prev = RbConfig::CONFIG['host_os']
149
+ RbConfig::CONFIG['host_os'] = "linux-gnu"
150
+
151
+ dl = DownloadTV::Downloader.new(0, path: config_path)
152
+ dl.detect_os.must_equal "xdg-open"
153
+
154
+ RbConfig::CONFIG['host_os'] = prev
155
+ end
156
+
157
+ it "returns open for mac" do
158
+ prev = RbConfig::CONFIG['host_os']
159
+ RbConfig::CONFIG['host_os'] = "darwin15.6.0"
160
+
161
+ dl = DownloadTV::Downloader.new(0, path: config_path)
162
+ dl.detect_os.must_equal "open"
163
+
164
+ RbConfig::CONFIG['host_os'] = prev
165
+ end
166
+
167
+ it "exits when it can't detect the platform" do
168
+ prev = RbConfig::CONFIG['host_os']
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
+
146
184
  end
data/test/test_helper.rb CHANGED
@@ -11,8 +11,10 @@ end
11
11
 
12
12
  def run_silently
13
13
  previous_stdout, $stdout = $stdout, StringIO.new
14
+ previous_stderr, $stderr = $stderr, StringIO.new
14
15
  yield
15
16
  $stdout.string
16
17
  ensure
17
18
  $stdout = previous_stdout
19
+ $stderr = previous_stderr
18
20
  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.0
4
+ version: 2.2.1
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-01 00:00:00.000000000 Z
11
+ date: 2017-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,48 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: date
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: io-console
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: fileutils
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
83
  description:
126
84
  email:
127
85
  - guillerg96@gmail.com
@@ -133,6 +91,7 @@ files:
133
91
  - ".gitignore"
134
92
  - ".travis.yml"
135
93
  - Gemfile
94
+ - LICENSE.md
136
95
  - README.md
137
96
  - Rakefile
138
97
  - bin/tv