From fa73e817a63a5cc4fc1cfc67efbffdc68a612cc6 Mon Sep 17 00:00:00 2001 From: arabcoders Date: Thu, 27 Mar 2025 01:13:52 +0300 Subject: [PATCH] Make it possible to override the pictures backends urls. --- README.md | 1 + app/library/HttpAPI.py | 10 ++-------- app/library/config.py | 12 ++++++++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 65548a13..62cf6792 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ Certain configuration values can be set via environment variables, using the `-e | YTP_PIP_PACKAGES | A space separated list of pip packages to install | `empty string` | | YTP_PIP_IGNORE_UPDATES | Do not update the custom pip packages | `false` | | YTP_BASIC_MODE | Whether to run WebUI in basic mode | `false` | +| YTP_PICTURES_BACKENDS | A comma separated list of pictures urls to use. | `empty string` | # Browser extensions & bookmarklets diff --git a/app/library/HttpAPI.py b/app/library/HttpAPI.py index 9884fb07..eeaeac71 100644 --- a/app/library/HttpAPI.py +++ b/app/library/HttpAPI.py @@ -1401,16 +1401,10 @@ class HttpAPI(Common): Response: The response object. """ - backends: list[str] = [ - "https://unsplash.it/1920/1080?random", - "https://picsum.photos/1920/1080", - "https://spaceholder.cc/i/1920x1080", - "https://imageipsum.com/1920x1080", - "https://placedog.net/1920/1080", - ] - backend = random.choice(backends) # noqa: S311 + backend = None try: + backend = random.choice(self.config.pictures_backends) # noqa: S311 CACHE_KEY = "random_background" if self.cache.has(CACHE_KEY) and not request.query.get("force", False): diff --git a/app/library/config.py b/app/library/config.py index b1a9c2b0..3a8ebf2d 100644 --- a/app/library/config.py +++ b/app/library/config.py @@ -146,6 +146,15 @@ class Config: console_enabled: bool = False "Enable direct access to yt-dlp console." + pictures_backends: list[str] = [ + "https://unsplash.it/1920/1080?random", + "https://picsum.photos/1920/1080", + "https://spaceholder.cc/i/1920x1080", + "https://imageipsum.com/1920x1080", + "https://placedog.net/1920/1080", + ] + "The list of picture backends to use for the background." + _manual_vars: tuple = ( "temp_path", "config_path", @@ -282,6 +291,9 @@ class Config: if k in self._int_vars: setattr(self, k, int(v)) + if isinstance(self.pictures_backends, str) and self.pictures_backends: + self.pictures_backends = self.pictures_backends.split(",") + numeric_level = getattr(logging, self.log_level.upper(), None) if not isinstance(numeric_level, int): msg = f"Invalid log level '{self.log_level}' specified."