Skip to content

Instantly share code, notes, and snippets.

@KenMacD
Created September 4, 2013 01:36
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save KenMacD/6431823 to your computer and use it in GitHub Desktop.
Save KenMacD/6431823 to your computer and use it in GitHub Desktop.
Mega download script from http://hacktracking.blogspot.ca/2013/07/download-mega-files-from-command-line.html. Download with "./mega-dl.sh '<URL>' <file name>" (Note the single quotes around the URL, otherwise bash complains "event not found")
#!/bin/bash
url=$1
enc_file=$2.enc
out_file=$2
id=`echo $url | awk -F '!' '{print $2}'`
key=`echo $url | awk -F '!' '{print $3}' | sed -e 's/-/+/g' -e 's/_/\//g' -e 's/,//g'`
b64_hex_key=`echo -n $key | base64 --decode --ignore-garbage 2> /dev/null | xxd -p | tr -d '\n'`
key[0]=$(( 0x${b64_hex_key:00:16} ^ 0x${b64_hex_key:32:16} ))
key[1]=$(( 0x${b64_hex_key:16:16} ^ 0x${b64_hex_key:48:16} ))
key=`printf "%x" ${key[*]}`
iv="${b64_hex_key:32:16}0000000000000000"
new_url=`curl --silent --request POST --data-binary '[{"a":"g","g":1,"p":"'$id'"}]' https://eu.api.mega.co.nz/cs | awk -F '"' '{print $10}'`
curl --output $enc_file $new_url
openssl enc -d -aes-128-ctr -K $key -iv $iv -in $enc_file -out $out_file
rm -f $enc_file
@peter279k
Copy link

Hi @KenMacD, thank you for your script about downloading files on MEGA.
Is it possible to resume downloading file ? If not, do you know how to make the downloading files resume on MEGA?

Thanks.

@vojmar
Copy link

vojmar commented Apr 27, 2019

probably outdated,
./mega-dl.sh 'https://mega.nz/#!lfxFBLDZ!qmpOITSeGgC5HQU5JzHDTdCJj_6eIY-3eHHp-1CHwIc' result.zip
Can't open result.zip.enc for reading, No such file or directory

@alirezarezamand
Copy link

So good, Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment