Skip to content

xkti/mg-download

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

<!> Still work in progress, but *should* (!!) be fully functional.
<!> There is not that much error handling. Things can explode!
NO WARRANTY OR GUARANTEE IS PROVIDED, USE AT YOUR OWN RISK.

mg-download.sh - quirky little mega.nz downloader with quota bypass
rev.11 for beta testing

Usage: ./mg-download.sh FILE/FOLDER_LINK [Case/senstive/path/to/subfolder]
To enable debug logs, add MGDL_DEBUG=1 to the beginning of your command.

Requirements:
  aria2
  bash
  bc
  coreutils
  curl
  jq
  openssl
  xxd

Features:
  Supports file and folder links
  Transfer quota bypass via Cloudflare Workers
  Partial download resume support
  Download acceleration with aria2
  Multiple concurrent downloads

Supported links:
  File:      ./mg-download.sh https://mega.nz/file/xxx#xxxxxx
  Folder:                     https://mega.nz/folder/xxx#xxxxxx
  Subfolder:                  https://mega.nz/folder/xxx#xxxxxx 'path'
  File in folder:             https://mega.nz/folder/xxx#xxxxxx/file/xxx

  Subfolder paths must have no lead/trailing slash and be case-sensitive.
  The base folder should NOT be included in the specified path.
  See Limitations below for more clarification.

  OK  ./mg-download.sh https://mega.nz/folder/xxx#xxxxxx 'Path/to folder'
                          no leading or trailing slash!  ^              ^
  BAD ./mg-download.sh https://mega.nz/folder/xxx#xxxxxx 'some/folder/'
  BAD ./mg-download.sh https://mega.nz/folder/xxx#xxxxxx '/another/thing/'
  BAD ./mg-download.sh https://mega.nz/folder/xxx#xxxxxx/folder/xxxxxx

Known issues:
- Closing/interrupting the script doesn't really gracefully close.
  I don't know how to get around this for the time being.

- aria2 can sometimes fail with code 22. More often than not, it will be
  MEGA reporting 509 Bandwidth Limit Exceeded. You can check aria2c.log
  to find the exact cause.

Limitations:
- MEGA uses AES-128-CCM (CTR + CBC-MAC) to de/encrypt and verify files.
  Due to openssl's command-line limitations and my own, this script only
  handles the decryption (CTR) aspect of things. Files should be verified
  through checksums when available.

- Downloads may be slow regardless of aria2. This is MEGA's fault, as one
  file may download at 1MiB/s while the next file could transfer at 100MiB/s
  or even higher.

- Subfolder links (folder/xxx#xxxxx/folder/xxx) are not supported, but
  you can specify the path to it to get the same behaviour. (see above)

- Concurrent downloads work under subshells. It's a pain to deal with so
  it could be buggy or entirely fine. Also because of it, we can't
  reliably see the download/decryption progress anymore. Just wait!

Quota bypass:
  Attached is an index.js file. It is a rudimentary proxy that will accept
    URLs from *.userstorage.mega.co.nz. Because MEGA does not account for
    Cloudflare's IP headers, it treats each request with a new IP address,
    effectively bypassing any defined transfer quota.

    Hardcoded in the script is a worker I set up on a fresh account, but
    I strongly urge you to set up your own like so:

    1. Create or login to your Cloudflare account
    2. Click the blue plus button on the top right
    3. Select "Workers"
    4a. If this is your first time, select the Hello World template.
      . Set your worker name and deploy.
      . Click "Edit code."
      . Delete everything and paste the contents of index.js in.
      . Click "Deploy"
      . Copy worker URL and edit the PROXY variable in the script to use it.
    4b. If you know your way around Workers/wrangler, simply deploy index.js
        and replace PROXY="..." with your new worker URL. (No trailing slash)

About

mega.nz downloader made in bash

Topics

Resources

Stars

Watchers

Forks

Contributors

No contributors