Last active
December 13, 2022 15:42
-
-
Save giorgi-o/bc555ccfbe594f1546262c79a5f724fe to your computer and use it in GitHub Desktop.
Command-line music player with autoplay, using yt-dlp and mpv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
SETLOCAL ENABLEDELAYEDEXPANSION | |
:: make sure yt-dlp.exe and mpv.exe are either in the same folder as this script, or in PATH | |
:: volume percentage | |
SET VOLUME=40 | |
SET /p "INPUT=CD Player activated: " | |
if "%INPUT%"=="" exit /b 1 | |
:: favorites | |
IF "%INPUT%"=="lofi" SET "ID=jfKfPfyJRdk" | |
IF "%INPUT%"=="zelda" SET "ID=GdzrrWA8e7A" | |
:: ...add yours here | |
set "YTDLP_OPTIMISATION_ARGS=--extractor-args youtube:skip^=translated_subs^;player_skip^=configs^,webpage^,js^;player_client^=android --extractor-args youtubetab:skip^=webpage" | |
set "YTDLP_ARGS=-f 251/93/ba/ba* --retries infinite --print urls --print " " --print " " --print "Playing %%(fulltitle)s [%%(duration_string^|Live)s]" --print " by %%(uploader)s" --print " " %YTDLP_OPTIMISATION_ARGS%" | |
set "MPV=mpv --no-video --volume=%VOLUME% --af=lavfi=[silenceremove=stop_periods=-1:stop_duration=10:stop_threshold=0.005:detection=peak]" | |
set AUDIO_URL= | |
if "%ID%"=="" ( | |
echo Searching YouTube... | |
for /f "delims=" %%l in ('yt-dlp --print id %YTDLP_ARGS% -- "ytsearch:%INPUT%"') do ( | |
if "!ID!"=="" (set ID=%%l) else (if "!AUDIO_URL!"=="" (set "AUDIO_URL=%%l") else (echo:%%l)) | |
) | |
) else ( | |
echo Loading https://youtube.com/watch^?v^=%ID% | |
for /f "delims=" %%l in ('yt-dlp %YTDLP_ARGS% -- %ID%') do ( | |
if "!AUDIO_URL!"=="" (set "AUDIO_URL=%%l") else (echo:%%l) | |
) | |
) | |
%MPV% "%AUDIO_URL%" | |
echo Autoplaying related videos... | |
:: get list of ids from yt-dlp | |
set AUTOPLAY_COUNT=100 | |
for /f %%i in ('yt-dlp %YTDLP_OPTIMISATION_ARGS% --get-id --flat-playlist --playlist-items 2:%AUTOPLAY_COUNT% -- "https://www.youtube.com/watch?v=%ID%&list=RDAMVM%ID%&start_radio=1"') do ( | |
echo: | |
echo Loading https://youtube.com/watch^?v^=%%i | |
set AUDIO_URL= | |
for /f "delims=" %%l in ('yt-dlp %YTDLP_ARGS% -- %%i') do ( | |
if "!AUDIO_URL!"=="" (set "AUDIO_URL=%%l") else (echo:%%l) | |
) | |
%MPV% "!AUDIO_URL!" | |
) | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment