Skip to content

Commit

Permalink
Minor fix for jdwonloader sync while download and when adding cred fr…
Browse files Browse the repository at this point in the history
…om botsettings

Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
anasty17 committed Oct 8, 2024
1 parent cb16cb3 commit a8bad66
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions bot/modules/bot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
nzb_options,
get_nzb_options,
get_qb_options,
jd_lock,
)
from ..helper.ext_utils.bot_utils import (
SetInterval,
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -442,29 +443,30 @@ 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)
return
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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a8bad66

Please sign in to comment.