TL;DR
you use curl --head --location --write-out "%{url_effective}" --url "https://github.com/[USER]/[REPO]/releases/latest/download/foo.bar"
here is an example, in-practice,
yt-dlp (nightly) uses github API to check to see if it is the latest version available,
but github API is rate limited, and often fails (without a token).
due to yt-dlp using the tag name, in releases,
same as their versioning system,
and each of the releases uses same-name convention,
https://github.com/yt-dlp/yt-dlp-nightly-builds/releases/latest/download/yt-dlp.exe
will first redirect /latest/ to the actual latest release.
you'll have to store then crop the string by start and end points,
but eventually you'll be able to compare (just if it is the same or not),
to the value you'll get from yt-dlp --version
the following code is a part of longer script,
it uses curl with proxy, for downloading using an opened TOR browser.
it also preserve previous --help entries, and generate new --help entries,
this way you can compare them both to see what has changed.
this is a Windows CMD batch file, with no special expansions. it provides both DNS over HTTPS, as well simply resolve hostnames to IP to reduce some traffic.
as for curl.exe all Windows 10+ should have one already installled.
::@echo off
chcp 65001 1>nul 2>nul
::-----------------------------------
:: yt-dlp dependencies and updater.
::-----------------------------------
::------------------------------------------------------------------------------------------------
pushd "%~sdp0"
set "PATH=%CD%;%PATH%"
goto MAIN
::------------------------------------------------------------------------------------------------
::------------------------------------------------------------------------------------------------
:CURL_OVER_TOR
echo. 1>&2
echo. 1>&2
echo [INFO] request URL: [%~1] 1>&2
echo [INFO] force filename: [%~2] 1>&2
set "ARGS="
set ARGS=%ARGS% --disable
set ARGS=%ARGS% --verbose
set ARGS=%ARGS% --remote-time
set ARGS=%ARGS% --location-trusted
set ARGS=%ARGS% --insecure
set ARGS=%ARGS% --anyauth
set ARGS=%ARGS% --tlsv1.2
set ARGS=%ARGS% --ssl-no-revoke
set ARGS=%ARGS% --ssl-revoke-best-effort
set ARGS=%ARGS% --doh-insecure
::set ARGS=%ARGS% --socks5-hostname "127.0.0.1:9150"
set ARGS=%ARGS% --proxy "socks5h://127.0.0.1:9150"
set ARGS=%ARGS% --noproxy "localhost,127.0.0.1,::1,192.168.0.0/24,10.0.0.0/24"
set ARGS=%ARGS% --resolve "github.com:443:140.82.112.6"
set ARGS=%ARGS% --resolve "github.com:443:140.82.114.3"
set ARGS=%ARGS% --resolve "raw.githubusercontent.com:443:185.199.111.133"
set ARGS=%ARGS% --resolve "release-assets.githubusercontent.com:443:185.199.108.133"
set ARGS=%ARGS% --resolve "release-assets.githubusercontent.com:443:185.199.109.133"
set ARGS=%ARGS% --resolve "release-assets.githubusercontent.com:443:185.199.110.133"
set ARGS=%ARGS% --resolve "release-assets.githubusercontent.com:443:185.199.111.133"
set ARGS=%ARGS% --resolve "security.cloudflare-dns.com:443:1.1.1.2"
set ARGS=%ARGS% --resolve "security.cloudflare-dns.com:443:1.0.0.2"
set ARGS=%ARGS% --resolve "security.cloudflare-dns.com:443:[2606:4700:4700::1112]"
set ARGS=%ARGS% --resolve "security.cloudflare-dns.com:443:[2606:4700:4700::1002]"
set ARGS=%ARGS% --doh-url "https://security.cloudflare-dns.com/dns-query"
set ARGS=%ARGS% --url "%~1"
if ["%~2"] neq [""] (
set ARGS=%ARGS% --output-dir "%CD%"
set ARGS=%ARGS% --output "%~2"
)
::set "HTTP_PROXY=http://127.0.0.1:9150"
::set "HTTPS_PROXY=http://127.0.0.1:9150"
set "ALL_PROXY=socks5h://127.0.0.1:9150"
set "NO_PROXY=localhost,127.0.0.1,::1,192.168.0.0/24,10.0.0.0/24"
echo. 1>&2
call "curl.exe" %ARGS%
set "EXIT_CODE=%ErrorLevel%"
set "HTTP_PROXY="
set "HTTPS_PROXY="
set "ALL_PROXY="
set "NO_PROXY="
echo [INFO] CURL ended with EXIT_CODE: %EXIT_CODE% 1>&2
goto :eof
::------------------------------------------------------------------------------------------------
:MAIN
"taskkill.exe" /F /IM "yt-dlp.exe" /T
::--- yt-dlp.exe downloading without using the built-in updater, and without using api.github.com .
set "YT_DLP_VERSION_LATEST="
for /F "usebackq delims=" %%E IN (`call "curl.exe" --disable --silent --head --ipv4 --proxy "socks5h://127.0.0.1:9150" --max-redirs 1 --location --output nul --write-out "%%{url_effective}" --url "https://github.com/yt-dlp/yt-dlp-nightly-builds/releases/latest/download/yt-dlp.exe" 2^>nul`) do (
set "YT_DLP_VERSION_LATEST=%%E"
goto EXIT_LOOP_YT_DLP_VERSION_LATEST
)
:EXIT_LOOP_YT_DLP_VERSION_LATEST
set "YT_DLP_VERSION_LATEST=%YT_DLP_VERSION_LATEST:~66,17%"
set "YT_DLP_VERSION_CURRENT="
for /F "usebackq delims=" %%E IN (`call ".\yt-dlp.exe" --version 2^>nul`) do (
set "YT_DLP_VERSION_CURRENT=%%E"
goto EXIT_LOOP_YT_DLP_VERSION_CURRENT
)
:EXIT_LOOP_YT_DLP_VERSION_CURRENT
::--- note: the whole two checks above is just to "delete" (well.. rename) any existing version. which will trigger the download. readme are --help entries. it's a good way to figure out if anything important has changed from one version to another.
if ["%YT_DLP_VERSION_LATEST%"] neq ["%YT_DLP_VERSION_CURRENT%"] (
del /f /q "yt-dlp.exe.old" 1>nul 2>nul
ren "yt-dlp.exe" "yt-dlp.exe.old" 1>nul 2>nul
call :CURL_OVER_TOR "https://github.com/yt-dlp/yt-dlp-nightly-builds/releases/latest/download/yt-dlp.exe" "yt-dlp.exe"
del "__readme_yt-dlp.old.txt" 1>nul 2>nul
ren "__readme_yt-dlp.txt" "__readme_yt-dlp.old.txt" 1>nul 2>nul
"yt-dlp.exe" --version 1>"__readme_yt-dlp.txt" 2>&1
"yt-dlp.exe" --help 1>>"__readme_yt-dlp.txt" 2>&1
)
pause