From a8bad66829024ee17ac088c74a8e592ed1a54e7d Mon Sep 17 00:00:00 2001 From: anasty17 Date: Tue, 8 Oct 2024 03:05:53 +0300 Subject: [PATCH] Minor fix for jdwonloader sync while download and when adding cred from botsettings Signed-off-by: anasty17 --- bot/modules/bot_settings.py | 40 +++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/bot/modules/bot_settings.py b/bot/modules/bot_settings.py index c5d2a2eed5d..b0877fe716b 100644 --- a/bot/modules/bot_settings.py +++ b/bot/modules/bot_settings.py @@ -39,6 +39,7 @@ nzb_options, get_nzb_options, get_qb_options, + jd_lock, ) from ..helper.ext_utils.bot_utils import ( SetInterval, @@ -333,7 +334,7 @@ async def edit_variable(_, message, pre_message, key): ]: await rclone_serve_booter() elif key in ["JD_EMAIL", "JD_PASS"]: - jdownloader.initiate() + await jdownloader.initiate() elif key == "RSS_DELAY": add_job() elif key == "USET_SERVERS": @@ -442,11 +443,21 @@ async def edit_nzb_server(_, message, pre_message, key, index=0): async def sync_jdownloader(): - if not config_dict["DATABASE_URL"] or jdownloader.device is None: - return - try: - await wait_for(retry_function(jdownloader.update_devices), timeout=10) - except: + async with jd_lock: + if not config_dict["DATABASE_URL"] or jdownloader.device is None: + return + try: + await wait_for(retry_function(jdownloader.update_devices), timeout=10) + except: + is_connected = await jdownloader.jdconnect() + if not is_connected: + LOGGER.error(jdownloader.error) + return + isDeviceConnected = await jdownloader.connectToDevice() + if not isDeviceConnected: + LOGGER.error(jdownloader.error) + return + await jdownloader.device.system.exit_jd() is_connected = await jdownloader.jdconnect() if not is_connected: LOGGER.error(jdownloader.error) @@ -454,17 +465,8 @@ async def sync_jdownloader(): isDeviceConnected = await jdownloader.connectToDevice() if not isDeviceConnected: LOGGER.error(jdownloader.error) - return - await jdownloader.device.system.exit_jd() if await aiopath.exists("cfg.zip"): await remove("cfg.zip") - is_connected = await jdownloader.jdconnect() - if not is_connected: - LOGGER.error(jdownloader.error) - return - isDeviceConnected = await jdownloader.connectToDevice() - if not isDeviceConnected: - LOGGER.error(jdownloader.error) await ( await create_subprocess_exec("7z", "a", "cfg.zip", "/JDownloader/cfg") ).wait() @@ -595,14 +597,8 @@ async def edit_bot_settings(client, query): show_alert=True, ) return - if jd_downloads: - await query.answer( - "You can't sync settings while using jdownloader!", - show_alert=True, - ) - return await query.answer( - "Syncronization Started. JDownloader will get restarted. It takes up to 5 sec!", + "Syncronization Started. JDownloader will get restarted. It takes up to 10 sec!", show_alert=True, ) await sync_jdownloader()