Skip to content

Commit

Permalink
Generate our own gid for mega mirrors
Browse files Browse the repository at this point in the history
Signed-off-by: lzzy12 <[email protected]>
  • Loading branch information
lzzy12 committed Jun 5, 2020
1 parent c791b39 commit c4c7575
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions bot/helper/mirror_utils/download_utils/mega_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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
Expand Down Expand Up @@ -137,7 +138,8 @@ def add_download(self, mega_link: str, path: str, listener):
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()
Expand Down
3 changes: 1 addition & 2 deletions bot/helper/mirror_utils/status_utils/mega_download_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class MegaDownloadStatus(Status):

def __init__(self, obj,listener):
def __init__(self, obj, listener):
self.uid = obj.uid
self.listener = listener
self.obj = obj
Expand All @@ -22,7 +22,6 @@ def progress_raw(self):
def progress(self):
"""Progress of download in percentage"""
return f"{self.progress_raw()}%"


def status(self) -> str:
return MirrorStatus.STATUS_DOWNLOADING
Expand Down
11 changes: 6 additions & 5 deletions bot/modules/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


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
Expand Down Expand Up @@ -66,7 +66,7 @@ def onDownloadComplete(self):
return
elif self.extract:
download.is_extracting = True

path = fs_utils.get_base_name(m_path)
if path != "unsupported":
LOGGER.info(
Expand Down Expand Up @@ -171,6 +171,7 @@ def onUploadError(self, error):
else:
update_all_messages()


def _mirror(bot, update, isTar=False, extract=False):
message_args = update.message.text.split(' ')
try:
Expand Down Expand Up @@ -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))
Expand All @@ -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,
Expand Down

0 comments on commit c4c7575

Please sign in to comment.