commit
9ab357983b
5 changed files with 37 additions and 17 deletions
|
|
@ -28,7 +28,6 @@ class Download:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
id: str = None
|
id: str = None
|
||||||
manager = None
|
|
||||||
download_dir: str = None
|
download_dir: str = None
|
||||||
temp_dir: str = None
|
temp_dir: str = None
|
||||||
output_template: str = None
|
output_template: str = None
|
||||||
|
|
@ -95,6 +94,10 @@ class Download:
|
||||||
|
|
||||||
def _progress_hook(self, data: dict):
|
def _progress_hook(self, data: dict):
|
||||||
dataDict = {k: v for k, v in data.items() if k in self._ytdlp_fields}
|
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})
|
self.status_queue.put({"id": self.id, **dataDict})
|
||||||
|
|
||||||
def _postprocessor_hook(self, data: dict):
|
def _postprocessor_hook(self, data: dict):
|
||||||
|
|
@ -243,6 +246,9 @@ class Download:
|
||||||
if self.proc.is_alive():
|
if self.proc.is_alive():
|
||||||
tasks.append(loop.run_in_executor(None, self.proc.join))
|
tasks.append(loop.run_in_executor(None, self.proc.join))
|
||||||
|
|
||||||
|
if self.status_queue:
|
||||||
|
self.status_queue.put(Terminator())
|
||||||
|
|
||||||
if self.manager:
|
if self.manager:
|
||||||
tasks.append(loop.run_in_executor(None, self.manager.shutdown))
|
tasks.append(loop.run_in_executor(None, self.manager.shutdown))
|
||||||
|
|
||||||
|
|
@ -314,14 +320,10 @@ class Download:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
self.update_task = asyncio.get_running_loop().run_in_executor(None, self.status_queue.get)
|
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=}.")
|
LOG.debug(f"Closing progress update for: {self.info._id=}.")
|
||||||
return
|
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:
|
if status is None or status.__class__ is Terminator:
|
||||||
LOG.debug(f"Closing progress update for: {self.info._id=}.")
|
LOG.debug(f"Closing progress update for: {self.info._id=}.")
|
||||||
|
|
@ -367,16 +369,26 @@ class Download:
|
||||||
self.info.speed = status.get("speed")
|
self.info.speed = status.get("speed")
|
||||||
self.info.eta = status.get("eta")
|
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:
|
try:
|
||||||
self.info.file_size = os.path.getsize(status.get("filename"))
|
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"))
|
ff = await ffprobe(status.get("filename"))
|
||||||
self.info.extras["is_video"] = ff.has_video()
|
self.info.extras["is_video"] = ff.has_video()
|
||||||
self.info.extras["is_audio"] = ff.has_audio()
|
self.info.extras["is_audio"] = ff.has_audio()
|
||||||
self.info.datetime = str(formatdate(time.time()))
|
except Exception as e:
|
||||||
except (FileNotFoundError, Exception) as e:
|
|
||||||
self.info.extras["is_video"] = True
|
self.info.extras["is_video"] = True
|
||||||
self.info.extras["is_audio"] = 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}")
|
asyncio.create_task(self.emitter.updated(dl=self.info), name=f"emitter-u-{self.id}")
|
||||||
|
|
|
||||||
|
|
@ -429,7 +429,7 @@ class DownloadQueue:
|
||||||
self.event.clear()
|
self.event.clear()
|
||||||
LOG.debug("Cleared wait event.")
|
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.")
|
LOG.info("Download pool is paused.")
|
||||||
await self.paused.wait()
|
await self.paused.wait()
|
||||||
LOG.info("Download pool resumed downloading.")
|
LOG.info("Download pool resumed downloading.")
|
||||||
|
|
@ -449,7 +449,7 @@ class DownloadQueue:
|
||||||
|
|
||||||
async def __downloadFile(self, id: str, entry: Download):
|
async def __downloadFile(self, id: str, entry: Download):
|
||||||
LOG.info(
|
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:
|
try:
|
||||||
|
|
@ -468,6 +468,7 @@ class DownloadQueue:
|
||||||
await entry.close()
|
await entry.close()
|
||||||
|
|
||||||
if self.queue.exists(key=id):
|
if self.queue.exists(key=id):
|
||||||
|
LOG.debug(f"Download '{id}' is done. Removing from queue.")
|
||||||
self.queue.delete(key=id)
|
self.queue.delete(key=id)
|
||||||
|
|
||||||
if entry.is_canceled() is True:
|
if entry.is_canceled() is True:
|
||||||
|
|
@ -477,6 +478,8 @@ class DownloadQueue:
|
||||||
|
|
||||||
self.done.put(value=entry)
|
self.done.put(value=entry)
|
||||||
asyncio.create_task(self.emitter.completed(dl=entry.info.serialize()), name=f"notifier-d-{id}")
|
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:
|
if self.event:
|
||||||
self.event.set()
|
self.event.set()
|
||||||
|
|
|
||||||
|
|
@ -161,9 +161,9 @@ class HttpSocket(common):
|
||||||
await self.emitter.warning("No URL provided.", to=sid)
|
await self.emitter.warning("No URL provided.", to=sid)
|
||||||
return
|
return
|
||||||
|
|
||||||
preset: str = data.get("preset", "default")
|
preset: str = str(data.get("preset", "default"))
|
||||||
folder: str = data.get("folder")
|
folder: str = str(data.get("folder"))
|
||||||
ytdlp_cookies: str = data.get("ytdlp_cookies")
|
ytdlp_cookies: str = str(data.get("ytdlp_cookies"))
|
||||||
ytdlp_config: dict | None = data.get("ytdlp_config")
|
ytdlp_config: dict | None = data.get("ytdlp_config")
|
||||||
output_template: str = data.get("output_template")
|
output_template: str = data.get("output_template")
|
||||||
if ytdlp_config is None:
|
if ytdlp_config is None:
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ from yt_dlp.networking.impersonate import ImpersonateTarget
|
||||||
LOG = logging.getLogger("Utils")
|
LOG = logging.getLogger("Utils")
|
||||||
|
|
||||||
IGNORED_KEYS: tuple[str] = (
|
IGNORED_KEYS: tuple[str] = (
|
||||||
"cookiefile",
|
|
||||||
"paths",
|
"paths",
|
||||||
"outtmpl",
|
"outtmpl",
|
||||||
"progress_hooks",
|
"progress_hooks",
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,12 @@ export const useSocketStore = defineStore('socket', () => {
|
||||||
|
|
||||||
socket.value.on("updated", stream => {
|
socket.value.on("updated", stream => {
|
||||||
const data = JSON.parse(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, {});
|
let dl = stateStore.get('queue', data._id, {});
|
||||||
data.deleting = dl?.deleting;
|
data.deleting = dl?.deleting;
|
||||||
stateStore.update('queue', data._id, data);
|
stateStore.update('queue', data._id, data);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue