diff --git a/app/features/ytdlp/extractor.py b/app/features/ytdlp/extractor.py index 26a32fe8..dea1d6d2 100644 --- a/app/features/ytdlp/extractor.py +++ b/app/features/ytdlp/extractor.py @@ -266,7 +266,12 @@ def extract_info_sync( params["verbose"] = True params.pop("quiet", None) - log_wrapper = LogWrapper() + suppress: tuple[str, ...] = () + patterns = kwargs.get("suppress_logs") + if isinstance(patterns, list | tuple): + suppress = tuple(value for value in patterns if isinstance(value, str) and value) + + log_wrapper = LogWrapper(suppress=suppress) id_dict: dict[str, str | None] = get_archive_id(url=url) archive_id: str | None = f".{id_dict['id']}" if id_dict.get("id") else None logger_name: str = f"yt-dlp{archive_id or '.extract_info'}" diff --git a/app/features/ytdlp/utils.py b/app/features/ytdlp/utils.py index 93034d89..a1ded5db 100644 --- a/app/features/ytdlp/utils.py +++ b/app/features/ytdlp/utils.py @@ -86,8 +86,9 @@ class LogTarget: class LogWrapper: - def __init__(self): + def __init__(self, suppress: list[str] | tuple[str, ...] | None = None): self.targets: list[LogTarget] = [] + self.suppress: tuple[str, ...] = tuple(value for value in (suppress or ()) if isinstance(value, str) and value) def add_target(self, target: logging.Logger | Callable, level: int = logging.DEBUG, name: str | None = None): """ @@ -118,7 +119,13 @@ class LogWrapper: def has_targets(self): return len(self.targets) > 0 + def _skip(self, msg: Any) -> bool: + return isinstance(msg, str) and any(value in msg for value in self.suppress) + def _log(self, level, msg, *args, **kwargs): + if self._skip(msg): + return + for target in self.targets: if level < target.level: continue diff --git a/app/library/downloads/item_adder.py b/app/library/downloads/item_adder.py index 2e37178c..7467cf87 100644 --- a/app/library/downloads/item_adder.py +++ b/app/library/downloads/item_adder.py @@ -51,6 +51,14 @@ def _get_ignored_conditions(extras: dict | None) -> list[str]: return ignored +def _task_ignored_logs(item: "Item") -> list[str] | None: + extras = item.extras if isinstance(item.extras, dict) else {} + if not extras.get("source_handler"): + return None + + return ["has already been recorded in the archive"] + + async def add_item( queue: "DownloadQueue", entry: dict, @@ -209,6 +217,7 @@ async def add( follow_redirect=True, capture_logs=logging.WARNING, budget_sleep=True, + suppress_logs=_task_ignored_logs(item), ) if not entry: