feat: unlock 720p/1080p YouTube downloads (Deno + bgutil PO tokens)
YouTube now forces SABR streaming, capping downloads at 360p without a GVS PO token. Adds the full recipe (cloud mode only): - Dockerfile: Deno JS runtime (nsig challenge) + latest yt-dlp[default] nightly + bgutil-ytdlp-pot-provider plugin - docker-compose.cloud.yml: bgutil PO-token sidecar + BGUTIL_BASE_URL - main.py / metering.py: when BGUTIL_BASE_URL is set, use yt-dlp default clients + the bgutil HTTP provider (→ 720p); self-host keeps the conservative fallback Verified E2E through the container: managed user -> YouTube -> DataImpulse residential proxy + Deno + bgutil -> real 720p (format 136) download, no 403.
This commit is contained in:
parent
c15f26b31c
commit
ebe876c497
5 changed files with 50 additions and 15 deletions
|
|
@ -36,3 +36,7 @@ OPENSHORTS_LOGO_URL=https://openshorts.app/logo.png
|
|||
# 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=
|
||||
|
||||
# PO-token provider for 720p/1080p YouTube (bgutil sidecar in docker-compose.cloud.yml).
|
||||
# Defaults to the sidecar; only override if you run bgutil elsewhere.
|
||||
BGUTIL_BASE_URL=http://bgutil:4416
|
||||
|
|
|
|||
|
|
@ -35,13 +35,18 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||
nodejs \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Deno JS runtime — yt-dlp needs it to solve YouTube's nsig challenge for 720p+
|
||||
# (used together with the bgutil PO-token sidecar in cloud mode).
|
||||
COPY --from=denoland/deno:bin /deno /usr/local/bin/deno
|
||||
|
||||
# Copy virtual env from builder
|
||||
COPY --from=builder /opt/venv /opt/venv
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# Always upgrade yt-dlp to latest (YouTube bot-detection changes frequently)
|
||||
RUN pip install --upgrade --no-cache-dir yt-dlp
|
||||
# Latest yt-dlp (nightly, YouTube changes constantly) + the bgutil PO-token
|
||||
# provider plugin. Together with Deno + the bgutil sidecar this unlocks 720p/1080p.
|
||||
RUN pip install --upgrade --pre --no-cache-dir "yt-dlp[default]" bgutil-ytdlp-pot-provider
|
||||
|
||||
# Copy application code
|
||||
COPY . .
|
||||
|
|
|
|||
|
|
@ -72,14 +72,19 @@ def probe_url_minutes(url: str) -> float:
|
|||
bandwidth. Raises ValueError if the duration is unknown (e.g. live streams).
|
||||
"""
|
||||
import yt_dlp
|
||||
opts = {
|
||||
"skip_download": True, "quiet": True, "no_warnings": True,
|
||||
"extractor_args": {
|
||||
bgutil = os.environ.get("BGUTIL_BASE_URL", "").strip()
|
||||
if bgutil:
|
||||
extractor_args = {"youtubepot-bgutilhttp": {"base_url": [bgutil]}}
|
||||
else:
|
||||
extractor_args = {
|
||||
"youtube": {
|
||||
"player_client": ["tv_embed", "android", "mweb", "web"],
|
||||
"player_skip": ["webpage", "configs"],
|
||||
}
|
||||
},
|
||||
}
|
||||
opts = {
|
||||
"skip_download": True, "quiet": True, "no_warnings": True,
|
||||
"extractor_args": extractor_args,
|
||||
}
|
||||
proxy = os.environ.get("PROXY_URL", "").strip()
|
||||
if proxy:
|
||||
|
|
|
|||
|
|
@ -21,10 +21,19 @@ services:
|
|||
retries: 10
|
||||
restart: unless-stopped
|
||||
|
||||
# PO-token provider — lets yt-dlp fetch YouTube's GVS PO tokens so 720p/1080p
|
||||
# formats are available (with Deno + a recent yt-dlp in the backend image).
|
||||
bgutil:
|
||||
image: brainicism/bgutil-ytdlp-pot-provider
|
||||
container_name: openshorts-bgutil
|
||||
restart: unless-stopped
|
||||
|
||||
backend:
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
bgutil:
|
||||
condition: service_started
|
||||
environment:
|
||||
- BILLING_ENABLED=true
|
||||
- DATABASE_URL=postgresql+asyncpg://openshorts:${POSTGRES_PASSWORD:-openshorts}@db:5432/openshorts
|
||||
|
|
@ -47,6 +56,8 @@ services:
|
|||
# Residential proxy for YouTube downloads (avoids datacenter-IP bans).
|
||||
# e.g. http://user:pass@gate.dataimpulse.com:823 — leave empty to go direct.
|
||||
- PROXY_URL=${PROXY_URL:-}
|
||||
# PO-token provider (bgutil sidecar) → unlocks 720p/1080p downloads.
|
||||
- BGUTIL_BASE_URL=${BGUTIL_BASE_URL:-http://bgutil:4416}
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
|
|
|
|||
28
main.py
28
main.py
|
|
@ -481,9 +481,24 @@ def download_youtube_video(url, output_dir="."):
|
|||
if _proxy:
|
||||
print("🌐 Using residential proxy for download.")
|
||||
|
||||
# Common yt-dlp options to work around YouTube bot detection.
|
||||
# extractor_args tries multiple player clients in order; tv_embed / android
|
||||
# avoid the OAuth/PO-token checks that block server IPs.
|
||||
# YouTube client strategy:
|
||||
# - Hosted (BGUTIL_BASE_URL set): use yt-dlp's default clients + the bgutil
|
||||
# PO-token provider → unlocks 720p/1080p (needs the bgutil sidecar + a Deno
|
||||
# JS runtime + a recent yt-dlp, all baked into the cloud image).
|
||||
# - Self-host (no bgutil): fall back to the conservative tv_embed/android
|
||||
# clients that work without a PO-token provider (caps around 360p, but no
|
||||
# extra infra required).
|
||||
_bgutil = os.environ.get("BGUTIL_BASE_URL", "").strip()
|
||||
if _bgutil:
|
||||
_extractor_args = {'youtubepot-bgutilhttp': {'base_url': [_bgutil]}}
|
||||
else:
|
||||
_extractor_args = {
|
||||
'youtube': {
|
||||
'player_client': ['tv_embed', 'android', 'mweb', 'web'],
|
||||
'player_skip': ['webpage', 'configs'],
|
||||
}
|
||||
}
|
||||
|
||||
_COMMON_YDL_OPTS = {
|
||||
'quiet': False,
|
||||
'verbose': True,
|
||||
|
|
@ -495,12 +510,7 @@ def download_youtube_video(url, output_dir="."):
|
|||
'fragment_retries': 10,
|
||||
'nocheckcertificate': True,
|
||||
'cachedir': False,
|
||||
'extractor_args': {
|
||||
'youtube': {
|
||||
'player_client': ['tv_embed', 'android', 'mweb', 'web'],
|
||||
'player_skip': ['webpage', 'configs'],
|
||||
}
|
||||
},
|
||||
'extractor_args': _extractor_args,
|
||||
'http_headers': {
|
||||
'User-Agent': (
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
|
||||
|
|
|
|||
Loading…
Reference in a new issue