lollercoaster lollercoaster - 11 days ago 5
Python Question

how to download an entire folder of public files from megaupload (mega.co.nz)?

I'm trying to download a public link (no login required). See the below:

enter image description here

Essentially in the browser you can select download as zip from the menu, but I don't have enough storage space on my laptop, so I'd like to do it on AWS.

The links are in the format:

https://mega.co.nz/#F!XXXXXXXX!XXXXXXXXXXXXXXXXXX-XXX


Things I've tried that don't work:



If anyone has a working command line script or knows how I might build something of the form for the command line


$ megadownloader https://mega.co.nz/#F!XXXXXXXX!XXXXXXXXXXXXXXXXXX-XXX


that would be awesome.

If there is a way in the browser (tried but couldn't find) to just find a static link by which I could then paste into a simple
urllib2
script in Python, that would even be the best, but I couldn't find such a link in the source of the mega.co.nz page.

Answer

You are not using a simple file server, but a web application that offers to download files as ZIP. If it is zipping "on fly" server side, the static link you want may not exist at all.

When facing such a problem, the only foolproof way is (it is a python based way as you question is tagged as python) :

  • write a python script on your laptop that simulates what you do in browser and test it on laptop. If using Python 2.x, you could use mechanize, or simply the Standard Python Library modules urllib2 (python 2.x) or urlib.request (python 3.x). Be sure to add a CookieProcessor to the list of standard handlers to correctly process sessions.
  • analyse in browser (or try to use wireshark to see it directly in HTTP frames) the commands that are sent to server and control that you can send them from your script and get expected responses
  • once your script runs fine on the laptop, port it and use it where you need.

Ok it is not a very precise answer, but it should give you enough hints and the path to go. Feel then free to ask more detailed questions here if you get stuck anywhere in the procedure : just give the python code you have written and explain what you do not know how to do. You should get more precise answers.