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

This commit is contained in:
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') file = m.upload('myfile.doc')
m.get_upload_link(file) m.get_upload_link(file)
### Download a file from URL or it's ID,key combo ### Download a file from URL or file obj,key combo
m.download('utYjgSTQ','OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc') file = m.find('myfile.doc')
m.download(file)
m.download_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc') m.download_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')
### Search account for a file, and get its public link ### 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') raise errors.ValidationError('File id and key must be present')
def download_url(self, url): def download_url(self, url):
'''
Download a file by it's public url
'''
path = self.parse_url(url).split('!') path = self.parse_url(url).split('!')
file_id = path[0] file_id = path[0]
file_key = path[1] file_key = path[1]
self.download_file(file_id, file_key, is_public=True) self.download_file(file_id, file_key, is_public=True)
def download(self, file_id, file_key): def download(self, file):
self.download_file(file_id, file_key, is_public=True) '''
Download a file by it's file object
'''
url = self.get_link(file)
self.download_url(url)
def parse_url(self, url): def parse_url(self, url):
#parse file id and key from url #parse file id and key from url

View file

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