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.
This commit is contained in:
parent
41f43dc0dc
commit
c32d579675
7 changed files with 21 additions and 95 deletions
|
|
@ -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 <info@yourdomain.com>
|
|
||||||
# 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<TOKEN>/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://<account_id>.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
|
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -40,3 +40,6 @@ output/
|
||||||
skills/
|
skills/
|
||||||
skills-lock.json
|
skills-lock.json
|
||||||
|
|
||||||
|
|
||||||
|
# Cloud env example kept local only (avoid leaking infra hints)
|
||||||
|
.env.cloud.example
|
||||||
|
|
|
||||||
|
|
@ -37,11 +37,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
git \
|
git \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& 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
|
COPY --from=denoland/deno:bin /deno /usr/local/bin/deno
|
||||||
|
|
||||||
# bgutil PO-token provider, baked in as a local Node script (script mode) — no
|
# Helper token provider, baked in as a local Node script (no separate service).
|
||||||
# separate service/sidecar needed. Unlocks 720p/1080p together with Deno.
|
|
||||||
RUN git clone --depth 1 https://github.com/Brainicism/bgutil-ytdlp-pot-provider /opt/bgutil-provider \
|
RUN git clone --depth 1 https://github.com/Brainicism/bgutil-ytdlp-pot-provider /opt/bgutil-provider \
|
||||||
&& cd /opt/bgutil-provider/server \
|
&& cd /opt/bgutil-provider/server \
|
||||||
&& npm install --no-audit --no-fund \
|
&& npm install --no-audit --no-fund \
|
||||||
|
|
@ -54,8 +53,7 @@ COPY --from=builder /opt/venv /opt/venv
|
||||||
ENV PATH="/opt/venv/bin:$PATH"
|
ENV PATH="/opt/venv/bin:$PATH"
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
# Latest yt-dlp (nightly, YouTube changes constantly) + the bgutil PO-token
|
# Latest yt-dlp (nightly — it updates frequently) plus its helper plugin.
|
||||||
# provider plugin. Together with Deno + the baked-in bgutil script this unlocks 720p.
|
|
||||||
RUN pip install --upgrade --pre --no-cache-dir "yt-dlp[default]" bgutil-ytdlp-pot-provider
|
RUN pip install --upgrade --pre --no-cache-dir "yt-dlp[default]" bgutil-ytdlp-pot-provider
|
||||||
|
|
||||||
# Copy application code
|
# Copy application code
|
||||||
|
|
|
||||||
|
|
@ -75,21 +75,20 @@ async def record_job_outcome(ok: bool, error_text: str = ""):
|
||||||
# 1) Proxy / credits problem — most urgent, alert immediately.
|
# 1) Proxy / credits problem — most urgent, alert immediately.
|
||||||
if _looks_like_proxy_error(error_text) and _cooldown_ok("proxy"):
|
if _looks_like_proxy_error(error_text) and _cooldown_ok("proxy"):
|
||||||
await send_admin_alert(
|
await send_admin_alert(
|
||||||
"⚠️ Proxy error — DataImpulse may be out of credits",
|
"⚠️ Proxy error — may be out of credits",
|
||||||
"A managed job failed with a proxy-related error. Check your residential "
|
"A managed job failed with a proxy-related error. Check your proxy "
|
||||||
"proxy balance (DataImpulse) — downloads will keep failing until it's topped up.\n\n"
|
"balance — downloads will keep failing until it's topped up.\n\n"
|
||||||
f"Error:\n{error_text[:1200]}",
|
f"Error:\n{error_text[:1200]}",
|
||||||
)
|
)
|
||||||
return
|
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)
|
recent = list(_recent)
|
||||||
fails = recent.count(False)
|
fails = recent.count(False)
|
||||||
if len(recent) >= _FAIL_WINDOW_MIN and fails >= _FAIL_THRESHOLD and _cooldown_ok("failrate"):
|
if len(recent) >= _FAIL_WINDOW_MIN and fails >= _FAIL_THRESHOLD and _cooldown_ok("failrate"):
|
||||||
await send_admin_alert(
|
await send_admin_alert(
|
||||||
"⚠️ High download failure rate",
|
"⚠️ High download failure rate",
|
||||||
f"{fails} of the last {len(recent)} managed jobs failed. The YouTube "
|
f"{fails} of the last {len(recent)} managed jobs failed. The download "
|
||||||
"download path may be broken (yt-dlp / PO-token change). A backend image "
|
"path may be broken. Rebuilding the backend image usually pulls a fix.\n\n"
|
||||||
"rebuild usually pulls the yt-dlp fix.\n\n"
|
|
||||||
f"Last error:\n{error_text[:1200]}",
|
f"Last error:\n{error_text[:1200]}",
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -66,10 +66,9 @@ def probe_file_minutes(path: str) -> float:
|
||||||
def probe_url_minutes(url: str) -> float:
|
def probe_url_minutes(url: str) -> float:
|
||||||
"""Return the video duration in minutes from yt-dlp metadata (no download).
|
"""Return the video duration in minutes from yt-dlp metadata (no download).
|
||||||
|
|
||||||
Uses the same residential proxy + anti-bot extractor args as the actual
|
Uses the same proxy + extractor settings as the actual download (main.py) so
|
||||||
download (main.py), so the metadata probe doesn't get IP-blocked on the
|
the probe behaves consistently with it. Metadata only — negligible bandwidth.
|
||||||
server before we even reach the download step. Metadata only — negligible
|
Raises ValueError if the duration is unknown (e.g. live streams).
|
||||||
bandwidth. Raises ValueError if the duration is unknown (e.g. live streams).
|
|
||||||
"""
|
"""
|
||||||
import yt_dlp
|
import yt_dlp
|
||||||
# SSRF guard: reject non-http(s) / private / metadata hosts before probing.
|
# SSRF guard: reject non-http(s) / private / metadata hosts before probing.
|
||||||
|
|
|
||||||
|
|
@ -46,11 +46,8 @@ services:
|
||||||
- MANAGED_GEMINI_API_KEY=${MANAGED_GEMINI_API_KEY}
|
- MANAGED_GEMINI_API_KEY=${MANAGED_GEMINI_API_KEY}
|
||||||
- MANAGED_UPLOAD_POST_API_KEY=${MANAGED_UPLOAD_POST_API_KEY}
|
- MANAGED_UPLOAD_POST_API_KEY=${MANAGED_UPLOAD_POST_API_KEY}
|
||||||
- OPENSHORTS_LOGO_URL=${OPENSHORTS_LOGO_URL:-https://openshorts.app/logo.png}
|
- OPENSHORTS_LOGO_URL=${OPENSHORTS_LOGO_URL:-https://openshorts.app/logo.png}
|
||||||
# Residential proxy for YouTube downloads (avoids datacenter-IP bans).
|
# Optional HTTP proxy for downloads. Leave empty to go direct.
|
||||||
# e.g. http://user:pass@gate.dataimpulse.com:823 — leave empty to go direct.
|
|
||||||
- PROXY_URL=${PROXY_URL:-}
|
- 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:
|
volumes:
|
||||||
pgdata:
|
pgdata:
|
||||||
|
|
|
||||||
16
main.py
16
main.py
|
|
@ -479,21 +479,15 @@ def download_youtube_video(url, output_dir="."):
|
||||||
cookies_path = None
|
cookies_path = None
|
||||||
print("⚠️ YOUTUBE_COOKIES env var not found.")
|
print("⚠️ YOUTUBE_COOKIES env var not found.")
|
||||||
|
|
||||||
# Optional residential proxy for YouTube (avoids datacenter-IP bans on hosted
|
# Optional HTTP proxy. Set PROXY_URL to route downloads through it; unset
|
||||||
# servers). Set PROXY_URL (e.g. http://user:pass@gate.provider.com:port).
|
# (self-host) goes direct as before.
|
||||||
# When unset (self-host), downloads go direct as before.
|
|
||||||
_proxy = os.environ.get("PROXY_URL", "").strip() or None
|
_proxy = os.environ.get("PROXY_URL", "").strip() or None
|
||||||
if _proxy:
|
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
|
# Two download strategies, tried in order so a break in the HD path degrades
|
||||||
# gracefully instead of failing the whole job:
|
# gracefully instead of failing the whole job: an HD attempt first, then a
|
||||||
# 1) HD — yt-dlp default clients + the bgutil PO-token provider
|
# conservative fallback (also the only strategy for self-host).
|
||||||
# (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.
|
|
||||||
_bgutil_http = os.environ.get("BGUTIL_BASE_URL", "").strip()
|
_bgutil_http = os.environ.get("BGUTIL_BASE_URL", "").strip()
|
||||||
_bgutil_script = os.environ.get("BGUTIL_SCRIPT_PATH", "").strip()
|
_bgutil_script = os.environ.get("BGUTIL_SCRIPT_PATH", "").strip()
|
||||||
if _bgutil_http:
|
if _bgutil_http:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue