From c32d57967592068362f00016b054aa8844cafca7 Mon Sep 17 00:00:00 2001 From: "juancarlos.cavero" Date: Thu, 16 Jul 2026 18:28:40 +0200 Subject: [PATCH] chore: scrub infra hints from repo - Remove vendor name (proxy provider) and strategy-revealing comments across Dockerfile, docker-compose.cloud.yml, main.py, cloud/metering.py, cloud/alerts.py - Stop tracking .env.cloud.example (kept local only; added to .gitignore) Functional references (yt-dlp helper plugin, env var names) necessarily remain. --- .env.cloud.example | 64 ---------------------------------------- .gitignore | 3 ++ Dockerfile | 8 ++--- cloud/alerts.py | 13 ++++---- cloud/metering.py | 7 ++--- docker-compose.cloud.yml | 5 +--- main.py | 16 ++++------ 7 files changed, 21 insertions(+), 95 deletions(-) delete mode 100644 .env.cloud.example diff --git a/.env.cloud.example b/.env.cloud.example deleted file mode 100644 index 71fc8f0..0000000 --- a/.env.cloud.example +++ /dev/null @@ -1,64 +0,0 @@ -# Cloud (paid / managed-keys) mode — env template for openshorts.app. -# Copy to .env and fill in. Only needed when running with docker-compose.cloud.yml. -# Self-hosters running plain BYOK do NOT need any of this. - -BILLING_ENABLED=true - -# Postgres (docker-compose.cloud.yml provisions the `db` service) -POSTGRES_PASSWORD=change-me -DATABASE_URL=postgresql+asyncpg://openshorts:change-me@db:5432/openshorts - -# Auth -JWT_SECRET=generate-a-long-random-string -FRONTEND_URL=https://openshorts.app -ALLOWED_ORIGINS=https://openshorts.app - -# Email — magic link + admin alerts, via SMTP (e.g. Namecheap Private Email). -# Quote the password if it contains $ or * so dotenv keeps it literal. -SMTP_HOST=mail.privateemail.com -SMTP_PORT=465 -SMTP_USER=info@yourdomain.com -SMTP_PASSWORD='your-mailbox-password' -EMAIL_FROM=OpenShorts -# Operational alerts (proxy out of credits / high failure rate) are emailed here. -ADMIN_EMAIL=you@example.com - -# Telegram admin alerts (optional) — instant pings for purchases, cancellations, -# proxy-out-of-credits and high failure rate. Create a bot with @BotFather to get -# the token, then message your bot and read the chat id from: -# https://api.telegram.org/bot/getUpdates -TELEGRAM_BOT_TOKEN= -TELEGRAM_CHAT_ID= - -# Google OAuth (optional; magic link works without it) -GOOGLE_CLIENT_ID= -GOOGLE_CLIENT_SECRET= - -# Stripe (test keys shown; use live keys in production). -# Prices are resolved by lookup_key (starter_monthly, topup_60, ...) at runtime, -# so no price IDs are needed here. Create the prices with those lookup_keys. -STRIPE_SECRET_KEY=sk_test_... -STRIPE_WEBHOOK_SECRET=whsec_... - -# Managed provider keys (server-owned; only handed to entitled paid users) -MANAGED_GEMINI_API_KEY= -MANAGED_UPLOAD_POST_API_KEY= -OPENSHORTS_LOGO_URL=https://openshorts.app/logo.png - -# Residential proxy for YouTube downloads (avoids datacenter-IP bans on the -# hosted server). Recommended: DataImpulse (~$1/GB PAYG). Downloads are capped -# to 720p when this is set, to control bandwidth cost. Empty = direct download. -PROXY_URL= - -# Cloudflare R2 (S3-compatible) — durable storage for users' generated videos. -# Create an R2 bucket + an "Object Read & Write" API token scoped to it. -R2_ENDPOINT=https://.r2.cloudflarestorage.com -R2_BUCKET=openshorts-videos -R2_ACCESS_KEY_ID= -R2_SECRET_ACCESS_KEY= - -# PO-token provider for 720p/1080p YouTube downloads. -# The bgutil provider is baked into the backend image in *script mode* -# (BGUTIL_SCRIPT_PATH is set inside the Dockerfile) — no sidecar, nothing to set here. -# Only if you run bgutil as an external HTTP service, point at it instead: -# BGUTIL_BASE_URL=http://bgutil:4416 diff --git a/.gitignore b/.gitignore index f2df51c..7a52e00 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,6 @@ output/ skills/ skills-lock.json + +# Cloud env example kept local only (avoid leaking infra hints) +.env.cloud.example diff --git a/Dockerfile b/Dockerfile index f50bcf1..3e336d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,11 +37,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ git \ && rm -rf /var/lib/apt/lists/* -# Deno JS runtime — yt-dlp needs it to solve YouTube's nsig challenge for 720p+. +# Deno JS runtime — required by yt-dlp for some extractor challenges. COPY --from=denoland/deno:bin /deno /usr/local/bin/deno -# bgutil PO-token provider, baked in as a local Node script (script mode) — no -# separate service/sidecar needed. Unlocks 720p/1080p together with Deno. +# Helper token provider, baked in as a local Node script (no separate service). RUN git clone --depth 1 https://github.com/Brainicism/bgutil-ytdlp-pot-provider /opt/bgutil-provider \ && cd /opt/bgutil-provider/server \ && npm install --no-audit --no-fund \ @@ -54,8 +53,7 @@ COPY --from=builder /opt/venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" ENV PYTHONUNBUFFERED=1 -# Latest yt-dlp (nightly, YouTube changes constantly) + the bgutil PO-token -# provider plugin. Together with Deno + the baked-in bgutil script this unlocks 720p. +# Latest yt-dlp (nightly — it updates frequently) plus its helper plugin. RUN pip install --upgrade --pre --no-cache-dir "yt-dlp[default]" bgutil-ytdlp-pot-provider # Copy application code diff --git a/cloud/alerts.py b/cloud/alerts.py index be18a30..abb2357 100644 --- a/cloud/alerts.py +++ b/cloud/alerts.py @@ -75,21 +75,20 @@ async def record_job_outcome(ok: bool, error_text: str = ""): # 1) Proxy / credits problem — most urgent, alert immediately. if _looks_like_proxy_error(error_text) and _cooldown_ok("proxy"): await send_admin_alert( - "⚠️ Proxy error — DataImpulse may be out of credits", - "A managed job failed with a proxy-related error. Check your residential " - "proxy balance (DataImpulse) — downloads will keep failing until it's topped up.\n\n" + "⚠️ Proxy error — may be out of credits", + "A managed job failed with a proxy-related error. Check your proxy " + "balance — downloads will keep failing until it's topped up.\n\n" f"Error:\n{error_text[:1200]}", ) return - # 2) High failure rate — the YouTube download path may be broken (arms race). + # 2) High failure rate — the download path may be broken. recent = list(_recent) fails = recent.count(False) if len(recent) >= _FAIL_WINDOW_MIN and fails >= _FAIL_THRESHOLD and _cooldown_ok("failrate"): await send_admin_alert( "⚠️ High download failure rate", - f"{fails} of the last {len(recent)} managed jobs failed. The YouTube " - "download path may be broken (yt-dlp / PO-token change). A backend image " - "rebuild usually pulls the yt-dlp fix.\n\n" + f"{fails} of the last {len(recent)} managed jobs failed. The download " + "path may be broken. Rebuilding the backend image usually pulls a fix.\n\n" f"Last error:\n{error_text[:1200]}", ) diff --git a/cloud/metering.py b/cloud/metering.py index fcd7c88..7e9b380 100644 --- a/cloud/metering.py +++ b/cloud/metering.py @@ -66,10 +66,9 @@ def probe_file_minutes(path: str) -> float: def probe_url_minutes(url: str) -> float: """Return the video duration in minutes from yt-dlp metadata (no download). - Uses the same residential proxy + anti-bot extractor args as the actual - download (main.py), so the metadata probe doesn't get IP-blocked on the - server before we even reach the download step. Metadata only — negligible - bandwidth. Raises ValueError if the duration is unknown (e.g. live streams). + Uses the same proxy + extractor settings as the actual download (main.py) so + the probe behaves consistently with it. Metadata only — negligible bandwidth. + Raises ValueError if the duration is unknown (e.g. live streams). """ import yt_dlp # SSRF guard: reject non-http(s) / private / metadata hosts before probing. diff --git a/docker-compose.cloud.yml b/docker-compose.cloud.yml index 876dc0d..865f9db 100644 --- a/docker-compose.cloud.yml +++ b/docker-compose.cloud.yml @@ -46,11 +46,8 @@ services: - MANAGED_GEMINI_API_KEY=${MANAGED_GEMINI_API_KEY} - MANAGED_UPLOAD_POST_API_KEY=${MANAGED_UPLOAD_POST_API_KEY} - OPENSHORTS_LOGO_URL=${OPENSHORTS_LOGO_URL:-https://openshorts.app/logo.png} - # Residential proxy for YouTube downloads (avoids datacenter-IP bans). - # e.g. http://user:pass@gate.dataimpulse.com:823 — leave empty to go direct. + # Optional HTTP proxy for downloads. Leave empty to go direct. - PROXY_URL=${PROXY_URL:-} - # 720p/1080p: the bgutil PO-token provider is baked into the backend image - # (script mode, BGUTIL_SCRIPT_PATH). No sidecar or BGUTIL_BASE_URL needed. volumes: pgdata: diff --git a/main.py b/main.py index 42b413b..27f6005 100644 --- a/main.py +++ b/main.py @@ -479,21 +479,15 @@ def download_youtube_video(url, output_dir="."): cookies_path = None print("⚠️ YOUTUBE_COOKIES env var not found.") - # Optional residential proxy for YouTube (avoids datacenter-IP bans on hosted - # servers). Set PROXY_URL (e.g. http://user:pass@gate.provider.com:port). - # When unset (self-host), downloads go direct as before. + # Optional HTTP proxy. Set PROXY_URL to route downloads through it; unset + # (self-host) goes direct as before. _proxy = os.environ.get("PROXY_URL", "").strip() or None if _proxy: - print("🌐 Using residential proxy for download.") + print("🌐 Using proxy for download.") # Two download strategies, tried in order so a break in the HD path degrades - # gracefully instead of failing the whole job: - # 1) HD — yt-dlp default clients + the bgutil PO-token provider - # (BGUTIL_BASE_URL, needs the sidecar + Deno + recent yt-dlp) → 720p/1080p. - # 2) Fallback — conservative tv_embed/android clients, no PO provider (~360p), - # which is also the ONLY strategy for self-host (no bgutil configured). - # PO-token provider: HTTP mode (external BGUTIL_BASE_URL) or the baked-in - # local Node script (BGUTIL_SCRIPT_PATH, set in the image). Either enables HD. + # gracefully instead of failing the whole job: an HD attempt first, then a + # conservative fallback (also the only strategy for self-host). _bgutil_http = os.environ.get("BGUTIL_BASE_URL", "").strip() _bgutil_script = os.environ.get("BGUTIL_SCRIPT_PATH", "").strip() if _bgutil_http: