Merge pull request #174 from arabcoders/dev

Dev
This commit is contained in:
Abdulmohsen 2025-01-18 17:56:15 +03:00 committed by GitHub
commit 501e97aabd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 33 additions and 29 deletions

View file

@ -317,8 +317,11 @@ class Download:
except asyncio.CancelledError:
LOG.debug(f"Closing progress update for: {self.info._id=}.")
return
status = await self.update_task
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=}.")
@ -340,7 +343,11 @@ class Download:
self.info.filename = os.path.relpath(status.get("filename"), self.download_dir)
if os.path.exists(status.get("filename")):
self.info.file_size = os.path.getsize(status.get("filename"))
try:
self.info.file_size = os.path.getsize(status.get("filename"))
except FileNotFoundError:
self.info.file_size = 0
pass
self.info.status = status.get("status", self.info.status)
self.info.msg = status.get("msg")
@ -360,22 +367,16 @@ class Download:
self.info.speed = status.get("speed")
self.info.eta = status.get("eta")
if self.info.status == "finished" and "filename" in status:
if self.info.status == "finished" and "filename" in status and os.path.exists(status.get("filename")):
try:
self.info.file_size = os.path.getsize(status.get("filename"))
except FileNotFoundError:
LOG.warning(f'File not found: {status.get("filename")}')
self.info.file_size = None
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.extras["is_video"] = ff.has_video()
self.info.extras["is_audio"] = ff.has_audio()
self.info.datetime = str(formatdate(time.time()))
except Exception as e:
self.info.extras['is_video'] = True
self.info.extras['is_audio'] = True
except (FileNotFoundError, 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}")
asyncio.create_task(self.emitter.updated(dl=self.info), name=f"emitter-u-{self.id}")

View file

@ -230,6 +230,7 @@ class DownloadQueue:
already=None,
):
ytdlp_config = ytdlp_config if ytdlp_config else {}
folder = str(folder)
LOG.info(
f"Adding url '{url}' to folder '{folder}' with the following options 'Preset: {preset}' 'Naming: {output_template}', 'Cookies: {ytdlp_cookies}' 'YTConfig: {ytdlp_config}'."

View file

@ -22,6 +22,8 @@ IGNORED_KEYS: tuple[str] = (
"outtmpl",
"progress_hooks",
"postprocessor_hooks",
"format",
"download_archive",
)
YTDLP_INFO_CLS: yt_dlp.YoutubeDL = None
OS_ALT_SEP: list[str] = list(sep for sep in [os.sep, os.path.altsep] if sep is not None and sep != "/")
@ -77,6 +79,7 @@ def get_opts(preset: str, ytdl_opts: dict) -> dict:
LOG.debug(f"Using preset '{preset}', altered options: {opts}")
return opts
def getVideoInfo(url: str, ytdlp_opts: dict = None, no_archive: bool = True) -> Any | dict[str, Any] | None:
"""
Extracts video information from the given URL.
@ -187,17 +190,9 @@ def mergeConfig(config: dict, new_config: dict) -> dict:
Returns:
dict: Merged config
"""
ignored_keys: tuple = (
"cookiefile",
"download_archive" "paths",
"outtmpl",
"progress_hooks",
"postprocessor_hooks",
)
for key in ignored_keys:
for key in IGNORED_KEYS:
if key in new_config:
LOG.error(f"Key '{key}' is not allowed to be manually set.")
del new_config[key]
conf = mergeDict(new_config, config)

View file

@ -10,7 +10,7 @@ import coloredlogs
from dotenv import load_dotenv
from yt_dlp.version import __version__ as YTDLP_VERSION
from .Utils import load_file
from .Utils import load_file, mergeDict, IGNORED_KEYS
from .version import APP_VERSION
@ -218,15 +218,22 @@ class Config:
LOG.error(f"Error starting debugpy server at '0.0.0.0:{self.debugpy_port}'. {e}")
optsFile: str = os.path.join(self.config_path, "ytdlp.json")
if os.path.exists(optsFile) and os.path.getsize(optsFile) > 4:
if os.path.exists(optsFile) and os.path.getsize(optsFile) > 5:
LOG.info(f"Loading yt-dlp custom options from '{optsFile}'.")
(opts, status, error) = load_file(optsFile, dict)
if not status:
LOG.error(f"Could not load yt-dlp custom options from '{optsFile}'. {error}")
sys.exit(1)
if isinstance(opts, dict):
for key in IGNORED_KEYS:
if key in opts:
LOG.error(f"Key '{key}' is not allowed to be loaded via 'ytdlp.json' file.")
del opts[key]
self.ytdl_options.update(opts)
self.ytdl_options = mergeDict(self.ytdl_options, opts)
else:
LOG.error(f"Invalid yt-dlp custom options file '{optsFile}'.")
else:
LOG.info(f"No yt-dlp custom options found at '{optsFile}'.")

View file

@ -150,7 +150,7 @@ class Main:
LOG.info("=" * 40)
if self.config.access_log:
http_logger.addFilter(lambda record: "GET /ping" not in record.getMessage())
http_logger.addFilter(lambda record: "GET /api/ping" not in record.getMessage())
web.run_app(
self.app,