Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
Fix packages ids after jd restart

Signed-off-by: anasty17 <[email protected]>

minor fixes

Signed-off-by: anasty17 <[email protected]>

Minor fix for queue

Signed-off-by: anasty17 <[email protected]>
Co-Authored-By: Anas Tayyar <[email protected]>
Co-Authored-By: z-mirror <[email protected]>
  • Loading branch information
2 people authored and Dawn-India committed Oct 20, 2024
1 parent 38c7eef commit 5c69284
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
1 change: 0 additions & 1 deletion bot/helper/ext_utils/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
5 changes: 3 additions & 2 deletions bot/helper/listeners/aria2_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
17 changes: 10 additions & 7 deletions bot/helper/listeners/jdownloader_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions bot/helper/task_utils/download_utils/jd_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/task_utils/download_utils/yt_dlp_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down

0 comments on commit 5c69284

Please sign in to comment.