Example #1
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 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
Example #3
0
def cancel_mirror(bot, update):
    mirror_message = update.message.reply_to_message
    with download_dict_lock:
        keys = download_dict.keys()
        dl = download_dict[mirror_message.message_id]
    if mirror_message is None or mirror_message.message_id not in keys:
        if '/mirror' in mirror_message.text or '/tarmirror' in mirror_message.text:
            msg = 'Message has already been cancelled'
        else:
            msg = 'Please reply to the /mirror message which was used to start the download to cancel it!'
        sendMessage(msg, bot, update)
        return
    if dl.status() == "Uploading":
        sendMessage("Upload in Progress, Don't Cancel it.", bot, update)
        return
    elif dl.status() == "Archiving":
        sendMessage("Archival in Progress, Don't Cancel it.", bot, update)
        return
    elif dl.status() != "Queued":
        download = dl.download()
        if len(download.followed_by_ids) != 0:
            downloads = aria2.get_downloads(download.followed_by_ids)
            aria2.pause(downloads)
        aria2.pause([download])
    else:
        dl._listener.onDownloadError("Download stopped by user!")
    sleep(1)  # Wait a Second For Aria2 To free Resources.
    clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
Example #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()
Example #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 = "โ›ฝ๐Œ๐ข๐ซ๐ซ๐จ๐ซ ๐Ž๐Ÿ ๐˜๐จ๐ฎ๐ซ ๐…๐ข๐ฅ๐ž ๐€๐ฅ๐ซ๐ž๐š๐๐ฒ ๐‡๐š๐ฏ๐ž ๐๐ž๐ž๐ง ๐‚๐š๐ง๐œ๐ž๐ฅ๐ฅ๐ž๐"
                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}/')
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}/')
Example #7
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}/')
Example #8
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}/')
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}/')
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}/')
Example #11
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)
Example #12
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}/')
def cancel_mirror(update: Update, context):
    mirror_message = update.message.reply_to_message
    with download_dict_lock:
        keys = download_dict.keys()
        download = download_dict[mirror_message.message_id].download()
    if mirror_message is None or mirror_message.message_id not in keys:
        if '/mirror' in mirror_message.text or '/tarmirror' in mirror_message.text:
            msg = 'Message has already been cancelled'
        else:
            msg = 'Please reply to the /mirror message which was used to start the download to cancel it!'
        return
    else:
        msg = 'Download cancelled'
    sendMessage(msg, context, update)
    if len(download.followed_by_ids) != 0:
        downloads = aria2.get_downloads(download.followed_by_ids)
        aria2.pause(downloads)
    aria2.pause([download])
    with download_dict_lock:
        upload_helper = download_dict[mirror_message.message_id].upload_helper
    if upload_helper is not None:
        upload_helper.cancel()
    sleep(1)  #Wait a Second For Aria2 To free Resources.
    clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
Example #14
0
def _qb_listener(listener, client, gid, ext_hash, select, meta_time, path):
    stalled_time = time()
    uploaded = False
    sizeChecked = False
    dupChecked = False
    rechecked = False
    get_info = 0
    while True:
        sleep(4)
        tor_info = client.torrents_info(torrent_hashes=ext_hash)
        if len(tor_info) == 0:
            with download_dict_lock:
                if listener.uid not in list(download_dict.keys()):
                    client.auth_log_out()
                    break
            get_info += 1
            if get_info > 10:
                client.auth_log_out()
                break
            continue
        get_info = 0
        try:
            tor_info = tor_info[0]
            if tor_info.state == "metaDL":
                stalled_time = time()
                if time(
                ) - meta_time >= 999999999:  # timeout while downloading metadata
                    client.torrents_pause(torrent_hashes=ext_hash)
                    sleep(0.3)
                    listener.onDownloadError("Dead Torrent!")
                    client.torrents_delete(torrent_hashes=ext_hash,
                                           delete_files=True)
                    client.auth_log_out()
                    break
            elif tor_info.state == "downloading":
                stalled_time = time()
                if STOP_DUPLICATE and not listener.isLeech and not dupChecked and ospath.isdir(
                        f'{path}'):
                    LOGGER.info('Checking File/Folder if already in Drive')
                    qbname = str(listdir(f'{path}')[-1])
                    if qbname.endswith('.!qB'):
                        qbname = ospath.splitext(qbname)[0]
                    if listener.isZip:
                        qbname = qbname + ".zip"
                    if not listener.extract:
                        qbmsg, button = GoogleDriveHelper().drive_list(
                            qbname, True)
                        if qbmsg:
                            msg = "File/Folder is already available in Drive."
                            client.torrents_pause(torrent_hashes=ext_hash)
                            sleep(0.3)
                            listener.onDownloadError(msg)
                            sendMarkup("Here are the search results:",
                                       listener.bot, listener.update, button)
                            client.torrents_delete(torrent_hashes=ext_hash,
                                                   delete_files=True)
                            client.auth_log_out()
                            break
                    dupChecked = True
                if not sizeChecked:
                    limit = None
                    if ZIP_UNZIP_LIMIT is not None and (listener.isZip
                                                        or listener.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 limit is {TORRENT_DIRECT_LIMIT}GB'
                        limit = TORRENT_DIRECT_LIMIT
                    if limit is not None:
                        LOGGER.info('Checking File/Folder Size...')
                        sleep(1)
                        size = tor_info.size
                        if size > limit * 1024**3:
                            client.torrents_pause(torrent_hashes=ext_hash)
                            sleep(0.3)
                            listener.onDownloadError(
                                f"{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}"
                            )
                            client.torrents_delete(torrent_hashes=ext_hash,
                                                   delete_files=True)
                            client.auth_log_out()
                            break
                    sizeChecked = True
            elif tor_info.state == "stalledDL":
                if not rechecked and 0.99989999999999999 < tor_info.progress < 1:
                    LOGGER.info(
                        f"Force recheck - Name: {tor_info.name} Hash: {ext_hash} Downloaded Bytes: {tor_info.downloaded} Size: {tor_info.size} Total Size: {tor_info.total_size}"
                    )
                    client.torrents_recheck(torrent_hashes=ext_hash)
                    rechecked = True
                elif time(
                ) - stalled_time >= 999999999:  # timeout after downloading metadata
                    client.torrents_pause(torrent_hashes=ext_hash)
                    sleep(0.3)
                    listener.onDownloadError("Dead Torrent!")
                    client.torrents_delete(torrent_hashes=ext_hash,
                                           delete_files=True)
                    client.auth_log_out()
                    break
            elif tor_info.state == "missingFiles":
                client.torrents_recheck(torrent_hashes=ext_hash)
            elif tor_info.state == "error":
                client.torrents_pause(torrent_hashes=ext_hash)
                sleep(0.3)
                listener.onDownloadError(
                    "No enough space for this torrent on device")
                client.torrents_delete(torrent_hashes=ext_hash,
                                       delete_files=True)
                client.auth_log_out()
                break
            elif tor_info.state in [
                    "uploading", "queuedUP", "stalledUP", "forcedUP"
            ] and not uploaded:
                uploaded = True
                if not QB_SEED:
                    client.torrents_pause(torrent_hashes=ext_hash)
                if select:
                    for dirpath, subdir, files in walk(f"{path}",
                                                       topdown=False):
                        for filee in files:
                            if filee.endswith(".!qB") or filee.endswith(
                                    '.parts') and filee.startswith('.'):
                                osremove(ospath.join(dirpath, filee))
                        for folder in subdir:
                            if folder == ".unwanted":
                                rmtree(ospath.join(dirpath, folder))
                    for dirpath, subdir, files in walk(f"{path}",
                                                       topdown=False):
                        if not listdir(dirpath):
                            rmdir(dirpath)
                listener.onDownloadComplete()
                if QB_SEED:
                    with download_dict_lock:
                        if listener.uid not in list(download_dict.keys()):
                            client.torrents_delete(torrent_hashes=ext_hash,
                                                   delete_files=True)
                            client.auth_log_out()
                            break
                        download_dict[listener.uid] = QbDownloadStatus(
                            listener, client, gid, ext_hash, select)
                    update_all_messages()
                    LOGGER.info(f"Seeding started: {tor_info.name}")
                else:
                    client.torrents_delete(torrent_hashes=ext_hash,
                                           delete_files=True)
                    client.auth_log_out()
                    break
            elif tor_info.state == 'pausedUP' and QB_SEED:
                listener.onUploadError(
                    f"Seeding stopped with Ratio: {round(tor_info.ratio, 3)} and Time: {get_readable_time(tor_info.seeding_time)}"
                )
                client.torrents_delete(torrent_hashes=ext_hash,
                                       delete_files=True)
                client.auth_log_out()
                break
        except:
            pass
Example #15
0
def _qb_listener(listener, client, ext_hash, select, path):
    stalled_time = time()
    uploaded = False
    sizeChecked = False
    dupChecked = False
    rechecked = False
    while True:
        sleep(4)
        try:
            tor_info = client.torrents_info(torrent_hashes=ext_hash)
            if len(tor_info) == 0:
                with download_dict_lock:
                    if listener.uid not in list(download_dict.keys()):
                        client.auth_log_out()
                        break
                continue
            tor_info = tor_info[0]
            if tor_info.state == "metaDL":
                stalled_time = time()
                if QB_TIMEOUT is not None and time(
                ) - tor_info.added_on >= QB_TIMEOUT:  #timeout while downloading metadata
                    _onDownloadError("Dead Torrent!", client, ext_hash,
                                     listener)
                    break
            elif tor_info.state == "downloading":
                stalled_time = time()
                if STOP_DUPLICATE and not dupChecked and ospath.isdir(
                        f'{path}') and not listener.isLeech:
                    LOGGER.info('Checking File/Folder if already in Drive')
                    qbname = str(listdir(f'{path}')[-1])
                    if qbname.endswith('.!qB'):
                        qbname = ospath.splitext(qbname)[0]
                    if listener.isZip:
                        qbname = qbname + ".zip"
                    elif listener.extract:
                        try:
                            qbname = get_base_name(qbname)
                        except:
                            qbname = None
                    if qbname is not None:
                        qbmsg, button = GoogleDriveHelper().drive_list(
                            qbname, True)
                        if qbmsg:
                            msg = "File/Folder is already available in Drive."
                            _onDownloadError(msg, client, ext_hash, listener)
                            sendMarkup("Here are the search results:",
                                       listener.bot, listener.update, button)
                            break
                    dupChecked = True
                if not sizeChecked:
                    sleep(1)
                    size = tor_info.size
                    arch = any([listener.isZip, listener.extract])
                    if STORAGE_THRESHOLD is not None:
                        acpt = check_storage_threshold(size, arch)
                        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)}'
                            _onDownloadError(msg, client, ext_hash, listener)
                            break
                    limit = None
                    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 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:
                            fmsg = f"{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}"
                            _onDownloadError(fmsg, client, ext_hash, listener)
                            break
                    sizeChecked = True
            elif tor_info.state == "stalledDL":
                if not rechecked and 0.99989999999999999 < tor_info.progress < 1:
                    msg = f"Force recheck - Name: {tor_info.name} Hash: "
                    msg += f"{ext_hash} Downloaded Bytes: {tor_info.downloaded} "
                    msg += f"Size: {tor_info.size} Total Size: {tor_info.total_size}"
                    LOGGER.info(msg)
                    client.torrents_recheck(torrent_hashes=ext_hash)
                    rechecked = True
                elif QB_TIMEOUT is not None and time(
                ) - stalled_time >= QB_TIMEOUT:  # timeout after downloading metadata
                    _onDownloadError("Dead Torrent!", client, ext_hash,
                                     listener)
                    break
            elif tor_info.state == "missingFiles":
                client.torrents_recheck(torrent_hashes=ext_hash)
            elif tor_info.state == "error":
                _onDownloadError("No enough space for this torrent on device",
                                 client, ext_hash, listener)
                break
            elif (tor_info.state.lower().endswith("up")
                  or tor_info.state == "uploading") and not uploaded:
                LOGGER.info(f"onQbDownloadComplete: {ext_hash}")
                uploaded = True
                if not QB_SEED:
                    client.torrents_pause(torrent_hashes=ext_hash)
                if select:
                    clean_unwanted(path)
                listener.onDownloadComplete()
                if QB_SEED and not listener.isLeech and not listener.extract:
                    with download_dict_lock:
                        if listener.uid not in list(download_dict.keys()):
                            client.torrents_delete(torrent_hashes=ext_hash,
                                                   delete_files=True)
                            client.auth_log_out()
                            break
                        download_dict[listener.uid] = QbDownloadStatus(
                            listener, client, ext_hash, select)
                    update_all_messages()
                    LOGGER.info(f"Seeding started: {tor_info.name}")
                else:
                    client.torrents_delete(torrent_hashes=ext_hash,
                                           delete_files=True)
                    client.auth_log_out()
                    break
            elif tor_info.state == 'pausedUP' and QB_SEED:
                listener.onUploadError(
                    f"Seeding stopped with Ratio: {round(tor_info.ratio, 3)} and Time: {get_readable_time(tor_info.seeding_time)}"
                )
                client.torrents_delete(torrent_hashes=ext_hash,
                                       delete_files=True)
                client.auth_log_out()
                update_all_messages()
                break
        except Exception as e:
            LOGGER.error(str(e))