Add method get_public_folder_info.

This commit is contained in:
Ethan Dalool 2020-03-23 20:31:33 -07:00
parent 25c567a5a3
commit 1a7c3ea781

View file

@ -1062,11 +1062,15 @@ class Mega:
def get_public_url_info(self, url): def get_public_url_info(self, url):
""" """
Get size and name from a public url, dict returned Dispatch to get_public_folder_info and get_public_file_info.
""" """
(public_handle, decryption_key) = self._parse_url(url) (public_handle, decryption_key) = self._parse_url(url)
if '/#F!' in url:
return self.get_public_folder_info(public_handle, decryption_key)
else:
return self.get_public_file_info(public_handle, decryption_key) return self.get_public_file_info(public_handle, decryption_key)
def import_public_url(self, url, dest_node=None, dest_name=None): def import_public_url(self, url, dest_node=None, dest_name=None):
""" """
Import the public url into user account Import the public url into user account
@ -1082,6 +1086,18 @@ class Mega:
# decrypt them # decrypt them
return self.get_files(public_folder_handle=folder_handle) return self.get_files(public_folder_handle=folder_handle)
def get_public_folder_info(self, folder_handle, folder_key):
"""
Get the total size of a public folder.
"""
# At the moment, the key is not actually needed. However if we decide
# to extract more statistics, then we may need it and I'd rather not
# change the function interface when that happens. So let's just take
# the key now even though it does nothing.
files = self.get_public_folder_files(folder_handle).values()
size = sum(file['s'] for file in files if file['t'] == NODE_TYPE_FILE)
return {'size': size}
def get_public_file_info(self, file_handle, file_key): def get_public_file_info(self, file_handle, file_key):
""" """