rmega 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6555304d89d2e8b375962e427881c16873ab8311088dee76e9ad2dd719af7d01
4
- data.tar.gz: 7808a4295238d240540af37b99f6d05a8f6c05b0ee7a558b9c1ba101836a8a4f
3
+ metadata.gz: 5ed425ea5b0da557c00e5e2abd80b00ddb72f7d32e4a12c6ee3e79d65a0e4a34
4
+ data.tar.gz: d4ddf7dcb5e5b40433da1e03eec12ccf91c3b400009493158c2b5055c5bc6119
5
5
  SHA512:
6
- metadata.gz: 99c86e71c98452e6510a7338dc9ef168f69e27bf239f9149a1cb62af58ff0c1768289354ab6e02bb5e1c71fd92eab3e188a61af0cfe8a4245902b5d9ecf8c047
7
- data.tar.gz: 389dfb0808a4ccbead5565ddcc46ab0555616b936bd7a2ef3e18d47d8c49d635d4d10f22936a1dbd046d9eb80c97c3dc4f29264e81f25dd385922dd577d3df71
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
@@ -0,0 +1,14 @@
1
+ FROM ruby
2
+
3
+ RUN apt-get install -y
4
+
5
+ RUN mkdir app
6
+
7
+ COPY . /app
8
+
9
+ RUN cd /app && \
10
+ gem install bundler && \
11
+ bundle install
12
+
13
+ WORKDIR /app
14
+ ENTRYPOINT ["rspec", "-f", "d"]
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # Rmega
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 line usage
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 easily download and upload files to MEGA.
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
- * See the CHANGELOG file for more info
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 usage
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.co.nz/#!MAkg2Iab!bc9Y2U6d93IlRRKVYpcC9hLZjS4G278OPdH6nTFPDNQ'
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!n4kqzbJooqc3o_s96PZjN1tEJzQ4QQwskHf7YqKa'\n"
20
- opts.banner << "\t#{File.basename(__FILE__)} https://www.reddit.com/r/megalinks\n"
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
- urls = html.scan(Rmega::Nodes::Factory::URL_REGEXP).flatten.select { |u| Rmega::Nodes::Factory.url?(u) }.uniq
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
@@ -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.co.nz/#doc (section 11)
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.',
@@ -16,15 +16,25 @@ module Rmega
16
16
  module Factory
17
17
  extend self
18
18
 
19
- URL_REGEXP = /(http.:\/\/[w\.]*mega\.[a-z\.]+\/\#[A-Z0-9\_\-\!\=]+)/i
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
- FOLDER_URL_REGEXP = /\#\F/
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
- return false unless string.to_s =~ URL_REGEXP
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.strip.split('!')[1, 2]
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 =~ FOLDER_URL_REGEXP
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|
@@ -21,7 +21,7 @@ module Rmega
21
21
  end
22
22
 
23
23
  def public_url
24
- @public_url ||= "https://mega.co.nz/#!#{public_handle}!#{Utils.base64urlencode(decrypted_file_key)}"
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
- Utils.base64urldecode(public_url.split('!').last)
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
@@ -1,4 +1,4 @@
1
1
  module Rmega
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  HOMEPAGE = "https://github.com/topac/rmega"
4
4
  end
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 = ["dani.m.mobile@gmail.com"]
7
- gem.description = %q{mega.co.nz ruby api}
8
- gem.summary = %q{mega.co.nz ruby api}
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
 
@@ -23,7 +23,7 @@ def login
23
23
  end
24
24
 
25
25
  def temp_folder
26
- Dir.tmpdir
26
+ $temp_folder ||= "#{Dir.tmpdir}/#{SecureRandom.hex(10)}"
27
27
  end
28
28
 
29
29
  RSpec.configure do |config|
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.5
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: 2019-04-17 00:00:00.000000000 Z
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.co.nz ruby api
55
+ description: mega.nz ruby api
56
56
  email:
57
- - dani.m.mobile@gmail.com
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
- rubyforge_project:
142
- rubygems_version: 2.7.6
142
+ rubygems_version: 3.1.2
143
143
  signing_key:
144
144
  specification_version: 4
145
- summary: mega.co.nz ruby api
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