rget 4.1.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dropbox.rb +45 -28
  3. data/lib/webradio.rb +13 -8
  4. data/rget.gemspec +2 -2
  5. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e7390b3e41059e8ecbd831444e486d8a4e53344
4
- data.tar.gz: f9954fa00090ecef43a12e6a3edb1748b5d6a3e1
3
+ metadata.gz: 77d5b5444c527c81d9ccf64f5fa5679afec2f29d
4
+ data.tar.gz: 909b06eb3fce971d60bff406dfec32da68c69b42
5
5
  SHA512:
6
- metadata.gz: aace3fa444aed6bbc74ff1e2f46cd010bdd6bae3e2749c6cbdd077bbd7dfe84cd511b37da5b291ce4fe8617d3c157717f553bbc62b7d6f25321de6fecada3fd4
7
- data.tar.gz: ead867d95d7761594d021cf6619cb4c3415843ca43d67c1a8528faae5dc6ac13aa1e2af13d07d1dc654971af8cac5852b4e99260633f6bbc09f05414db35b106
6
+ metadata.gz: be8da2f75615ef51c693956f4ab2ece11c6e4cf77ae98cecb3320b5d84222d70261dc26f67fea47dccb6fc16176ab19c1c98cf590262e33f83f494a082e531c6
7
+ data.tar.gz: 7988434983f08de1c1347ee190386e6c91794d04c047160617ce0a48d43c1ed386560cc8566255ed740768b805e1c6ecc74e3438b14f6628f2926fd9f8767b61
data/lib/dropbox.rb CHANGED
@@ -1,36 +1,53 @@
1
- require "dropbox-api"
2
- require "dropbox-api/tasks"
1
+ require "dropbox_api"
3
2
  require 'pit'
4
3
 
5
- module DropboxAuth
6
- def self.client
7
- token = Pit::get('rget-dropbox')
8
- unless token[:api_key]
9
- print "Enter dropbox app key: "
10
- token[:api_key] = $stdin.gets.chomp
11
- print "Enter dropbox app secret: "
12
- token[:api_secret] = $stdin.gets.chomp
13
- Pit::set('rget-dropbox', data: token)
4
+ module RGet
5
+ class Dropbox
6
+ def self.client
7
+ self.new
14
8
  end
15
- Dropbox::API::Config.app_key = token[:api_key]
16
- Dropbox::API::Config.app_secret = token[:api_secret]
17
- Dropbox::API::Config.mode = 'dropbox'
18
9
 
19
- unless token[:access_token]
20
- consumer = Dropbox::API::OAuth.consumer(:authorize)
21
- request_token = consumer.get_request_token
22
- puts "\nGo to this url and click 'Authorize' to get the token:"
23
- puts request_token.authorize_url
24
- query = request_token.authorize_url.split('?').last
25
- verifier, = CGI.parse(query)['oauth_token']
26
- print "\nOnce you authorize the app on Dropbox, press enter... "
27
- $stdin.gets
28
- access_token = request_token.get_access_token(oauth_verifier: verifier)
29
- token[:access_token] = access_token.token
30
- token[:access_secret] = access_token.secret
31
- Pit::set('rget-dropbox', data: token)
10
+ def initialize
11
+ token = Pit::get('rget-dropbox')
12
+ unless token[:api_token]
13
+ if token[:api_key]
14
+ api_key = token[:api_key]
15
+ else
16
+ print "Enter dropbox app key: "
17
+ api_key = $stdin.gets.chomp
18
+ end
19
+
20
+ if token[:api_secret]
21
+ api_secret = token[:api_secret]
22
+ else
23
+ print "Enter dropbox app secret: "
24
+ api_secret = $stdin.gets.chomp
25
+ end
26
+
27
+ authenticator = DropboxApi::Authenticator.new(api_key, api_secret)
28
+ puts "\nGo to this url and click 'Authorize' to get the token:"
29
+ puts authenticator.authorize_url
30
+
31
+ token.clear # delete all old settings
32
+ print "Enter the token: "
33
+ code = $stdin.gets.chomp
34
+ token[:api_token] = authenticator.get_token(code).token
35
+ Pit::set('rget-dropbox', data: token)
36
+ end
37
+ @client = DropboxApi::Client.new(token[:api_token])
32
38
  end
33
39
 
34
- Dropbox::API::Client.new(token: token[:access_token], secret: token[:access_secret])
40
+ def exist?(dst, dropbox_path)
41
+ !(@client.search(dst, dropbox_path).matches.size == 0)
42
+ end
43
+
44
+ def upload(dropbox_path)
45
+ info = DropboxApi::Metadata::CommitInfo.new('path'=>dropbox_path, 'mode'=>:add)
46
+ cursor = @client.upload_session_start('')
47
+ while data = yield
48
+ @client.upload_session_append_v2(cursor, data)
49
+ end
50
+ @client.upload_session_finish(cursor, info)
51
+ end
35
52
  end
36
53
  end
data/lib/webradio.rb CHANGED
@@ -35,7 +35,7 @@ class WebRadio
35
35
  @options = options
36
36
  if !@options.dump && @options.path =~ %r|^dropbox://|
37
37
  require 'dropbox'
38
- @dropbox = DropboxAuth.client
38
+ @dropbox = RGet::Dropbox.client
39
39
  end
40
40
  end
41
41
 
@@ -136,11 +136,7 @@ private
136
136
 
137
137
  def exist?(dst)
138
138
  if @dropbox
139
- begin
140
- !@dropbox.ls(dropbox_file(dst))[0]['is_deleted']
141
- rescue Dropbox::API::Error::NotFound, NoMethodError
142
- false
143
- end
139
+ @dropbox.exist?(dst, dropbox_path)
144
140
  elsif @options.path
145
141
  File.exist?(File.join(@options.path, dst))
146
142
  else
@@ -153,7 +149,12 @@ private
153
149
  print "move to #{@options.path}..."
154
150
  begin
155
151
  if @dropbox
156
- @dropbox.chunked_upload(dropbox_file(dst), open(dst))
152
+ open(dst) do |r|
153
+ @dropbox.upload(dropbox_file(dst)) do
154
+ print '.'
155
+ r.read(10_000_000)
156
+ end
157
+ end
157
158
  File.delete(dst)
158
159
  elsif @options.path
159
160
  FileUtils.mv(dst, @options.path)
@@ -166,8 +167,12 @@ private
166
167
  end
167
168
  end
168
169
 
170
+ def dropbox_path
171
+ @options.path.sub(%r|^dropbox://|, '/')
172
+ end
173
+
169
174
  def dropbox_file(file)
170
- path = @options.path.sub(%r|^dropbox://|, '')
175
+ path = @options.path.sub(%r|^dropbox://|, '/')
171
176
  File.join(path, file)
172
177
  end
173
178
  end
data/rget.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "rget"
7
- spec.version = "4.1.0"
7
+ spec.version = "4.2.0"
8
8
  spec.authors = ["TADA Tadashi"]
9
9
  spec.email = ["t@tdtds.jp"]
10
10
  spec.description = %q{Downloading newest radio programs on the web. Supported radio stations are hibiki, onsen, niconico and freshlive.}
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency "nokogiri", ">= 1.7.0"
22
22
  spec.add_runtime_dependency "niconico", ">= 1.8.0"
23
23
  spec.add_runtime_dependency "pit"
24
- spec.add_runtime_dependency "dropbox-api", ">= 0.4.6"
24
+ spec.add_runtime_dependency "dropbox_api"
25
25
  spec.add_runtime_dependency "mp3info"
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 1.3"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rget
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TADA Tadashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-29 00:00:00.000000000 Z
11
+ date: 2017-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: dropbox-api
70
+ name: dropbox_api
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.4.6
75
+ version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 0.4.6
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: mp3info
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  version: '0'
186
186
  requirements: []
187
187
  rubyforge_project:
188
- rubygems_version: 2.6.13
188
+ rubygems_version: 2.5.1
189
189
  signing_key:
190
190
  specification_version: 4
191
191
  summary: Downloading newest radio programs on the web.