From c4c7575000814a408951f9e048fc64fa6db140ed Mon Sep 17 00:00:00 2001 From: lzzy12 Date: Fri, 5 Jun 2020 14:01:36 +0530 Subject: [PATCH] Generate our own gid for mega mirrors Signed-off-by: lzzy12 --- .../mirror_utils/download_utils/mega_downloader.py | 6 ++++-- .../mirror_utils/status_utils/mega_download_status.py | 3 +-- bot/modules/mirror.py | 11 ++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bot/helper/mirror_utils/download_utils/mega_downloader.py b/bot/helper/mirror_utils/download_utils/mega_downloader.py index a7a52e1..1c8c987 100644 --- a/bot/helper/mirror_utils/download_utils/mega_downloader.py +++ b/bot/helper/mirror_utils/download_utils/mega_downloader.py @@ -4,7 +4,8 @@ from mega import (MegaApi, MegaListener, MegaRequest, MegaTransfer, MegaError) from bot.helper.telegram_helper.message_utils import update_all_messages import os from bot.helper.mirror_utils.status_utils.mega_download_status import MegaDownloadStatus - +import random +import string class MegaDownloaderException(Exception): pass @@ -137,7 +138,8 @@ class MegaDownloadHelper: node = mega_listener.node if mega_listener.error is not None: return listener.onDownloadError(str(mega_listener.error)) - mega_listener.setValues(node.getName(), api.getSize(node), mega_link.split("!", 1)[-1].split("!", 1)[0]) + gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=8)) + mega_listener.setValues(node.getName(), api.getSize(node), gid) with download_dict_lock: download_dict[listener.uid] = MegaDownloadStatus(mega_listener, listener) threading.Thread(target=executor.do, args=(api.startDownload, (node, path))).start() diff --git a/bot/helper/mirror_utils/status_utils/mega_download_status.py b/bot/helper/mirror_utils/status_utils/mega_download_status.py index bb5cf73..cc7f7b4 100644 --- a/bot/helper/mirror_utils/status_utils/mega_download_status.py +++ b/bot/helper/mirror_utils/status_utils/mega_download_status.py @@ -5,7 +5,7 @@ from .status import Status class MegaDownloadStatus(Status): - def __init__(self, obj,listener): + def __init__(self, obj, listener): self.uid = obj.uid self.listener = listener self.obj = obj @@ -22,7 +22,6 @@ class MegaDownloadStatus(Status): def progress(self): """Progress of download in percentage""" return f"{self.progress_raw()}%" - def status(self) -> str: return MirrorStatus.STATUS_DOWNLOADING diff --git a/bot/modules/mirror.py b/bot/modules/mirror.py index a6d2cd0..dc1c3fa 100644 --- a/bot/modules/mirror.py +++ b/bot/modules/mirror.py @@ -26,7 +26,7 @@ ariaDlManager.start_listener() class MirrorListener(listeners.MirrorListeners): - def __init__(self, bot, update, isTar=False,tag=None, extract=False): + def __init__(self, bot, update, isTar=False, tag=None, extract=False): super().__init__(bot, update) self.isTar = isTar self.tag = tag @@ -66,7 +66,7 @@ class MirrorListener(listeners.MirrorListeners): return elif self.extract: download.is_extracting = True - + path = fs_utils.get_base_name(m_path) if path != "unsupported": LOGGER.info( @@ -171,6 +171,7 @@ class MirrorListener(listeners.MirrorListeners): else: update_all_messages() + def _mirror(bot, update, isTar=False, extract=False): message_args = update.message.text.split(' ') try: @@ -214,9 +215,9 @@ def _mirror(bot, update, isTar=False, extract=False): listener = MirrorListener(bot, update, isTar, tag, extract) if bot_utils.is_mega_link(link): mega_dl = MegaDownloadHelper() - mega_dl.add_download(link,f'{DOWNLOAD_DIR}/{listener.uid}/',listener) + mega_dl.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) else: - ariaDlManager.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/',listener) + ariaDlManager.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) @@ -234,7 +235,7 @@ def tar_mirror(update, context): @run_async def unzip_mirror(update, context): - _mirror(context.bot,update, extract=True) + _mirror(context.bot, update, extract=True) mirror_handler = CommandHandler(BotCommands.MirrorCommand, mirror,