Youtube to mpd


Below a script taking a youtube url as argument. The audio is extracted, then added to the mpd library, inserted in the playlist then played.

# download sound from youtube, convert to $format,
# then insert and play in mpd
MUSDIR=$(awk '/music_directory/ {sub("^\"","",$2);sub("\"$","",$2); print $2}' $HOME/.mpdconf)
cd ${MUSDIR}
yt-dlp --no-playlist -x \
	--audio-format $format \
	-c "${1}" \
	-o "%(title)s.%(ext)s" \
	--exec "mpc --wait update && mpc insert \"%(title)s.%(ext)s\" && mpc next"