From 140bd9fc10d0c0effa0420417d488154e1f5d9c7 Mon Sep 17 00:00:00 2001 From: 11philip22 Date: Tue, 4 May 2021 13:15:58 +0200 Subject: [PATCH 1/2] phase out megacmd --- MEGAabuse.py | 3 +- megaabuse/__init__.py | 64 +++++++++++++++++++++----------------- megaabuse/mega/__init__.py | 6 +--- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/MEGAabuse.py b/MEGAabuse.py index 1df32da..d6bbf20 100755 --- a/MEGAabuse.py +++ b/MEGAabuse.py @@ -372,6 +372,7 @@ def upload_manager(queue): # Log in and log out using megacmd LOGGER.info("Logging into: %s %s", usern, passwd) - ABUSE.keep_alive(usern, passwd) + # ABUSE.keep_alive(usern, passwd) + ABUSE.login(usern, passwd) LOGGER.info("Done") diff --git a/megaabuse/__init__.py b/megaabuse/__init__.py index 1803fac..6f566ac 100644 --- a/megaabuse/__init__.py +++ b/megaabuse/__init__.py @@ -15,7 +15,8 @@ from .accountfactory.exceptions import WaitForMailTimoutException from .accountfactory import GuerrillaGen -from .megacmd import MegaCmd +# from .megacmd import MegaCmd +from .mega import Mega def get_logger(name, *args, level=40, write=False): @@ -182,7 +183,7 @@ def get(self, amount, proxy=False): return accounts -class MegaAbuse(CreateAccount, MegaCmd): +class MegaAbuse(CreateAccount, Mega): """" The main class of MEGAabuse Attributes @@ -265,7 +266,8 @@ def __init__(self, logger=None, write_files=False, **kwargs): self.done = [line.rstrip() for line in f_done] CreateAccount.__init__(self, **kwargs) - MegaCmd.__init__(self, **kwargs) + # MegaCmd.__init__(self, **kwargs) + Mega.__init__(self) # Create logger or sub logger for class if logger is None: @@ -279,26 +281,26 @@ def update_json_file(file, data): with open(file, "w") as json_file: json.dump(data, json_file, indent=4) - def create_folder(self, user_name, password, folder_name, proxy=False): - """" Create a folder om a mega account - - Parameters - ---------- - user_name : str - password : str - folder_name : str - Root is written as /Root/ instead of / - proxy : str, optional - Socks5 url - - """ - - cmd = f"{self.tools_path} mkdir {folder_name} -u {user_name} -p {password}" - if proxy: - cmd += f" --proxy={proxy}" - self.logger.debug(cmd) - - return bool(subprocess.Popen(cmd, shell=True).wait() == 0) + # def create_folder(self, user_name, password, folder_name, proxy=False): + # """" Create a folder om a mega account + # + # Parameters + # ---------- + # user_name : str + # password : str + # folder_name : str + # Root is written as /Root/ instead of / + # proxy : str, optional + # Socks5 url + # + # """ + # + # cmd = f"{self.tools_path} mkdir {folder_name} -u {user_name} -p {password}" + # if proxy: + # cmd += f" --proxy={proxy}" + # self.logger.debug(cmd) + # + # return bool(subprocess.Popen(cmd, shell=True).wait() == 0) def upload_file(self, username, password, remote_path, file_path, proxy=False): """" Uploads a file to mega @@ -367,14 +369,19 @@ def upload_chunks(self, chunks, dir_name, proxy): # Proxy can be str or False user_name = list(credentials.keys())[0] password = credentials[user_name] + self.login(user_name, password) + folder_name = resume_data[c_counter]["folder name"] uploaded_files = resume_data[c_counter]["uploaded files"] # Create folder - remote_path = f"/Root/{folder_name}" - if not self.create_folder(user_name, password, remote_path, proxy): - self.logger.error("Could not create folder: %s", remote_path) - raise Exception(f"Could not create folder: {remote_path}") + # remote_path = f"/Root/{folder_name}" + # if not self.create_folder(user_name, password, remote_path, proxy): + # self.logger.error("Could not create folder: %s", remote_path) + # raise Exception(f"Could not create folder: {remote_path}") + if not self.create_folder(folder_name): + self.logger.error("Could not create folder: %s", folder_name) + raise Exception(f"Could not create folder: {folder_name}") for file in chunk["files"]: if file not in uploaded_files: @@ -413,7 +420,8 @@ def upload_chunks(self, chunks, dir_name, proxy): # Proxy can be str or False self.logger.debug("Exporting: %s", f"/{folder_name}") # Folder path is with / instead of /Root because the export folder function # uses megacmd instead of megatools. - export_url = super().export_folder(user_name, password, f"/{folder_name}") + # export_url = super().export_folder(user_name, password, f"/{folder_name}") + export_url = self.export(folder_name) export_urls.append(export_url) # Write export url to resume file diff --git a/megaabuse/mega/__init__.py b/megaabuse/mega/__init__.py index 5481262..04d3981 100644 --- a/megaabuse/mega/__init__.py +++ b/megaabuse/mega/__init__.py @@ -26,7 +26,7 @@ class Mega: - def __init__(self, options=None): + def __init__(self): self.schema = 'https' self.domain = 'mega.co.nz' self.timeout = 160 # max secs to wait for resp from api requests @@ -35,10 +35,6 @@ def __init__(self, options=None): self.request_id = make_id(10) self._trash_folder_node_id = None - if options is None: - options = {} - self.options = options - def login(self, email=None, password=None): if email: self._login_user(email, password) From 561213d635332f7741843fda3f60740c3dac8acb Mon Sep 17 00:00:00 2001 From: 11philip22 Date: Tue, 4 May 2021 16:46:42 +0200 Subject: [PATCH 2/2] phase out megacmd --- clean.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 clean.sh diff --git a/clean.sh b/clean.sh old mode 100644 new mode 100755