feat: add download_info_expires config to manage download info validity

This commit is contained in:
arabcoders 2025-08-22 18:10:22 +03:00
parent f21fee96a3
commit abf9c7a9d8
2 changed files with 14 additions and 1 deletions

View file

@ -107,6 +107,7 @@ class Download:
self.temp_dir = info.temp_dir
self.template = info.template
self.template_chapter = info.template_chapter
self.download_info_expires = int(config.download_info_expires)
self.preset = info.preset
self.info = info
self.id = info._id
@ -226,7 +227,15 @@ class Download:
self.logger.error(err_msg)
raise ValueError(err_msg) from e
if not self.info_dict:
# Safe-guard incase downloading take too long and the info expires.
if self.info_dict and isinstance(self.info_dict, dict) and self.download_info_expires > 0:
_ts: int | None = self.info_dict.get("timestamp")
_ts = datetime.fromtimestamp(_ts, tz=UTC) if _ts else None
if not _ts or (datetime.now(tz=UTC) - _ts).total_seconds() > self.download_info_expires:
self.info_dict = None
self.logger.warning(f"Info for '{self.info.url}' has expired, re-extracting info.")
if not self.info_dict or not isinstance(self.info_dict, dict):
self.logger.info(f"Extracting info for '{self.info.url}'.")
self.logs = []
ie_params = params.copy()

View file

@ -28,6 +28,9 @@ class Config:
download_path_depth: int = 2
"""How many subdirectories to show in auto complete."""
download_info_expires: int = 10800
"""How long (in seconds) the download info is valid before it needs to be re-extracted."""
temp_path: str = "/tmp"
"""The path to the temporary directory."""
@ -226,6 +229,7 @@ class Config:
"debugpy_port",
"playlist_items_concurrency",
"download_path_depth",
"download_info_expires",
)
"The variables that are integers."