From b67db09e2305b73aa9d1e6e4ce139f5a712f0af7 Mon Sep 17 00:00:00 2001 From: anasty17 Date: Sat, 30 Dec 2023 18:37:34 +0200 Subject: [PATCH] Temporary fix for subfolders in jdownloader Signed-off-by: anasty17 --- bot/helper/ext_utils/jdownloader_booter.py | 8 +++++--- bot/helper/listeners/jdownloader_listener.py | 2 +- .../mirror_utils/download_utils/jd_download.py | 15 ++++++--------- .../status_utils/jdownloader_status.py | 4 ++-- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/bot/helper/ext_utils/jdownloader_booter.py b/bot/helper/ext_utils/jdownloader_booter.py index 7eb6fb4c0aa..c4a6e972ede 100644 --- a/bot/helper/ext_utils/jdownloader_booter.py +++ b/bot/helper/ext_utils/jdownloader_booter.py @@ -114,7 +114,7 @@ def connectToDevice(self): continue break self.device.enable_direct_connection() - LOGGER.info("JDownloader Device is Connected!") + LOGGER.info("JDownloader Device have been Connected!") @new_task async def keepJdAlive(self): @@ -122,7 +122,9 @@ async def keepJdAlive(self): await aiosleep(180) if self.device is None: break - await sync_to_async(self.reconnect) - + try: + await sync_to_async(self.reconnect) + except: + pass jdownloader = JDownloader() diff --git a/bot/helper/listeners/jdownloader_listener.py b/bot/helper/listeners/jdownloader_listener.py index 2401d0e2613..701080bcb93 100644 --- a/bot/helper/listeners/jdownloader_listener.py +++ b/bot/helper/listeners/jdownloader_listener.py @@ -16,7 +16,7 @@ async def _onDownloadComplete(gid): jdownloader.device.downloads.cleanup, "DELETE_DISABLED", "REMOVE_LINKS_AND_DELETE_FILES", - "ALL", + "SELECTED", package_ids=[gid], ) await task.listener.onDownloadComplete() diff --git a/bot/helper/mirror_utils/download_utils/jd_download.py b/bot/helper/mirror_utils/download_utils/jd_download.py index 748f9a9f24c..24b0d08b241 100644 --- a/bot/helper/mirror_utils/download_utils/jd_download.py +++ b/bot/helper/mirror_utils/download_utils/jd_download.py @@ -125,29 +125,26 @@ async def add_jd_download(listener, path): ], ) packages = [] - size = 0 - exists = False for pack in queued_downloads: if pack["saveTo"] == path: if len(packages) == 0: name = pack["name"] gid = pack["uuid"] + size = pack.get("bytesTotal", 0) jd_downloads[gid] = "collect" - if pack["onlineCount"] == 0: + if pack.get("onlineCount", 1) == 0: await listener.onDownloadError(name) return packages.append(pack["uuid"]) - size += pack.get("bytesTotal", 0) - exists = True if len(packages) > 1: await retry_function( jdownloader.device.action, - "/linkgrabberv2/movePackages", - [packages[1:], packages[0]], + "/linkgrabberv2/movetoNewPackage", + [[], packages, name, path], ) - if exists: + if len(packages) == 1: break listener.name = listener.name or name @@ -188,7 +185,7 @@ async def add_jd_download(listener, path): [gid], ) - await sleep(1) + await sleep(0.5) download_packages = await retry_function( jdownloader.device.downloads.query_packages, diff --git a/bot/helper/mirror_utils/status_utils/jdownloader_status.py b/bot/helper/mirror_utils/status_utils/jdownloader_status.py index 5a28596a098..65eda9d1a98 100644 --- a/bot/helper/mirror_utils/status_utils/jdownloader_status.py +++ b/bot/helper/mirror_utils/status_utils/jdownloader_status.py @@ -1,6 +1,6 @@ from bot import LOGGER, jd_lock, jd_downloads from bot.helper.ext_utils.jdownloader_booter import jdownloader -from bot.helper.ext_utils.bot_utils import sync_to_async +from bot.helper.ext_utils.bot_utils import retry_function from bot.helper.ext_utils.status_utils import ( MirrorStatus, get_readable_file_size, @@ -78,7 +78,7 @@ def gid(self): async def cancel_task(self): LOGGER.info(f"Cancelling Download: {self.name()}") - await sync_to_async( + await retry_function( jdownloader.device.downloads.remove_links, package_ids=[int(self._gid)] ) async with jd_lock: