Esempio n. 1
0
def __onDownloadComplete(api, gid):
    LOGGER.info(f"onDownloadComplete: {gid}")
    dl = getDownloadByGid(gid)
    download = api.get_download(gid)
    if download.followed_by_ids:
        new_gid = download.followed_by_ids[0]
        new_download = api.get_download(new_gid)
        if dl is None:
            dl = getDownloadByGid(new_gid)
        with download_dict_lock:
            download_dict[dl.uid()] = AriaDownloadStatus(
                new_gid, dl.getListener())
        LOGGER.info(f'Changed gid from {gid} to {new_gid}')
    elif dl:
        Thread(target=dl.getListener().onDownloadComplete).start()
 def __onDownloadPause(self, api, gid):
     LOGGER.info(f"onDownloadPause: {gid}")
     dl = getDownloadByGid(gid)
     try:
         dl.getListener().onDownloadError('Download stopped by user!')
     except AttributeError:
         pass
Esempio n. 3
0
def __onDownloadStarted(api, gid):
    try:
        if any([
                STOP_DUPLICATE, TORRENT_DIRECT_LIMIT, ZIP_UNZIP_LIMIT,
                STORAGE_THRESHOLD
        ]):
            sleep(1.5)
            dl = getDownloadByGid(gid)
            if dl is None:
                return
            download = api.get_download(gid)
            if STOP_DUPLICATE and not dl.getListener().isLeech:
                LOGGER.info('Checking File/Folder if already in Drive...')
                sname = download.name
                if dl.getListener().isZip:
                    sname = sname + ".zip"
                elif dl.getListener().extract:
                    try:
                        sname = get_base_name(sname)
                    except:
                        sname = None
                if sname is not None:
                    smsg, button = GoogleDriveHelper().drive_list(sname, True)
                    if smsg:
                        dl.getListener().onDownloadError(
                            'File/Folder already available in Drive.\n\n')
                        api.remove([download], force=True, files=True)
                        return sendMarkup("Here are the search results:",
                                          dl.getListener().bot,
                                          dl.getListener().update, button)
            if any([ZIP_UNZIP_LIMIT, TORRENT_DIRECT_LIMIT, STORAGE_THRESHOLD]):
                sleep(1)
                limit = None
                size = api.get_download(gid).total_length
                arch = any([dl.getListener().isZip, dl.getListener().extract])
                if STORAGE_THRESHOLD is not None:
                    acpt = check_storage_threshold(size, arch, True)
                    # True if files allocated, if allocation disabled remove True arg
                    if not acpt:
                        msg = f'You must leave {STORAGE_THRESHOLD}GB free storage.'
                        msg += f'\nYour File/Folder size is {get_readable_file_size(size)}'
                        dl.getListener().onDownloadError(msg)
                        return api.remove([download], force=True, files=True)
                if ZIP_UNZIP_LIMIT is not None and arch:
                    mssg = f'Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB'
                    limit = ZIP_UNZIP_LIMIT
                elif TORRENT_DIRECT_LIMIT is not None:
                    mssg = f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}GB'
                    limit = TORRENT_DIRECT_LIMIT
                if limit is not None:
                    LOGGER.info('Checking File/Folder Size...')
                    if size > limit * 1024**3:
                        dl.getListener().onDownloadError(
                            f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}'
                        )
                        return api.remove([download], force=True, files=True)
    except:
        LOGGER.error(
            f"onDownloadStart: {gid} stop duplicate and size check didn't pass"
        )
Esempio n. 4
0
def cancel_mirror(update, context):
    args = update.message.text.split(" ", maxsplit=1)
    mirror_message = None
    if len(args) > 1:
        gid = args[1]
        dl = getDownloadByGid(gid)
        if not dl:
            sendMessage(f"GID: <code>{gid}</code> Not Found.", context.bot,
                        update)
            return
        mirror_message = dl.message
    elif update.message.reply_to_message:
        mirror_message = update.message.reply_to_message
        with download_dict_lock:
            keys = list(download_dict.keys())
            try:
                dl = download_dict[mirror_message.message_id]
            except:
                pass
    if len(args) == 1 and (not mirror_message
                           or mirror_message.message_id not in keys):
        msg = f"Reply to active <code>/{BotCommands.MirrorCommand}</code> message which was used to start the download or send <code>/{BotCommands.CancelMirror} GID</code> to cancel it!"
        sendMessage(msg, context.bot, update)
        return
    if dl.status() == MirrorStatus.STATUS_ARCHIVING:
        sendMessage("Archival in Progress, You Can't Cancel It.", context.bot,
                    update)
    elif dl.status() == MirrorStatus.STATUS_EXTRACTING:
        sendMessage("Extract in Progress, You Can't Cancel It.", context.bot,
                    update)
    elif dl.status() == MirrorStatus.STATUS_SPLITTING:
        sendMessage("Split in Progress, You Can't Cancel It.", context.bot,
                    update)
    else:
        dl.download().cancel_download()
Esempio n. 5
0
def cancel_mirror(update,context):
    args = update.message.text.split(" ",maxsplit=1)
    mirror_message = None
    if len(args) > 1:
        gid = args[1]
        dl = getDownloadByGid(gid)
        if not dl:
            sendMessage(f"GID: <code>{gid}</code> not found.",context.bot,update)
            return
        with download_dict_lock:
            keys = list(download_dict.keys())
        mirror_message = dl.message
    elif update.message.reply_to_message:
        mirror_message = update.message.reply_to_message
        with download_dict_lock:
            keys = list(download_dict.keys())
            dl = download_dict[mirror_message.message_id]
    if len(args) == 1:
        if mirror_message is None or mirror_message.message_id not in keys:
            if BotCommands.MirrorCommand in mirror_message.text or \
                    BotCommands.TarMirrorCommand in mirror_message.text:
                msg = "Mirror already have been cancelled"
                sendMessage(msg,context.bot,update)
                return
            else:
                msg = "Please reply to the /mirror message which was used to start the download or /cancel gid to cancel it!"
                sendMessage(msg,context.bot,update)
                return
    if dl.status() == "Uploading":
        dl.download().cancel_download()
    sleep(1)  # Wait a Second For Aria2 To free Resources.
    clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
        return
def xdcc_download(update, context):

    bot = context.bot
    message_args = update.message.text.split(' ', 2)
    try:
        server_channel = message_args[1]
    except IndexError:
        server_channel = ''
    server_channel = server_channel.strip()
    if not server_channel:
        sendMessage('You need to provide a channel to join.', bot, update)
        return

    try:
        command = message_args[2]
    except IndexError:
        command = message_args[2]

    if not command:
        sendMessage('You need to provide download command.', bot, update)
        return

    server_channel = server_channel.split(",")
    server_info = {}
    args = {}

    for each_info in server_channel:
        info = each_info.split("=")
        if info[0].lower() == "channel":
            args.update({info[0]: info[1]})
        else:
            server_info.update({info[0]: info[1]})
    tag = None

    pattern = r".* (.*?) xdcc (send|batch) (.*)"
    commands = re.match(pattern, command)
    args.update({
        "bot": commands.group(1),
        "action": commands.group(2),
        "packs": commands.group(3)
    })

    gid = format(binascii.crc32((args['bot'] + args['packs']).encode('utf8')),
                 '08x')
    if getDownloadByGid(gid):
        sendMessage('Mirror already in queue.', bot, update)
        return

    root = f"/{args['bot']} {args['packs']}/"
    listener = MirrorListener(bot, update, False, tag, root=root)
    xdcc_dl = XDCCDownload(listener)
    xdcc_dl.add_download(args, f'{DOWNLOAD_DIR}{listener.uid}/{root}')
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Esempio n. 7
0
 def __onDownloadComplete(self, api: API, gid):
     LOGGER.info(f"onDownloadComplete: {gid}")
     dl = getDownloadByGid(gid)
     download = api.get_download(gid)
     if download.followed_by_ids:
         new_gid = download.followed_by_ids[0]
         new_download = api.get_download(new_gid)
         if dl is None:
             dl = getDownloadByGid(new_gid)
         with download_dict_lock:
             download_dict[dl.uid()] = AriaDownloadStatus(
                 new_gid, dl.getListener())
             if new_download.is_torrent:
                 download_dict[dl.uid()].is_torrent = True
         update_all_messages()
         LOGGER.info(f"Changed gid from {gid} to {new_gid}")
     elif dl:
         threading.Thread(
             target=dl.getListener().onDownloadComplete).start()
Esempio n. 8
0
 def __onDownloadError(self, api, gid):
     sleep(
         0.5
     )  # sleep for split second to ensure proper dl gid update from onDownloadComplete
     LOGGER.info(f"onDownloadError: {gid}")
     dl = getDownloadByGid(gid)
     download = api.get_download(gid)
     error = download.error_message
     LOGGER.info(f"Download Error: {error}")
     if dl:
         dl.getListener().onDownloadError(error)
Esempio n. 9
0
def __onDownloadError(api, gid):
    LOGGER.info(f"onDownloadError: {gid}")
    sleep(0.5)
    dl = getDownloadByGid(gid)
    try:
        download = api.get_download(gid)
        error = download.error_message
        LOGGER.info(f"Download Error: {error}")
    except:
        pass
    if dl:
        dl.getListener().onDownloadError(error)
Esempio n. 10
0
def cancel_mirror(update, context):
    args = update.message.text.split(" ", maxsplit=1)
    mirror_message = None
    if len(args) > 1:
        gid = args[1]
        dl = getDownloadByGid(gid)
        if not dl:
            sendMessage(f"GID: <code>{gid}</code> Not Found.", context.bot,
                        update)
            return
        mirror_message = dl.message
    elif update.message.reply_to_message:
        mirror_message = update.message.reply_to_message
        with download_dict_lock:
            keys = list(download_dict.keys())
            try:
                dl = download_dict[mirror_message.message_id]
            except:
                pass
    if len(args) == 1:
        msg = f"Please reply to the <code>/{BotCommands.MirrorCommand}</code> message which was used to start the download or send <code>/{BotCommands.CancelMirror} GID</code> to cancel it!"
        if mirror_message and mirror_message.message_id not in keys:
            if BotCommands.MirrorCommand in mirror_message.text or \
               BotCommands.TarMirrorCommand in mirror_message.text or \
               BotCommands.UnzipMirrorCommand in mirror_message.text:
                msg1 = "Mirror Already Have Been Cancelled"
                sendMessage(msg1, context.bot, update)
                return
            else:
                sendMessage(msg, context.bot, update)
                return
        elif not mirror_message:
            sendMessage(msg, context.bot, update)
            return
    if dl.status() == "Uploading...๐Ÿ“ค":
        sendMessage("Upload in Progress, You Can't Cancel It.", context.bot,
                    update)
        return
    elif dl.status() == "Archiving...๐Ÿ”":
        sendMessage("Archival in Progress, You Can't Cancel It.", context.bot,
                    update)
        return
    elif dl.status() == "Extracting...๐Ÿ“‚":
        sendMessage("Extract in Progress, You Can't Cancel It.", context.bot,
                    update)
        return
    else:
        dl.download().cancel_download()
    sleep(
        3
    )  # incase of any error with ondownloaderror listener, clean_download will delete the folder but the download will stuck in status msg.
    clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
Esempio n. 11
0
def cancel_mirror(update, context):
    args = update.message.text.split(" ", maxsplit=1)
    mirror_message = None
    if len(args) > 1:
        gid = args[1]
        dl = getDownloadByGid(gid)
        if not dl:
            sendMessage(f"GID: <code>{gid}</code> not found.", context.bot,
                        update)
            return
        with download_dict_lock:
            keys = list(download_dict.keys())
        mirror_message = dl.message
    else:
        if update.message.reply_to_message:
            mirror_message = update.message.reply_to_message
            with download_dict_lock:
                try:
                    keys = list(download_dict.keys())
                    dl = download_dict[mirror_message.message_id]
                except:
                    sendMessage(
                        "It's not your msg, reply to your mirror msg which was used to start the download to cancel.",
                        context.bot, update)
                    return
        if not update.message.reply_to_message:
            pass

    try:
        if dl.status() == "Uploading...๐Ÿ“ค":
            sendMessage("Upload in progress, can't cancel.", context.bot,
                        update)
            return
        elif dl.status() == "Archiving...๐Ÿ”":
            sendMessage("Archival in progress, can't cancel.", context.bot,
                        update)
            return
        elif dl.status() == "Extracting...๐Ÿ“‚":
            sendMessage("Extract in progress, can't cancel.", context.bot,
                        update)
            return
        else:
            dl.download().cancel_download()
            sleep(1)  # Wait a Second For Aria2 To free Resources.
            clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
    except:
        psn = f"Please reply to your mirror msg which was used to start the download or <code>/{BotCommands.CancelMirror} GID</code> to cancel."
        sendMessage(psn, context.bot, update)
        return
Esempio n. 12
0
def __onDownloadStarted(api, gid):
    if STOP_DUPLICATE or TORRENT_DIRECT_LIMIT is not None or ZIP_UNZIP_LIMIT is not None:
        sleep(1.5)
        dl = getDownloadByGid(gid)
        download = api.get_download(gid)
        try:
            if STOP_DUPLICATE and dl is not None and not dl.getListener(
            ).isLeech:
                LOGGER.info('Checking File/Folder if already in Drive...')
                sname = download.name
                if dl.getListener().isZip:
                    sname = sname + ".zip"
                if not dl.getListener().extract:
                    smsg, button = GoogleDriveHelper().drive_list(sname, True)
                    if smsg:
                        dl.getListener().onDownloadError(
                            'File/Folder already available in Drive.\n\n')
                        api.remove([download], force=True, files=True)
                        sendMarkup("Here are the search results:",
                                   dl.getListener().bot,
                                   dl.getListener().update, button)
                        return
            if dl is not None and (ZIP_UNZIP_LIMIT is not None
                                   or TORRENT_DIRECT_LIMIT is not None):
                sleep(1)
                limit = None
                if ZIP_UNZIP_LIMIT is not None and (dl.getListener().isZip or
                                                    dl.getListener().extract):
                    mssg = f'Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB'
                    limit = ZIP_UNZIP_LIMIT
                elif TORRENT_DIRECT_LIMIT is not None:
                    mssg = f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}GB'
                    limit = TORRENT_DIRECT_LIMIT
                if limit is not None:
                    LOGGER.info('Checking File/Folder Size...')
                    size = api.get_download(gid).total_length
                    if size > limit * 1024**3:
                        dl.getListener().onDownloadError(
                            f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}'
                        )
                        api.remove([download], force=True, files=True)
                        return
        except:
            LOGGER.error(
                f"onDownloadStart: {gid} stop duplicate and size check didn't pass"
            )
Esempio n. 13
0
def get_confirm(update, context):
    query = update.callback_query
    user_id = query.from_user.id
    data = query.data
    data = data.split(" ")
    qbdl = getDownloadByGid(data[1])
    if qbdl is None:
        query.answer(text="This task has been cancelled!", show_alert=True)
        query.message.delete()
    elif user_id != qbdl.listener().message.from_user.id:
        query.answer(text="Don't waste your time!", show_alert=True)
    elif data[0] == "pin":
        query.answer(text=data[2], show_alert=True)
    elif data[0] == "done":
        query.answer()
        qbdl.client().torrents_resume(torrent_hashes=data[2])
        sendStatusMessage(qbdl.listener().update, qbdl.listener().bot)
        query.message.delete()
Esempio n. 14
0
def cancel_mirror(update, context):
    args = update.message.text.split(" ", maxsplit=1)
    mirror_message = None
    if len(args) > 1:
        gid = args[1]
        dl = getDownloadByGid(gid)
        if not dl:
            sendMessage(f"GID: <code>{gid}</code> not found.", context.bot,
                        update)
            return
        with download_dict_lock:
            keys = list(download_dict.keys())
        mirror_message = dl.message
    elif update.message.reply_to_message:
        mirror_message = update.message.reply_to_message
        with download_dict_lock:
            keys = list(download_dict.keys())
            dl = download_dict[mirror_message.message_id]
    if len(args) == 1:
        if mirror_message is None or mirror_message.message_id not in keys:
            if BotCommands.MirrorCommand in mirror_message.text or \
                    BotCommands.TarMirrorCommand in mirror_message.text:
                msg = "โ›ฝ๐Œ๐ข๐ซ๐ซ๐จ๐ซ ๐Ž๐Ÿ ๐˜๐จ๐ฎ๐ซ ๐…๐ข๐ฅ๐ž ๐€๐ฅ๐ซ๐ž๐š๐๐ฒ ๐‡๐š๐ฏ๐ž ๐๐ž๐ž๐ง ๐‚๐š๐ง๐œ๐ž๐ฅ๐ฅ๐ž๐"
                sendMessage(msg, context.bot, update)
                return
            else:
                msg = "โ›ฝ๐๐ฅ๐ž๐š๐ฌ๐ž ๐‘๐ž๐ฉ๐ฅ๐ฒ ๐“๐จ ๐“๐ก๐ž /mirror ๐Œ๐ž๐ฌ๐ฌ๐š๐ ๐ž ๐–๐ก๐ข๐œ๐ก ๐–๐š๐ฌ ๐”๐ฌ๐ž๐ ๐“๐จ ๐’๐ญ๐š๐ซ๐ญ ๐“๐ก๐ž ๐ƒ๐จ๐ฐ๐ง๐ฅ๐จ๐š๐ ๐จ๐ซ /cancel ๐†๐ข๐ ๐“๐จ ๐‚๐š๐ง๐œ๐ž๐ฅ ๐ˆ๐ญ!"
                sendMessage(msg, context.bot, update)
                return
    if dl.status() == "๐”๐ฉ๐ฅ๐จ๐š๐๐ข๐ง๐  ๐Ÿ“ค...":
        sendMessage(
            "โ›ฝ๐”๐ฉ๐ฅ๐จ๐š๐๐ข๐ง๐  ๐Ž๐Ÿ ๐˜๐จ๐ฎ๐ซ ๐…๐ข๐ฅ๐ž ๐ˆ๐ฌ ๐€๐ฅ๐ซ๐ž๐š๐๐ฒ ๐ˆ๐ง ๐๐ซ๐จ๐ ๐ซ๐ž๐ฌ๐ฌ, ๐ƒ๐จ๐ง'๐ญ ๐‚๐š๐ง๐œ๐ž๐ฅ ๐ˆ๐ญ.",
            context.bot, update)
        return
    elif dl.status() == "๐€๐ซ๐œ๐ก๐ข๐ฏ๐ข๐ง๐  ๐Ÿ—ƒ๏ธ๐Ÿ”...":
        sendMessage(
            "โ›ฝ๐€๐ซ๐œ๐ก๐ข๐ฏ๐š๐ฅ ๐Ž๐Ÿ ๐˜๐จ๐ฎ๐ซ ๐…๐ข๐ฅ๐ž ๐ˆ๐ฌ ๐ˆ๐ง ๐€๐ฅ๐ซ๐ž๐š๐๐ฒ ๐๐ซ๐จ๐ ๐ซ๐ž๐ฌ๐ฌ, ๐ƒ๐จ๐ง'๐ญ ๐‚๐š๐ง๐œ๐ž๐ฅ ๐ˆ๐ญ.",
            context.bot, update)
        return
    else:
        dl.download().cancel_download()
    sleep(1)  # Wait a Second For Aria2 To free Resources.
    clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
Esempio n. 15
0
def cancel_mirror(update, context):
    args = update.message.text.split(" ", maxsplit=1)
    mirror_message = None
    if len(args) > 1:
        gid = args[1]
        dl = getDownloadByGid(gid)
        if not dl:
            sendMessage(f"<b>Gษชแด…:</b> <code>{gid}</code> <b>Nแดแด› Fแดแดœษดแด…๐Ÿšซ.</b>",
                        context.bot, update)
            return
        with download_dict_lock:
            keys = list(download_dict.keys())
        mirror_message = dl.message
    elif update.message.reply_to_message:
        mirror_message = update.message.reply_to_message
        with download_dict_lock:
            keys = list(download_dict.keys())
            dl = download_dict[mirror_message.message_id]
    if len(args) == 1:
        if mirror_message is None or mirror_message.message_id not in keys:
            if BotCommands.MirrorCommand in mirror_message.text or \
                    BotCommands.TarMirrorCommand in mirror_message.text:
                msg = "<b>โ˜˜๏ธMษชส€ส€แดส€ AสŸส€แด‡แด€แด…ส Hแด€แด แด‡ Bแด‡แด‡ษด Cแด€ษดแด„แด‡สŸสŸแด‡แด…</b>"
                sendMessage(msg, context.bot, update)
                return
            else:
                msg = "<b>โ›ฝPสŸแด‡แด€sแด‡ Rแด‡แด˜สŸส Tแด Tสœแด‡</b> /{BotCommands.MirrorCommand} <b>Mแด‡ssแด€ษขแด‡ Wสœษชแด„สœ Wแด€s Usแด‡แด… Tแด Sแด›แด€ส€แด› Tสœแด‡ DแดแดกษดสŸแดแด€แด… Oส€</b> /{BotCommands.CancelMirror} <b>Gษชแด… Tแด Cแด€ษดแด„แด‡สŸ Mษชส€ส€แดส€ Yแดแดœส€ Pส€แดแด„แด‡ss!</b>"
                sendMessage(msg, context.bot, update)
                return
    if dl.status() == "Uploading":
        sendMessage(
            "<b>๐Ÿ“คUแด˜สŸแดแด€แด… O๊œฐ Yแดแดœส€ FษชสŸแด‡ Is AสŸส€แด‡แด€แด…ส Iษด Pส€แดษขส€แด‡ss, PสŸแด‡แด€sแด‡ ๐ŸšซDแดษด'แด› Cแด€ษดแด„แด‡สŸ Iแด›!</b>",
            context.bot, update)
        return
    elif dl.status() == "Archiving":
        sendMessage(
            "<b>๐Ÿ”Aส€แด„สœษชแด แด€สŸ O๊œฐ Yแดแดœส€ FษชสŸแด‡ Is AสŸส€แด‡แด€แด…ส Iษด Pส€แดษขส€แด‡ss, PสŸแด‡แด€sแด‡ ๐ŸšซDแดษด'แด› Cแด€ษดแด„แด‡สŸ Iแด›!</b>",
            context.bot, update)
        return
    else:
        dl.download().cancel_download()
    sleep(1)  # Wait a Second For Aria2 To free Resources.
    clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
Esempio n. 16
0
def cancel_mirror(update, context):
    args = update.message.text.split(" ", maxsplit=1)
    mirror_message = None
    if len(args) > 1:
        gid = args[1]
        dl = getDownloadByGid(gid)
        if not dl:
            sendMessage(f"GID: <code>{gid}</code> not found.", context.bot, update)
            return
        with download_dict_lock:
            keys = list(download_dict.keys())
        mirror_message = dl.message
    elif update.message.reply_to_message:
        mirror_message = update.message.reply_to_message
        with download_dict_lock:
            keys = list(download_dict.keys())
            dl = download_dict[mirror_message.message_id]
    if len(args) == 1:
        if mirror_message is None or mirror_message.message_id not in keys:
            if BotCommands.MirrorCommand in update.message.text or \
               BotCommands.TarMirrorCommand in update.message.text or \
               BotCommands.UnzipMirrorCommand in update.message.text:
                msg = "Mirror Already Have Been Cancelled"
                sendMessage(msg, context.bot, update)
                return
            else:
                msg = f"Please reply to the <code>/{BotCommands.MirrorCommand}</code> message which was used to start the download or <code>/{BotCommands.CancelMirror} GID</code> to cancel it!"
                sendMessage(msg, context.bot, update)
                return
    if dl.status() == "Uploading...๐Ÿ“ค":
        sendMessage("Upload in Progress, You Can't Cancel It.", context.bot, update)
        return
    elif dl.status() == "Archiving...๐Ÿ”":
        sendMessage("Archival in Progress, You Can't Cancel It.", context.bot, update)
        return
    elif dl.status() == "Extracting...๐Ÿ“‚":
        sendMessage("Extract in Progress, You Can't Cancel It.", context.bot, update)
        return
    else:
        dl.download().cancel_download()
    sleep(1)  # Wait a Second For Aria2 To free Resources.
    clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
Esempio n. 17
0
def cancel_mirror(update, context):
    args = update.message.text.split(" ", maxsplit=1)
    mirror_message = None
    if len(args) > 1:
        gid = args[1]
        dl = getDownloadByGid(gid)
        if not dl:
            sendMessage(f"๐—š๐—œ๐——: <code>{gid}</code> not found.", context.bot,
                        update)
            return
        with download_dict_lock:
            keys = list(download_dict.keys())
        mirror_message = dl.message
    elif update.message.reply_to_message:
        mirror_message = update.message.reply_to_message
        with download_dict_lock:
            keys = list(download_dict.keys())
            dl = download_dict[mirror_message.message_id]
    if len(args) == 1:
        if mirror_message is None or mirror_message.message_id not in keys:
            if BotCommands.MirrorCommand in mirror_message.text or \
                    BotCommands.TarMirrorCommand in mirror_message.text:
                msg = "๐—ง๐—ผ๐—ฟ๐—ฟ๐—ฒ๐—ป๐˜ ๐—ฎ๐—น๐—ฟ๐—ฒ๐—ฎ๐—ฑ๐˜† ๐—ต๐—ฎ๐˜ƒ๐—ฒ ๐—ฏ๐—ฒ๐—ฒ๐—ป ๐—–๐—ฎ๐—ป๐—ฐ๐—ฒ๐—น๐—น๐—ฒ๐—ฑ"
                sendMessage(msg, context.bot, update)
                return
            else:
                msg = "Please reply to the /mirror message which was used to start the download or /cancel gid to cancel it!"
                sendMessage(msg, context.bot, update)
                return
    if dl.status() == "Uploading":
        sendMessage("Upload in Progress, Don't Cancel it.", context.bot,
                    update)
        return
    elif dl.status() == "Archiving":
        sendMessage("Archival in Progress, Don't Cancel it.", context.bot,
                    update)
        return
    else:
        dl.download().cancel_download()
    sleep(1)  # Wait a Second For Aria2 To free Resources.
    clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
Esempio n. 18
0
def cancel_mirror(update, context):
    args = update.message.text.split(" ", maxsplit=1)
    mirror_message = None
    if len(args) > 1:
        gid = args[1]
        dl = getDownloadByGid(gid)
        if not dl:
            sendMessage(
                f"ID yang kamu mirror: <code>{gid}</code> Gak ditemukan.",
                context.bot, update)
            return
        with download_dict_lock:
            keys = list(download_dict.keys())
        mirror_message = dl.message
    elif update.message.reply_to_message:
        mirror_message = update.message.reply_to_message
        with download_dict_lock:
            keys = list(download_dict.keys())
            dl = download_dict[mirror_message.message_id]
    if len(args) == 1:
        if mirror_message is None or mirror_message.message_id not in keys:
            if BotCommands.MirrorCommand in mirror_message.text or \
                    BotCommands.TarMirrorCommand in mirror_message.text:
                msg = "Mirror nya udah aku berhentiin ya"
                sendMessage(msg, context.bot, update)
                return
            else:
                msg = "Kalo pengen nge mirror pake /kaca sama kalo pengen batalin pake /gagal"
                sendMessage(msg, context.bot, update)
                return
    if dl.status() == "Lagi upload":
        sendMessage("Lagi Proses upload jangan digagalin.", context.bot,
                    update)
        return
    elif dl.status() == "Lagi Nge Arsip":
        sendMessage("Lagi Nge arsip jangan dibatalin.", context.bot, update)
        return
    else:
        dl.download().cancel_download()
    sleep(1)  # Wait a Second For Aria2 To free Resources.
    clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
Esempio n. 19
0
def cancel_mirror(client: Client, message: Message):
    args = message.text.split(" ", maxsplit=1)
    mirror_message = None
    if len(args) > 1:
        gid = args[1]
        dl = getDownloadByGid(gid)
        if not dl:
            sendMessage(f"GID: <code>{gid}</code> not found.", client, message)
            return
        with download_dict_lock:
            keys = list(download_dict.keys())
        mirror_message = dl.message
    elif message.reply_to_message:
        mirror_message = message.reply_to_message
        with download_dict_lock:
            keys = list(download_dict.keys())
            dl = download_dict[mirror_message.message_id]
    if len(args) == 1:
        if mirror_message is None or mirror_message.message_id not in keys:
            if BotCommands.MirrorCommand in mirror_message.text or \
                    BotCommands.TarMirrorCommand in mirror_message.text:
                msg = "Mirror already have been cancelled"
                sendMessage(msg, client, message)
                return
            else:
                msg = "Please reply to the /mirror message which was used to start the download or /cancel gid to cancel it!"
                sendMessage(msg, client, message)
                return
    if dl.status() == "Uploading":
        sendMessage("Upload in Progress, Don't Cancel it.", client, message)
        return
    elif dl.status() == "Archiving":
        sendMessage("Archival in Progress, Don't Cancel it.", client, message)
        return
    else:
        dl.download().cancel_download()
    sleep(1)  # Wait a Second For Aria2 To free Resources.
    clean_download(
        os.path.join(DOWNLOAD_DIR, str(mirror_message.message_id)) +
        os.path.sep)
def cancel_mirror(update, context):
    args = update.message.text.split(" ", maxsplit=1)
    mirror_message = None
    if len(args) > 1:
        gid = args[1]
        dl = getDownloadByGid(gid)
        if not dl:
            sendMessage(f"GID: <code>{gid}</code> khรดng tรฌm thแบฅy.",
                        context.bot, update)
            return
        with download_dict_lock:
            keys = list(download_dict.keys())
        mirror_message = dl.message
    elif update.message.reply_to_message:
        mirror_message = update.message.reply_to_message
        with download_dict_lock:
            keys = list(download_dict.keys())
            dl = download_dict[mirror_message.message_id]
    if len(args) == 1:
        if mirror_message is None or mirror_message.message_id not in keys:
            if BotCommands.MirrorCommand in mirror_message.text or \
                    BotCommands.TarMirrorCommand in mirror_message.text:
                msg = "Mirror already have been cancelled"
                sendMessage(msg, context.bot, update)
                return
            else:
                msg = "Vui lรฒng trแบฃ lแปi tin nhแบฏn /mirror ฤ‘ฦฐแปฃc sแปญ dแปฅng ฤ‘แปƒ bแบฏt ฤ‘แบงu tแบฃi xuแป‘ng hoแบทc /cancel gid ฤ‘แปƒ hแปงy nรณ!"
                sendMessage(msg, context.bot, update)
                return
    if dl.status() == "Uploading":
        sendMessage("ฤang tแบฃi lรชn, vui lรฒng khรดng hแปงy.", context.bot, update)
        return
    elif dl.status() == "Archiving":
        sendMessage("ฤang tiแบฟn hร nh lฦฐu trแปฏ, vui lรฒng khรดng hแปงy bแป.",
                    context.bot, update)
        return
    else:
        dl.download().cancel_download()
    sleep(1)  # Wait a Second For Aria2 To free Resources.
    clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
 def __onDownloadComplete(self, api: API, gid):
     LOGGER.info(f"onDownloadComplete: {gid}")
     dl = getDownloadByGid(gid)
     download = api.get_download(gid)
     if download.followed_by_ids:
         new_gid = download.followed_by_ids[0]
         new_download = api.get_download(new_gid)
         with download_dict_lock:
             download_dict[dl.uid()] = AriaDownloadStatus(
                 new_gid, dl.getListener(), self)
             if new_download.is_torrent:
                 download_dict[dl.uid()].is_torrent = True
         update_all_messages()
         LOGGER.info(f'Changed gid from {gid} to {new_gid}')
         return
     if dl:
         queue = self.queue_dict[dl.uid()]
         if queue.current_download != queue.queue_length:
             self.__startNextDownload(dl.uid())
             return
         threading.Thread(
             target=dl.getListener().onDownloadComplete).start()
Esempio n. 22
0
 def __onDownloadStopped(self, api, gid):
     LOGGER.info(f"onDownloadStop: {gid}")
     dl = getDownloadByGid(gid)
     if dl:
         dl.getListener().onDownloadError("Download stopped by user!")
 def __onDownloadStarted(self, api, gid):
     LOGGER.info(f"onDownloadStart: {gid}")
     dl = getDownloadByGid(gid)
     if dl:
         self.queue_dict[dl.uid()].name = api.get_download(gid).name
     update_all_messages()
Esempio n. 24
0
def __onDownloadStopped(api, gid):
    sleep(4)
    dl = getDownloadByGid(gid)
    if dl:
        dl.getListener().onDownloadError('Dead torrent!')