rmega 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +16 -0
- data/README.md +1 -1
- data/bin/rmega-dl +23 -5
- data/lib/rmega/cli.rb +19 -10
- data/lib/rmega/crypto/aes_cbc.rb +13 -10
- data/lib/rmega/net.rb +13 -7
- data/lib/rmega/nodes/downloadable.rb +3 -3
- data/lib/rmega/progress.rb +1 -0
- data/lib/rmega/version.rb +1 -1
- data/lib/rmega.rb +1 -0
- data/spec/integration/file_upload_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5220ae63878c82e2e72cb324a5277347dfebee7
|
4
|
+
data.tar.gz: 0055c65dcaca525127fe46a228885eb84100a8c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8051f36840c086b719974538d37b770824663a26ce84177316b0945b9acf6a8ba311668164a0ab23e3b1377a1f18a642b49669d167b43244ac1f7ffde5261ad8
|
7
|
+
data.tar.gz: eb1cbced4fa134640d631cceca5d03c400bfb1c88499fbc768310f74fbeea09ae416875627fd2e397b9c4025bca17c0f0175646039b842a1a6efe02e4d9b1913
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 0.2.4
|
2
|
+
|
3
|
+
### Changes
|
4
|
+
* \#25 Fix connection reset on file upload
|
5
|
+
* \#24 Speed up aes_cbc_mac func
|
6
|
+
|
7
|
+
## 0.2.3
|
8
|
+
|
9
|
+
### Changes
|
10
|
+
* Fixed reading options from the configuration file (~/.rmega)
|
11
|
+
* The max number of parallel threads is now 8
|
12
|
+
|
13
|
+
### New Features
|
14
|
+
* If `rmega-dl` receive a local file as the main args, that file is treated as a text file that must contains a list of mega links
|
15
|
+
* The download progress bar now distinguishes between allocate, verify and download phase
|
16
|
+
|
1
17
|
## 0.2.2
|
2
18
|
|
3
19
|
### Changes
|
data/README.md
CHANGED
@@ -88,7 +88,7 @@ end
|
|
88
88
|
folder.download("~/Downloads/my_folder")
|
89
89
|
|
90
90
|
# Download a file by url
|
91
|
-
|
91
|
+
public_url = 'https://mega.co.nz/#!MAkg2Iab!bc9Y2U6d93IlRRKVYpcC9hLZjS4G278OPdH6nTFPDNQ'
|
92
92
|
Rmega.download(public_url, '~/Downloads')
|
93
93
|
```
|
94
94
|
|
data/bin/rmega-dl
CHANGED
@@ -18,6 +18,7 @@ OptionParser.new do |opts|
|
|
18
18
|
opts.banner << "Examples:\n"
|
19
19
|
opts.banner << "\t#{File.basename(__FILE__)} 'https://mega.nz/#!aBkHBKLX!n4kqzbJooqc3o_s96PZjN1tEJzQ4QQwskHf7YqKa'\n"
|
20
20
|
opts.banner << "\t#{File.basename(__FILE__)} https://www.reddit.com/r/megalinks\n"
|
21
|
+
opts.banner << "\t#{File.basename(__FILE__)} mylinks.txt\n"
|
21
22
|
opts.banner << "\t#{File.basename(__FILE__)} /remote/docs/myfile.txt -u email@localhost\n"
|
22
23
|
opts.banner << "Options:"
|
23
24
|
|
@@ -36,14 +37,31 @@ cli_rescue do
|
|
36
37
|
raise("Node not found - #{cli_options[:url]}") unless node
|
37
38
|
node.download(cli_options[:output] || Dir.pwd)
|
38
39
|
else
|
39
|
-
urls = [
|
40
|
+
urls = []
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
urls =
|
44
|
-
|
42
|
+
if mega_url?(cli_options[:url])
|
43
|
+
# a valid MEGA urls
|
44
|
+
urls = [cli_options[:url]]
|
45
|
+
else
|
46
|
+
# A text file with a list of MEGA urls (considering only files < 1 Mb)
|
47
|
+
if File.exists?(cli_options[:url])
|
48
|
+
if File.size(cli_options[:url]) < 1_000_000
|
49
|
+
File.open(cli_options[:url], "rb") do |file|
|
50
|
+
file.each_line do |line|
|
51
|
+
line.strip!
|
52
|
+
urls << line if mega_url?(line)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
else
|
57
|
+
# A link to a web page with some MEGA urls in its body
|
58
|
+
html = Rmega::Session.new.http_get_content(cli_options[:url])
|
59
|
+
urls = html.scan(Rmega::Nodes::Factory::URL_REGEXP).flatten.uniq
|
60
|
+
end
|
45
61
|
end
|
46
62
|
|
63
|
+
raise("Nothing to download") if urls.empty?
|
64
|
+
|
47
65
|
urls.each_with_index do |url, index|
|
48
66
|
node = Rmega::Nodes::Factory.build_from_url(url)
|
49
67
|
print "[#{index+1}/#{urls.size}] " if urls.size > 1
|
data/lib/rmega/cli.rb
CHANGED
@@ -6,7 +6,7 @@ module Rmega
|
|
6
6
|
module CLI
|
7
7
|
module Helpers
|
8
8
|
def cli_options
|
9
|
-
$cli_options ||=
|
9
|
+
$cli_options ||= read_configuration_file
|
10
10
|
end
|
11
11
|
|
12
12
|
def cli_prompt_password
|
@@ -27,12 +27,14 @@ module Rmega
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def read_configuration_file
|
30
|
-
return unless File.exists?(configuration_filepath)
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
return {} unless File.exists?(configuration_filepath)
|
31
|
+
|
32
|
+
opts = YAML.load_file(configuration_filepath)
|
33
|
+
opts.keys.each { |k| opts[k.to_sym] = opts.delete(k) } # symbolize_keys!
|
34
|
+
|
35
|
+
return opts
|
34
36
|
rescue Exception => ex
|
35
|
-
raise(ex)
|
37
|
+
raise(ex)
|
36
38
|
end
|
37
39
|
|
38
40
|
def apply_cli_options
|
@@ -44,8 +46,16 @@ module Rmega
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def apply_opt_parser_options(opts)
|
47
|
-
opts.on("-t NUM", "--thread_pool_size", "Number of threads to use") { |
|
48
|
-
|
49
|
+
opts.on("-t NUM", "--thread_pool_size", "Number of threads to use [1-8], default and recommended is #{Rmega.options.thread_pool_size}") { |num|
|
50
|
+
num = num.to_i
|
51
|
+
|
52
|
+
if num <= 0
|
53
|
+
num = 1
|
54
|
+
elsif num > 8
|
55
|
+
num = 8
|
56
|
+
end
|
57
|
+
|
58
|
+
cli_options[:thread_pool_size] = num
|
49
59
|
}
|
50
60
|
|
51
61
|
opts.on("--proxy-addr ADDRESS", "Http proxy address") { |value|
|
@@ -71,7 +81,7 @@ module Rmega
|
|
71
81
|
opts.on("-v", "--version", "Print the version number") {
|
72
82
|
puts Rmega::VERSION
|
73
83
|
puts Rmega::HOMEPAGE
|
74
|
-
exit
|
84
|
+
exit(0)
|
75
85
|
}
|
76
86
|
end
|
77
87
|
|
@@ -99,7 +109,6 @@ module Rmega
|
|
99
109
|
end
|
100
110
|
|
101
111
|
def cli_rescue
|
102
|
-
read_configuration_file
|
103
112
|
apply_cli_options
|
104
113
|
yield
|
105
114
|
rescue Interrupt
|
data/lib/rmega/crypto/aes_cbc.rb
CHANGED
@@ -28,18 +28,21 @@ module Rmega
|
|
28
28
|
cipher.iv = iv if iv
|
29
29
|
cipher.key = key
|
30
30
|
|
31
|
-
n = 0
|
32
|
-
mac = nil
|
31
|
+
# n = 0
|
32
|
+
# mac = nil
|
33
33
|
|
34
|
-
loop do
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
34
|
+
# loop do
|
35
|
+
# block = data[n..n+15]
|
36
|
+
# break if !block or block.empty?
|
37
|
+
# block << "\x0"*(16-block.size) if block.size < 16
|
38
|
+
# n += 16
|
39
|
+
# mac = cipher.update(block)
|
40
|
+
# end
|
41
41
|
|
42
|
-
return mac
|
42
|
+
# return mac
|
43
|
+
|
44
|
+
block = data + "\x0" * ((16 - data.bytesize % 16) % 16)
|
45
|
+
return cipher.update(block)[-16..-1]
|
43
46
|
end
|
44
47
|
end
|
45
48
|
end
|
data/lib/rmega/net.rb
CHANGED
@@ -18,7 +18,7 @@ module Rmega
|
|
18
18
|
def http_get_content(url)
|
19
19
|
uri = URI(url)
|
20
20
|
req = ::Net::HTTP::Get.new(uri.request_uri)
|
21
|
-
return
|
21
|
+
return net_http(uri).request(req).body
|
22
22
|
end
|
23
23
|
|
24
24
|
def http_post(url, data)
|
@@ -26,30 +26,36 @@ module Rmega
|
|
26
26
|
req = ::Net::HTTP::Post.new(uri.request_uri)
|
27
27
|
req.body = data
|
28
28
|
logger.debug("REQ POST #{url} #{cut_string(data)}")
|
29
|
-
|
29
|
+
|
30
|
+
# if you don't use Net::Http#start it will not keep the socket open even if you set
|
31
|
+
# the connection header BUT setting the connection header to 'keep-alive' its enough
|
32
|
+
# to fool MEGA servers and don't let them reset your connection!
|
33
|
+
req['Connection'] = 'keep-alive'
|
34
|
+
|
35
|
+
response = net_http(uri).request(req)
|
30
36
|
logger.debug("REP #{response.code} #{cut_string(response.body)}")
|
31
37
|
return response
|
32
38
|
end
|
33
39
|
|
34
40
|
private
|
35
41
|
|
36
|
-
def
|
42
|
+
def net_http(uri)
|
37
43
|
http = ::Net::HTTP.new(uri.host, uri.port)
|
38
44
|
http.use_ssl = true if uri.scheme == 'https'
|
39
|
-
apply_http_options(http)
|
40
|
-
return http.request(req)
|
41
|
-
end
|
42
45
|
|
43
|
-
|
46
|
+
# apply common http options
|
44
47
|
http.proxy_from_env = false if options.http_proxy_address
|
45
48
|
|
46
49
|
options.marshal_dump.each do |name, value|
|
47
50
|
setter_method = name.to_s.split('http_')[1]
|
48
51
|
http.__send__("#{setter_method}=", value) if setter_method and value
|
49
52
|
end
|
53
|
+
|
54
|
+
return http
|
50
55
|
end
|
51
56
|
|
52
57
|
def cut_string(string, max = 50)
|
58
|
+
return "<binary data, #{string.size} bytes>" if string.encoding == ::Encoding::ASCII_8BIT
|
53
59
|
string.size <= max ? string : string[0..max-1]+"..."
|
54
60
|
end
|
55
61
|
end
|
@@ -69,7 +69,7 @@ module Rmega
|
|
69
69
|
path = ::File.expand_path(path)
|
70
70
|
path = Dir.exists?(path) ? ::File.join(path, name) : path
|
71
71
|
|
72
|
-
progress = Progress.new(filesize, caption: '
|
72
|
+
progress = Progress.new(filesize, caption: 'Allocate', filename: self.name)
|
73
73
|
pool = Pool.new
|
74
74
|
|
75
75
|
@resumed_download = allocated?(path)
|
@@ -84,12 +84,12 @@ module Rmega
|
|
84
84
|
|
85
85
|
if data
|
86
86
|
chunk_macs[start] = calculate_chunck_mac(data) if options.file_integrity_check
|
87
|
-
progress.increment(size, real: false)
|
87
|
+
progress.increment(size, real: false, caption: "Verify")
|
88
88
|
else
|
89
89
|
data = decrypt_chunk(start, download_chunk(start, size))
|
90
90
|
chunk_macs[start] = calculate_chunck_mac(data) if options.file_integrity_check
|
91
91
|
write_chunk(start, data)
|
92
|
-
progress.increment(size)
|
92
|
+
progress.increment(size, caption: "Download")
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
data/lib/rmega/progress.rb
CHANGED
data/lib/rmega/version.rb
CHANGED
data/lib/rmega.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rmega
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- topac
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.6.12
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: mega.co.nz ruby api
|