diff --git a/bot/helper/ext_utils/task_manager.py b/bot/helper/ext_utils/task_manager.py index 7a641dd0e57c..666b8eb211c8 100644 --- a/bot/helper/ext_utils/task_manager.py +++ b/bot/helper/ext_utils/task_manager.py @@ -178,7 +178,6 @@ async def start_from_queued(): list(queued_up.keys()), start=1 ): - f_tasks = all_limit - all_ await start_up_from_queued(mid) f_tasks -= 1 if f_tasks == 0 or ( diff --git a/bot/helper/listeners/aria2_listener.py b/bot/helper/listeners/aria2_listener.py index 4ebb264e82b7..3a855de1ef0d 100644 --- a/bot/helper/listeners/aria2_listener.py +++ b/bot/helper/listeners/aria2_listener.py @@ -68,12 +68,12 @@ async def _on_download_started(api, gid): LOGGER.info(f"onAria2DownloadStarted: {download.name} - Gid: {gid}") await sleep(1) + await sleep(2) if task := await get_task_by_gid(gid): download = await sync_to_async( api.get_download, gid ) - await sleep(2) await sync_to_async(download.update) task.listener.name = download.name task.listener.is_torrent = download.is_torrent @@ -316,7 +316,8 @@ async def _on_download_stopped(api, gid): @loop_thread async def _on_download_error(api, gid): - LOGGER.info(f"on_download_error: {gid}") + await sleep(1) + LOGGER.info(f"onDownloadError: {gid}") error = "None" try: download = await sync_to_async( diff --git a/bot/helper/listeners/jdownloader_listener.py b/bot/helper/listeners/jdownloader_listener.py index 4aee2232a9dd..7646f9a0f919 100644 --- a/bot/helper/listeners/jdownloader_listener.py +++ b/bot/helper/listeners/jdownloader_listener.py @@ -19,7 +19,7 @@ async def remove_download(gid): return await retry_function( jdownloader.device.downloads.remove_links, # type: ignore - package_ids=[gid], + package_ids=jd_downloads[gid]["ids"], ) if task := await get_task_by_gid(gid): await task.listener.on_download_error("Download removed manually!") @@ -72,11 +72,14 @@ async def _jd_listener(): ) except: continue - all_packages = [ - pack["uuid"] + + all_packages = { + pack["uuid"]: pack for pack in packages - ] + } + if not all_packages: + continue for ( d_gid, d_dict @@ -91,9 +94,9 @@ async def _jd_listener(): if len(jd_downloads[d_gid]["ids"]) == 0: path = jd_downloads[d_gid]["path"] jd_downloads[d_gid]["ids"] = [ - dl["uuid"] - for dl in all_packages - if dl["saveTo"].startswith(path) + uid + for uid, pk in all_packages.items() + if pk["saveTo"].startswith(path) ] if len(jd_downloads[d_gid]["ids"]) == 0: await remove_download(d_gid) diff --git a/bot/helper/task_utils/download_utils/jd_download.py b/bot/helper/task_utils/download_utils/jd_download.py index b00ea18df56b..d9284f06c187 100644 --- a/bot/helper/task_utils/download_utils/jd_download.py +++ b/bot/helper/task_utils/download_utils/jd_download.py @@ -164,11 +164,6 @@ def trim_path(path): async def add_jd_download(listener, path): try: async with jd_lock: - gid = token_urlsafe(12) - jd_downloads[gid] = { - "status": "collect", - "path": path - } if jdownloader.device is None: raise MYJDException(jdownloader.error) @@ -201,6 +196,13 @@ async def add_jd_download(listener, path): jdownloader.device.linkgrabber.remove_links, package_ids=odl_list ) + + gid = token_urlsafe(12) + jd_downloads[gid] = { + "status": "collect", + "path": path + } + if await aiopath.exists(listener.link): async with aiopen( listener.link, diff --git a/bot/helper/task_utils/download_utils/yt_dlp_download.py b/bot/helper/task_utils/download_utils/yt_dlp_download.py index af0a3a1c45d6..d6ab71ca4750 100644 --- a/bot/helper/task_utils/download_utils/yt_dlp_download.py +++ b/bot/helper/task_utils/download_utils/yt_dlp_download.py @@ -257,7 +257,7 @@ def _download(self, path): self._on_download_error("No video available to download from this playlist. Check logs for more details") return if self._listener.is_cancelled: - raise ValueError + return async_to_sync(self._listener.on_download_complete) except ValueError: self._on_download_error("Download Stopped by User!")