minor fixes

Signed-off-by: anasty17 <e.anastayyar@gmail.com>
This commit is contained in:
anasty17 2024-10-16 05:55:32 +03:00
parent 375838a973
commit cb601eb8df
No known key found for this signature in database
GPG Key ID: EAAC8A2DF2861DE4
3 changed files with 8 additions and 6 deletions

View File

@ -1,6 +1,6 @@
from asyncio import sleep, wait_for from asyncio import sleep
from bot import intervals, jd_lock, jd_downloads, LOGGER from bot import intervals, jd_lock, jd_downloads
from ..ext_utils.bot_utils import new_task, retry_function from ..ext_utils.bot_utils import new_task, retry_function
from ..ext_utils.jdownloader_booter import jdownloader from ..ext_utils.jdownloader_booter import jdownloader
from ..ext_utils.status_utils import get_task_by_gid from ..ext_utils.status_utils import get_task_by_gid
@ -12,7 +12,7 @@ async def remove_download(gid):
return return
await retry_function( await retry_function(
jdownloader.device.downloads.remove_links, jdownloader.device.downloads.remove_links,
package_ids=[gid], package_ids=jd_downloads[gid]["ids"],
) )
if task := await get_task_by_gid(gid): if task := await get_task_by_gid(gid):
await task.listener.on_download_error("Download removed manually!") await task.listener.on_download_error("Download removed manually!")

View File

@ -112,8 +112,6 @@ def trim_path(path):
async def add_jd_download(listener, path): async def add_jd_download(listener, path):
try: try:
async with jd_lock: async with jd_lock:
gid = token_urlsafe(12)
jd_downloads[gid] = {"status": "collect", "path": path}
if jdownloader.device is None: if jdownloader.device is None:
raise MYJDException(jdownloader.error) raise MYJDException(jdownloader.error)
@ -141,6 +139,10 @@ async def add_jd_download(listener, path):
jdownloader.device.linkgrabber.remove_links, jdownloader.device.linkgrabber.remove_links,
package_ids=odl_list, package_ids=odl_list,
) )
gid = token_urlsafe(12)
jd_downloads[gid] = {"status": "collect", "path": path}
if await aiopath.exists(listener.link): if await aiopath.exists(listener.link):
async with aiopen(listener.link, "rb") as dlc: async with aiopen(listener.link, "rb") as dlc:
content = await dlc.read() content = await dlc.read()

View File

@ -182,7 +182,7 @@ class YoutubeDLHelper:
) )
return return
if self._listener.is_cancelled: if self._listener.is_cancelled:
raise ValueError return
async_to_sync(self._listener.on_download_complete) async_to_sync(self._listener.on_download_complete)
except ValueError: except ValueError:
self._on_download_error("Download Stopped by User!") self._on_download_error("Download Stopped by User!")