rmega 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Dockerfile +14 -0
- data/README.md +14 -13
- data/bin/rmega-dl +8 -3
- data/bin/rmega-up +9 -1
- data/lib/rmega/api_response.rb +1 -1
- data/lib/rmega/nodes/factory.rb +18 -8
- data/lib/rmega/nodes/node.rb +3 -2
- data/lib/rmega/version.rb +1 -1
- data/rmega.gemspec +3 -3
- data/spec/integration/resume_download_spec.rb +2 -1
- data/spec/integration_spec_helper.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ed425ea5b0da557c00e5e2abd80b00ddb72f7d32e4a12c6ee3e79d65a0e4a34
|
4
|
+
data.tar.gz: d4ddf7dcb5e5b40433da1e03eec12ccf91c3b400009493158c2b5055c5bc6119
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 466832e6ceedaf3df21715c17bec1a507dde658db7821aae46f6427bda5e1031ed34d454f97b0ef90b4a5ee9f86da877af51cfbfd78f0b64cb36fd93be957b2a
|
7
|
+
data.tar.gz: f3928e47b107ab5693c3daa73c9d6725e94f622e539e4d30e96b3fff8c2af0b4394e38068b5f7508c6dc4b3802c45a5a3c8014ba2a967ba3e8da6b56fa07fa2f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 0.2.6
|
2
|
+
|
3
|
+
### New Features
|
4
|
+
* Support new links format, e.g. `https://mega.nz/#!foo!bar` is now `https://mega.nz/file/foo#bar`
|
5
|
+
* Add `--get-link` flag to `rmega-up`: generate and print the sharable link of the new file
|
6
|
+
|
7
|
+
## 0.2.5
|
8
|
+
|
9
|
+
### Changes
|
10
|
+
* \#27 The error raised when the free quota is exceeded is now properly handled
|
11
|
+
* \#27 Improved detection of mega link when a generic url is given to ```rmega-dl``` (see cmd line usage)
|
12
|
+
|
1
13
|
## 0.2.4
|
2
14
|
|
3
15
|
### Changes
|
data/Dockerfile
ADDED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/rmega.svg)](https://badge.fury.io/rb/rmega)
|
2
|
+
[![Build Status](https://travis-ci.org/topac/rmega.svg?branch=master)](https://travis-ci.org/topac/rmega)
|
3
|
+
|
4
|
+
# rmega
|
2
5
|
|
3
6
|
Pure ruby library for <img src="https://mega.co.nz/favicon.ico" alt=""/> **MEGA** [https://mega.nz/](https://mega.nz/).
|
4
7
|
Works on Linux and OSX with Ruby 1.9.3+.
|
@@ -9,22 +12,20 @@ Works on Linux and OSX with Ruby 1.9.3+.
|
|
9
12
|
gem install rmega
|
10
13
|
```
|
11
14
|
|
12
|
-
## Command
|
15
|
+
## Command Line Usage
|
16
|
+
|
17
|
+
<img src="https://i.imgur.com/3cjgp4g.gif"/>
|
13
18
|
|
14
|
-
Since version 0.2.0 you can use the commands `rmega-dl` and `rmega-up` to
|
19
|
+
Since version 0.2.0 you can use the commands `rmega-dl` and `rmega-up` to download and upload files to MEGA.
|
15
20
|
|
16
21
|
* Downloads are resumable
|
22
|
+
* You can download all the links in a given file, e.g. `rmega-dl my_links.txt`
|
23
|
+
* Scrape a web page and download all the MEGA links, e.g. `rmega-dl https://www.reddit.com/r/megalinks/foobar`
|
17
24
|
* HTTP proxy support
|
18
|
-
*
|
19
|
-
|
20
|
-
<img src="https://i.imgur.com/VVl55wj.gif"/>
|
21
|
-
|
22
|
-
*Pro tips:*
|
23
|
-
|
24
|
-
* Streaming: you can use a video player (e.g. VLC) to play videos while downloading them.
|
25
|
-
* Super privacy: you can use it combined with [torsocks](https://github.com/dgoulet/torsocks/) to download and upload files through the Tor network (very slow).
|
25
|
+
* Streaming! :beer: You can use a video player (VLC works perfectly) to play videos while downloading them
|
26
|
+
* You can use it combined with [torsocks](https://github.com/dgoulet/torsocks/) to download and upload files through the Tor network (slower)
|
26
27
|
|
27
|
-
## DSL
|
28
|
+
## DSL Usage
|
28
29
|
|
29
30
|
### Login
|
30
31
|
|
@@ -88,7 +89,7 @@ end
|
|
88
89
|
folder.download("~/Downloads/my_folder")
|
89
90
|
|
90
91
|
# Download a file by url
|
91
|
-
public_url = 'https://mega.
|
92
|
+
public_url = 'https://mega.nz/file/MAkg2Iab#bc9Y2U6d93IlRRKVYpcC9hLZjS4G278OPdH6nTFPDNQ'
|
92
93
|
Rmega.download(public_url, '~/Downloads')
|
93
94
|
```
|
94
95
|
|
data/bin/rmega-dl
CHANGED
@@ -16,8 +16,10 @@ OptionParser.new do |opts|
|
|
16
16
|
opts.banner << "\t#{File.basename(__FILE__)} url [options]\n"
|
17
17
|
opts.banner << "\t#{File.basename(__FILE__)} path [options]\n"
|
18
18
|
opts.banner << "Examples:\n"
|
19
|
-
opts.banner << "\t#{File.basename(__FILE__)} 'https://mega.nz/#!aBkHBKLX!
|
20
|
-
opts.banner << "\t#{File.basename(__FILE__)} https://
|
19
|
+
opts.banner << "\t#{File.basename(__FILE__)} 'https://mega.nz/#!aBkHBKLX!n4kqzbJooqcPZjN1tEJzQ4QQwskHf7YqKa'\n"
|
20
|
+
opts.banner << "\t#{File.basename(__FILE__)} https://mega.nz/file/aBkHBKLX#n4kqzbJooqcPZjN1tEJzQ4QQwskHf7YqKa\n"
|
21
|
+
opts.banner << "\t#{File.basename(__FILE__)} https://mega.nz/folder/aBkHBKLX#n4kqzbJooqcPZjN1tEJzQ4QQwskHf7YqKa\n"
|
22
|
+
opts.banner << "\t#{File.basename(__FILE__)} https://www.reddit.com/r/megalinks3\n"
|
21
23
|
opts.banner << "\t#{File.basename(__FILE__)} mylinks.txt\n"
|
22
24
|
opts.banner << "\t#{File.basename(__FILE__)} /remote/docs/myfile.txt -u email@localhost\n"
|
23
25
|
opts.banner << "Options:"
|
@@ -56,7 +58,10 @@ cli_rescue do
|
|
56
58
|
else
|
57
59
|
# A link to a web page with some MEGA urls in its body
|
58
60
|
html = Rmega::Session.new.http_get_content(cli_options[:url])
|
59
|
-
|
61
|
+
|
62
|
+
urls = html.scan(Rmega::Nodes::Factory::URL_REGEXP)
|
63
|
+
urls << html.scan(Rmega::Nodes::Factory::URL_REGEXP_NEW)
|
64
|
+
urls = urls.flatten.select { |u| Rmega::Nodes::Factory.url?(u) }.uniq
|
60
65
|
|
61
66
|
if cli_options[:debug] and urls.any?
|
62
67
|
Rmega.logger.debug("#{urls.size} URL(s) founded:\n" + urls.join("\n"))
|
data/bin/rmega-up
CHANGED
@@ -22,6 +22,10 @@ OptionParser.new do |opts|
|
|
22
22
|
cli_options[:remote_path] = path
|
23
23
|
}
|
24
24
|
|
25
|
+
opts.on("-l", "--get-link", "Generate and print the sharable link (witk key)") {
|
26
|
+
cli_options[:get_link] = true
|
27
|
+
}
|
28
|
+
|
25
29
|
apply_opt_parser_options(opts)
|
26
30
|
end.parse!
|
27
31
|
|
@@ -37,5 +41,9 @@ cli_rescue do
|
|
37
41
|
raise("Node not found - #{cli_options[:remote_path]}") unless node
|
38
42
|
raise("Node cannot be a file - #{cli_options[:remote_path]}") if node.type == :file
|
39
43
|
|
40
|
-
node.upload(cli_options[:path])
|
44
|
+
file = node.upload(cli_options[:path])
|
45
|
+
|
46
|
+
if cli_options[:get_link]
|
47
|
+
puts file.public_url
|
48
|
+
end
|
41
49
|
end
|
data/lib/rmega/api_response.rb
CHANGED
@@ -2,7 +2,7 @@ module Rmega
|
|
2
2
|
class APIResponse
|
3
3
|
attr_reader :body, :code
|
4
4
|
|
5
|
-
# Check out the error codes list at https://mega.
|
5
|
+
# Check out the error codes list at https://mega.nz/#doc (section 11)
|
6
6
|
ERRORS = {
|
7
7
|
-1 => 'An internal error has occurred. Please submit a bug report, detailing the exact circumstances in which this error occurred.',
|
8
8
|
-2 => 'You have passed invalid arguments to this command.',
|
data/lib/rmega/nodes/factory.rb
CHANGED
@@ -16,15 +16,25 @@ module Rmega
|
|
16
16
|
module Factory
|
17
17
|
extend self
|
18
18
|
|
19
|
-
URL_REGEXP = /(
|
19
|
+
URL_REGEXP = /(https{0,1}:\/\/[w\.]*mega\.[a-z\.]+\/\#[A-Z0-9\_\-\!\=]+)/i
|
20
|
+
URL_REGEXP_NEW = /(https{0,1}:\/\/[w\.]*mega\.[a-z\.]+\/[a-z]{4,6}\/[a-z0-9\_\-\=]+\#[a-z0-9\_\-\=]+)/i
|
20
21
|
|
21
|
-
|
22
|
+
def public_handle_and_key_from_url(string)
|
23
|
+
if string.to_s =~ URL_REGEXP
|
24
|
+
public_handle, key = string.strip.split('!')[1, 2]
|
25
|
+
return [] if key and (Utils.base64urldecode(key) rescue nil).nil?
|
26
|
+
return [public_handle, key]
|
27
|
+
elsif string.to_s =~ URL_REGEXP_NEW
|
28
|
+
public_handle, key = *string.scan(/\/([^\/]+)\#(.+)$/).flatten
|
29
|
+
return [] if key and (Utils.base64urldecode(key) rescue nil).nil?
|
30
|
+
return [public_handle, key]
|
31
|
+
else
|
32
|
+
return []
|
33
|
+
end
|
34
|
+
end
|
22
35
|
|
23
36
|
def url?(string)
|
24
|
-
|
25
|
-
public_handle, key = string.strip.split('!')[1, 2]
|
26
|
-
return false if key and (Utils.base64urldecode(key) rescue nil).nil?
|
27
|
-
return true
|
37
|
+
public_handle_and_key_from_url(string).any?
|
28
38
|
end
|
29
39
|
|
30
40
|
def build(session, data)
|
@@ -33,11 +43,11 @@ module Rmega
|
|
33
43
|
end
|
34
44
|
|
35
45
|
def build_from_url(url, session = Session.new)
|
36
|
-
public_handle, key = url
|
46
|
+
public_handle, key = *public_handle_and_key_from_url(url)
|
37
47
|
|
38
48
|
raise "Invalid url or missing file key" unless key
|
39
49
|
|
40
|
-
node = if url
|
50
|
+
node = if url.include?("/folder/") or url.include?("/#F!")
|
41
51
|
nodes_data = session.request({a: 'f', c: 1, r: 1}, {n: public_handle})
|
42
52
|
session.master_key = Utils.base64urldecode(key)
|
43
53
|
session.storage.nodes = nodes_data['f'].map do |data|
|
data/lib/rmega/nodes/node.rb
CHANGED
@@ -21,7 +21,7 @@ module Rmega
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def public_url
|
24
|
-
@public_url ||= "https://mega.
|
24
|
+
@public_url ||= "https://mega.nz/file/#{public_handle}\##{Utils.base64urlencode(decrypted_file_key)}"
|
25
25
|
end
|
26
26
|
|
27
27
|
def public_handle
|
@@ -138,7 +138,8 @@ module Rmega
|
|
138
138
|
elsif file_key
|
139
139
|
aes_ecb_decrypt(master_key, file_key)
|
140
140
|
else
|
141
|
-
|
141
|
+
ary = Rmega::Nodes::Factory.public_handle_and_key_from_url(public_url)
|
142
|
+
Utils.base64urldecode(ary[1])
|
142
143
|
end
|
143
144
|
end
|
144
145
|
|
data/lib/rmega/version.rb
CHANGED
data/rmega.gemspec
CHANGED
@@ -3,9 +3,9 @@ require File.expand_path('../lib/rmega/version', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["topac"]
|
6
|
-
gem.email = ["
|
7
|
-
gem.description = %q{mega.
|
8
|
-
gem.summary = %q{mega.
|
6
|
+
gem.email = ["topac@users.noreply.github.com"]
|
7
|
+
gem.description = %q{mega.nz ruby api}
|
8
|
+
gem.summary = %q{mega.nz ruby api}
|
9
9
|
gem.homepage = Rmega::HOMEPAGE
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
@@ -8,7 +8,8 @@ module Rmega
|
|
8
8
|
let(:destination_file) { "#{temp_folder}/temp.txt" }
|
9
9
|
|
10
10
|
before do
|
11
|
-
Thread.abort_on_exception = false
|
11
|
+
Thread.abort_on_exception = false if Thread.respond_to?(:abort_on_exception)
|
12
|
+
Thread.report_on_exception = false if Thread.respond_to?(:report_on_exception)
|
12
13
|
allow_any_instance_of(Pool).to receive(:threads_raises_exceptions).and_return(nil)
|
13
14
|
end
|
14
15
|
|
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.6
|
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: 2020-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -52,9 +52,9 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description: mega.
|
55
|
+
description: mega.nz ruby api
|
56
56
|
email:
|
57
|
-
-
|
57
|
+
- topac@users.noreply.github.com
|
58
58
|
executables:
|
59
59
|
- rmega-dl
|
60
60
|
- rmega-up
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- ".gitignore"
|
65
65
|
- ".travis.yml"
|
66
66
|
- CHANGELOG.md
|
67
|
+
- Dockerfile
|
67
68
|
- Gemfile
|
68
69
|
- LICENSE
|
69
70
|
- README.md
|
@@ -138,11 +139,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
139
|
- !ruby/object:Gem::Version
|
139
140
|
version: '0'
|
140
141
|
requirements: []
|
141
|
-
|
142
|
-
rubygems_version: 2.7.6
|
142
|
+
rubygems_version: 3.1.2
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
|
-
summary: mega.
|
145
|
+
summary: mega.nz ruby api
|
146
146
|
test_files:
|
147
147
|
- spec/integration/file_download_spec.rb
|
148
148
|
- spec/integration/file_integrity_spec.rb
|