download() now takes file obj, rather than public file id/handle

master
richardasaurus 2013-02-08 12:45:16 +00:00
parent 1d80921dc7
commit 29ede8f6ed
3 changed files with 14 additions and 5 deletions

View File

@ -33,8 +33,9 @@ This is a work in progress, further functionality coming shortly.
file = m.upload('myfile.doc')
m.get_upload_link(file)
### Download a file from URL or it's ID,key combo
m.download('utYjgSTQ','OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')
### Download a file from URL or file obj,key combo
file = m.find('myfile.doc')
m.download(file)
m.download_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')
### Search account for a file, and get its public link

11
mega.py
View File

@ -127,13 +127,20 @@ class Mega(object):
raise errors.ValidationError('File id and key must be present')
def download_url(self, url):
'''
Download a file by it's public url
'''
path = self.parse_url(url).split('!')
file_id = path[0]
file_key = path[1]
self.download_file(file_id, file_key, is_public=True)
def download(self, file_id, file_key):
self.download_file(file_id, file_key, is_public=True)
def download(self, file):
'''
Download a file by it's file object
'''
url = self.get_link(file)
self.download_url(url)
def parse_url(self, url):
#parse file id and key from url

View File

@ -41,7 +41,8 @@ def test():
print(m.delete(file[1]['k']))
##download file, by id+key or url
#m.download('6hBW0R4a','By7-Vjj5xal8K5w_IXH3PlGNyZ1VvIrjZkOmHGq1X00')
#file = m.find('myfile.doc')
#m.download(file)
#m.download_url('https://mega.co.nz/#!6hBW0R4a!By7-Vjj5xal8K5w_IXH3PlGNyZ1VvIrjZkOmHGq1X00')
if __name__ == '__main__':