Skip to content

Instantly share code, notes, and snippets.

@kidpixo
Created April 12, 2024 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidpixo/7bb40d29f269205472e573e981ea86d0 to your computer and use it in GitHub Desktop.
Save kidpixo/7bb40d29f269205472e573e981ea86d0 to your computer and use it in GitHub Desktop.
#------------------------------------------------
# Name : yt-streamer
# Input : youtube URL
# Purpose : stream url video from youtube to mpv. see:
# https://github.com/ytdl-org/yt-dlp/issues/2124#issuecomment-32429104
# Dependencies : yt-dlp, mpv
#------------------------------------------------
yt-streamer() {
# add help option == print and exit
if [[ "$1" == "-h" ]] || [[ -z "$1" ]]
then
echo "yt-streamer ():"
echo "├─ Description : Stream URL video to mpv via yt-dlp."
echo "└─ Usage : yt-streamer ${GREEN}URL${RESET} ${RED}OPTIONS${RESET}"
echo " └─ ${RED}OPTIONS${RESET} : passed to yt-dlp, ${GREEN}default${RESET} '-f \"bestaudio/best\"'"
echo
return 0
else
# # caputure all other arguments after 1st URL
local ytdl_args="${@:1}"
# local ytdl_args="${@:1}"
# # check if format is passed, if not add default format
# if [[ ! $ytdl_args =~ "-f " ]]; then
# ytdl_args=" -f \"bestaudio/best\" \"$ytdl_args\""
# fi
yt-dlp -o - -f "bestaudio/best" "${ytdl_args}" | mpv -
echo "yt-dlp -o --f \"bestaudio/best\" \"${ytdl_args}\" | mpv -" # debug command
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment