From 40f9fb95c2015dbd29a75624fa544f049bb2b4a7 Mon Sep 17 00:00:00 2001 From: gissehel Date: Sun, 5 May 2013 00:55:52 +0200 Subject: [PATCH] Renaming file and folders support --- README.md | 6 ++++++ mega/mega.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/README.md b/README.md index bb83ae3..2b6cad3 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Python library for the Mega.co.nz API, currently supporting: - deleting - searching - sharing + - renaming This is a work in progress, further functionality coming shortly. @@ -68,6 +69,11 @@ m.download(file, '/home/john-smith/Desktop') ```python m.create_folder('new_folder') ``` +### Rename a file or a folder +```python +file = m.find('myfile.doc') +m.rename(file, 'my_file.doc') +``` ### Search account for a file, and get its public link ```python file = m.find('myfile.doc') diff --git a/mega/mega.py b/mega/mega.py index d588b56..73b66ae 100644 --- a/mega/mega.py +++ b/mega/mega.py @@ -584,3 +584,22 @@ class Mega(object): 'i': self.request_id}) #return API msg return data + + def rename(self, file, new_name): + file = file[1] + #create new attribs + attribs = {'n': new_name} + #encrypt attribs + encrypt_attribs = base64_url_encode(encrypt_attr(attribs, file['k'])) + encrypted_key = a32_to_base64(encrypt_key(file['key'], self.master_key)) + + #update attributes + data = self.api_request([{ + 'a': 'a', + 'attr': encrypt_attribs, + 'key': encrypted_key, + 'n': file['h'], + 'i': self.request_id}]) + + #return API msg + return data