@echo off
rem update-yt-dlp-nightly.bat
rem
rem Installs the latest yt-dlp NIGHTLY build as a standalone yt-dlp.exe.
rem This is a thin dispatcher  -  the actual logic lives in
rem update-yt-dlp-nightly.ps1, which MUST stay in the same directory as
rem this file. Run it however and whenever YOU decide: by hand, from
rem Windows Task Scheduler, from your BBS software's own event scheduler
rem (e.g. Synchronet's Timed Events). This script does none of that
rem scheduling itself  -  see "Scheduling this yourself" below.
rem
rem Why nightly, and why worth scheduling at all: yt-dlp's stable releases
rem lag behind YouTube's frequent extractor/player-client changes by
rem design (stable is for general-purpose reliability across every site
rem yt-dlp supports, not fast-tracking one site's breakage). In practice
rem this means YouTube can break in a way stable doesn't fix for weeks,
rem while nightly usually has it fixed within a day or two  -  see
rem README's "Fixing intermittent HTTP 403 errors" section for the
rem specific incident that prompted this script: yt-dlp stable@2026.07.04
rem hit a 100%%-failure-rate YouTube extractor break; nightly@2026.08.17
rem had already fixed it.
rem
rem Trade-off, stated plainly: nightly is explicitly NOT the vetted-stable
rem channel  -  an occasional nightly build can introduce its own
rem regression. Running this on a schedule accepts that small, usually-
rem short-lived risk in exchange for not being stuck broken against
rem YouTube for weeks at a time. If a nightly update ever makes things
rem worse, grab the current stable yt-dlp.exe from
rem https://github.com/yt-dlp/yt-dlp/releases/latest instead and swap it
rem back in the same way, then investigate.
rem
rem Works with PowerShell 2.0, which is what Windows 7 SP1 ships by
rem default (confirmed live on a real Windows 7 SP1 BBS box)  -  the .ps1
rem deliberately avoids every PowerShell 3.0+-only feature. No Windows
rem Management Framework upgrade needed.
rem
rem ---- Usage ----
rem   update-yt-dlp-nightly.bat                          updates yt-dlp.exe next to this script
rem   update-yt-dlp-nightly.bat "C:\path\to\yt-dlp.exe"   updates a specific file instead
rem
rem ---- Scheduling this yourself ----
rem
rem Windows Task Scheduler (schtasks, run as the same account that
rem launches the door, daily at 03:17  -  offset from :00 on purpose so
rem you're not hammering GitHub's API at the same instant as every other
rem scheduled task on earth):
rem
rem   schtasks /create /tn "update-yt-dlp-nightly" /tr "C:\path\to\update-yt-dlp-nightly.bat" /sc daily /st 03:17
rem
rem Your BBS software's own event/task scheduler: this is just a normal
rem batch file with a normal exit code (0 = success or "already current",
rem 1 = failed, leaves yt-dlp.exe untouched either way) and status lines
rem printed to stdout  -  point whatever "run this external command on a
rem schedule" feature your BBS package has at it (e.g. Synchronet's Timed
rem Events) exactly like you would any other maintenance script.

rem Full path, not bare "powershell"  -  confirmed live on a real Windows 7
rem SP1 box: powershell.exe was present at the normal location below but
rem NOT on PATH ("'powershell' is not recognized..."), so PATH-based
rem resolution can't be relied on. %SystemRoot% is always set.
set PWSH="%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe"
if not exist %PWSH% (
    echo update-yt-dlp-nightly: ERROR: PowerShell not found at %PWSH%
    exit /b 1
)
%PWSH% -NoProfile -ExecutionPolicy Bypass -File "%~dp0update-yt-dlp-nightly.ps1" %*
exit /b %errorlevel%
