Merge pull request #175 from arabcoders/dev

Finalize Fix for #173
This commit is contained in:
Abdulmohsen 2025-01-18 21:14:06 +03:00 committed by GitHub
commit 9ab357983b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 17 deletions

View file

@ -28,7 +28,6 @@ class Download:
"""
id: str = None
manager = None
download_dir: str = None
temp_dir: str = None
output_template: str = None
@ -95,6 +94,10 @@ class Download:
def _progress_hook(self, data: dict):
dataDict = {k: v for k, v in data.items() if k in self._ytdlp_fields}
if "finished" == data.get("status", None) and data.get("info_dict", {}).get("filename", False):
dataDict["filename"] = data["info_dict"]["filename"]
self.status_queue.put({"id": self.id, **dataDict})
def _postprocessor_hook(self, data: dict):
@ -243,6 +246,9 @@ class Download:
if self.proc.is_alive():
tasks.append(loop.run_in_executor(None, self.proc.join))
if self.status_queue:
self.status_queue.put(Terminator())
if self.manager:
tasks.append(loop.run_in_executor(None, self.manager.shutdown))
@ -314,14 +320,10 @@ class Download:
while True:
try:
self.update_task = asyncio.get_running_loop().run_in_executor(None, self.status_queue.get)
except asyncio.CancelledError:
status = await self.update_task
except (asyncio.CancelledError, OSError, FileNotFoundError):
LOG.debug(f"Closing progress update for: {self.info._id=}.")
return
try:
status = await self.update_task
except Exception as e:
LOG.error(f"Failed to get status update for: {self.info._id=}. {e}")
pass
if status is None or status.__class__ is Terminator:
LOG.debug(f"Closing progress update for: {self.info._id=}.")
@ -367,16 +369,26 @@ class Download:
self.info.speed = status.get("speed")
self.info.eta = status.get("eta")
if self.info.status == "finished" and "filename" in status and os.path.exists(status.get("filename")):
if (
"finished" == self.info.status
and "filename" in status
and os.path.isfile(status.get("filename"))
and os.path.exists(status.get("filename"))
):
try:
self.info.file_size = os.path.getsize(status.get("filename"))
self.info.datetime = str(formatdate(time.time()))
except FileNotFoundError:
pass
try:
ff = await ffprobe(status.get("filename"))
self.info.extras["is_video"] = ff.has_video()
self.info.extras["is_audio"] = ff.has_audio()
self.info.datetime = str(formatdate(time.time()))
except (FileNotFoundError, Exception) as e:
except Exception as e:
self.info.extras["is_video"] = True
self.info.extras["is_audio"] = True
LOG.exception(f"Failed to ffprobe: {status.get('filename')}. {e}")
LOG.exception(f"Failed to ffprobe: {status.get}. {e}")
LOG.exception(e)
asyncio.create_task(self.emitter.updated(dl=self.info), name=f"emitter-u-{self.id}")

View file

@ -429,7 +429,7 @@ class DownloadQueue:
self.event.clear()
LOG.debug("Cleared wait event.")
if self.paused and isinstance(self.paused, asyncio.Event):
if self.paused and isinstance(self.paused, asyncio.Event) and self.isPaused():
LOG.info("Download pool is paused.")
await self.paused.wait()
LOG.info("Download pool resumed downloading.")
@ -449,7 +449,7 @@ class DownloadQueue:
async def __downloadFile(self, id: str, entry: Download):
LOG.info(
f"Downloading 'id: {id}', 'Title: {entry.info.title}', 'URL: {entry.info.url}' to 'folder: {entry.info.folder}'."
f"Downloading 'id: {id}', 'Title: {entry.info.title}', 'URL: {entry.info.url}' to 'Folder: {entry.info.folder}'."
)
try:
@ -468,6 +468,7 @@ class DownloadQueue:
await entry.close()
if self.queue.exists(key=id):
LOG.debug(f"Download '{id}' is done. Removing from queue.")
self.queue.delete(key=id)
if entry.is_canceled() is True:
@ -477,6 +478,8 @@ class DownloadQueue:
self.done.put(value=entry)
asyncio.create_task(self.emitter.completed(dl=entry.info.serialize()), name=f"notifier-d-{id}")
else:
LOG.warning(f"Download '{id}' not found in queue.")
if self.event:
self.event.set()

View file

@ -161,9 +161,9 @@ class HttpSocket(common):
await self.emitter.warning("No URL provided.", to=sid)
return
preset: str = data.get("preset", "default")
folder: str = data.get("folder")
ytdlp_cookies: str = data.get("ytdlp_cookies")
preset: str = str(data.get("preset", "default"))
folder: str = str(data.get("folder"))
ytdlp_cookies: str = str(data.get("ytdlp_cookies"))
ytdlp_config: dict | None = data.get("ytdlp_config")
output_template: str = data.get("output_template")
if ytdlp_config is None:

View file

@ -17,7 +17,6 @@ from yt_dlp.networking.impersonate import ImpersonateTarget
LOG = logging.getLogger("Utils")
IGNORED_KEYS: tuple[str] = (
"cookiefile",
"paths",
"outtmpl",
"progress_hooks",

View file

@ -78,6 +78,12 @@ export const useSocketStore = defineStore('socket', () => {
socket.value.on("updated", stream => {
const data = JSON.parse(stream);
if (true === stateStore.has('history', item._id)) {
stateStore.update('history', item._id, item);
return;
}
let dl = stateStore.get('queue', data._id, {});
data.deleting = dl?.deleting;
stateStore.update('queue', data._id, data);