From 29ede8f6ed866121d91eed241f0b8bf630c08160 Mon Sep 17 00:00:00 2001 From: richardasaurus Date: Fri, 8 Feb 2013 12:45:16 +0000 Subject: [PATCH] download() now takes file obj, rather than public file id/handle --- README.md | 5 +++-- mega.py | 11 +++++++++-- tests/test.py | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e6db386..e12ae3c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/mega.py b/mega.py index c17e861..aa9e533 100644 --- a/mega.py +++ b/mega.py @@ -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 diff --git a/tests/test.py b/tests/test.py index de15046..507934b 100644 --- a/tests/test.py +++ b/tests/test.py @@ -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__':