Skip to content

Commit

Permalink
download from an url
Browse files Browse the repository at this point in the history
  • Loading branch information
juanriaza committed Jan 31, 2013
1 parent 0dec814 commit 73cbc29
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ files = m.get_files()
m.download_file(file_id, file_key)
# upload a file
m.uploadfile('/home/kim/mega/secret_plans')
# download from an url
m.download_from_url('https://mega.co.nz/#!wYo3AYZC!Zwi1f3ANtYwKNOc07fwuN1enOoRj4CreFouuGqi4D6Y')
```

## Running the tests
Expand Down
6 changes: 6 additions & 0 deletions mega/mega.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import binascii

import requests
from urlobject import URLObject
from Crypto.Cipher import AES
from Crypto.PublicKey import RSA
from Crypto.Util import Counter
Expand Down Expand Up @@ -115,6 +116,11 @@ def get_files(self):
self.trashbin_id = file['h']
return files_data

def download_from_url(self, url):
url_object = URLObject(url)
file_id, file_key = url_object.fragment[1:].split('!')
self.download_file(file_id, file_key, public=True)

def download_file(self, file_id, file_key, public=False):
if public:
file_key = base64_to_a32(file_key)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
requests>=1.1.0
URLObject>=2.1.1
pycrypto>=2.6

0 comments on commit 73cbc29

Please sign in to comment.