From 44fd225ab1281cdcfe352a5d31e54913131947e4 Mon Sep 17 00:00:00 2001 From: arabcoders Date: Sat, 1 Nov 2025 17:22:16 +0300 Subject: [PATCH] Add yt-dlp wrapper to keep it in sync with user installed yt-dlp. Ref #469 --- Dockerfile | 12 ++++----- app/library/PackageInstaller.py | 9 ++++--- yt-dlp | 44 +++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 10 deletions(-) create mode 100755 yt-dlp diff --git a/Dockerfile b/Dockerfile index 51028cce..c65478a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,12 +57,10 @@ RUN mkdir /config /downloads && ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ dpkg-reconfigure --frontend=noninteractive locales && \ update-locale LANG=en_US.UTF-8 \ - && rm -rf /var/lib/apt/lists/* + mkdir -p /opt/bin && rm -rf /var/lib/apt/lists/* COPY entrypoint.sh / - -RUN sed -i 's/\r$//g' /entrypoint.sh && chmod +x /entrypoint.sh - +COPY --chown=app:app yt-dlp /opt/bin/yt-dlp COPY --chown=app:app ./app /app/app COPY --chown=app:app --from=node_builder /app/exported /app/ui/exported COPY --chown=app:app --from=python_builder /opt/python /opt/python @@ -72,13 +70,13 @@ COPY --from=ghcr.io/arabcoders/jellyfin-ffmpeg /usr/bin/ffprobe /usr/bin/ffprobe COPY --from=denoland/deno:latest /usr/bin/deno /usr/bin/deno COPY --chown=app:app ./healthcheck.sh /usr/local/bin/healthcheck -ENV PATH="/opt/python/bin:$PATH" +ENV PATH="/opt/bin:/opt/python/bin:$PATH" ENV LANG=en_US.UTF-8 ENV LANGUAGE=en_US:en ENV LC_ALL=en_US.UTF-8 -RUN chown -R app:app /config /downloads && \ - chmod +x /usr/local/bin/healthcheck /usr/bin/mp4box /usr/bin/ffmpeg /usr/bin/ffprobe /usr/bin/deno +RUN sed -i 's/\r$//g' /entrypoint.sh && chmod +x /entrypoint.sh && chown -R app:app /config /downloads && \ + chmod +x /usr/local/bin/healthcheck /usr/bin/mp4box /usr/bin/ffmpeg /usr/bin/ffprobe /usr/bin/deno /opt/bin/yt-dlp VOLUME /config VOLUME /downloads diff --git a/app/library/PackageInstaller.py b/app/library/PackageInstaller.py index 18c35fe5..7ad3782e 100644 --- a/app/library/PackageInstaller.py +++ b/app/library/PackageInstaller.py @@ -110,10 +110,13 @@ class PackageInstaller: str(self.user_site), ] + if "yt_dlp" == pkg: + pkg = "yt-dlp" + if version: - if "nightly" == version and pkg == "yt_dlp": + if "nightly" == version and pkg == "yt-dlp": cmd.extend(["--pre", "yt-dlp[default]"]) - elif "master" == version and pkg == "yt_dlp": + elif "master" == version and pkg == "yt-dlp": cmd.append("git+https://github.com/yt-dlp/yt-dlp.git@master") else: cmd.append(version if str(version).startswith("git+") else f"{pkg}=={version}") @@ -179,7 +182,7 @@ class PackageInstaller: return False - def out(self, out: bytes | str | None = None, err=bytes | str | None) -> None: + def out(self, out: bytes | str | None = None, err: bytes | str | None = None) -> None: if out: for line in (line.strip() for line in out.strip().splitlines() if line.strip()): LOG.info(line.decode() if isinstance(line, bytes) else line) diff --git a/yt-dlp b/yt-dlp new file mode 100755 index 00000000..fb841520 --- /dev/null +++ b/yt-dlp @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +########### +# Set PATH to include user installed packages +PY_BASE_VERSION=$(/opt/python/bin/python -V 2>&1 | awk '{print $2}' | cut -d. -f1,2) + +CONFIG_PATH="${YTP_CONFIG_PATH:-/app/var/config}" +USER_SITE="${CONFIG_PATH}/python${PY_BASE_VERSION}-packages" +USER_SITE_BIN="${USER_SITE}/bin" + +if [ -d "${USER_SITE_BIN}" ]; then + case ":${PATH}:" in + *:"${USER_SITE_BIN}":*) + ;; + *) + if [ -n "${PATH}" ]; then + PATH="${USER_SITE_BIN}:${PATH}" + else + PATH="${USER_SITE_BIN}" + fi + ;; + esac + + export PATH +fi + +if [ -d "${USER_SITE}" ]; then + case ":${PYTHONPATH}:" in + *:"${USER_SITE}":*) + ;; + *) + if [ -n "${PYTHONPATH}" ]; then + PYTHONPATH="${USER_SITE}:${PYTHONPATH}" + else + PYTHONPATH="${USER_SITE}" + fi + ;; + esac + + export PYTHONPATH +fi + +# Execute yt-dlp with passed arguments +exec /opt/python/bin/python -m yt_dlp "${@}"