Last active
October 12, 2021 12:20
-
-
Save kidpixo/28c073a30598a6985d942d46d3bb2791 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#------------------------------------------------ | |
# Name : yt-streamer | |
# Input : youtube URL | |
# Purpose : stream url video to mpv. see: | |
# https://github.com/ytdl-org/youtube-dl/issues/2124#issuecomment-32429104 | |
#------------------------------------------------ | |
yt-streamer() { | |
# locale colors do not work in sub-functions | |
open=$'\001' | |
close=$'\002' | |
RED=$open`tput setaf 1`$close | |
RESET=$open`tput sgr0`$close | |
GREEN=$open`tput setaf 2`$close | |
# add help option == print and exit | |
if [[ "$1" == "-h" ]] || [[ -z "$1" ]] | |
then | |
echo "yt-streamer ():" | |
echo "├─ Description : Stream URL video to mpv via youtube-dl." | |
echo "└─ Usage : yt-streamer ${GREEN}URL${RESET} ${RED}OPTIONS${RESET}" | |
echo " └─ ${RED}OPTIONS${RESET} : passed to youtube-dl, ${GREEN}default${RESET} '-f \"bestaudio/best\"'" | |
echo | |
return 0 | |
else | |
# caputure all other arguments after 1st URL | |
local ytdl_args="${@:2}" | |
# check if format is passed, if not add default format | |
if [[ ! $ytdl_args =~ "-f" ]]; then | |
ytdl_args+='-f "bestaudio/best"' | |
fi | |
echo youtube-dl -o - ${ytdl_args} "$1" "| mpv -" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment