@echo OFF
title %~n0
:: Drop this script where you want to save streams to, and make sure
:: the STREAMLINK_DIR variable is set to the location of your Streamlink
:: install.
::
:: Windows installer:
::     https://github.com/streamlink/streamlink/releases/latest
:: Option documentation:
::     https://streamlink.github.io/cli.html
::
:: Note: Youtube broke rewinding using HLS in Apr 2020, so options for
::       that won't work.

set STREAMLINK_DIR=C:\Program Files (x86)\Streamlink

:: CHECK_DELAY: Seconds between checks to see if stream has begun
set CHECK_DELAY=60
:: RECONN_TIMEOUT: Max seconds waiting for a stalled stream to restart
set RECONN_TIMEOUT=300

set OUT_DIR=%cd%
cd %STREAMLINK_DIR%
:PROMPT
set /p URL="URL: "
set FN=out.ts
set /p FN="OUTPUT [out.ts]: "
set QUAL=480p
set /p QUAL="QUALITY [480p]: "
streamlink.exe "%URL%" %QUAL% --retry-streams %CHECK_DELAY% --hls-timeout %RECONN_TIMEOUT% --force -o "%OUT_DIR%\%FN%"
echo.
goto :PROMPT
