youtube-tui

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.concealed.world/youtube-tui
Log | Files | Refs | README | LICENSE

commit 7c74758ed06fe763f26eccef414e45282e00ea0e
parent 68f678270693fc5acb102b7b9ba47fbbdd44a1ed
Author: Nixx <nixx@firemail.cc>
Date:   Fri, 30 Oct 2020 22:09:52 +0000

Fixed curl issues with '--http2-prior-knowledge', made 'best' format default

Diffstat:
Mexample-config-file/ytsearch | 3++-
Mytsearch | 53+++++++++++++++++++++++++++++++----------------------
2 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/example-config-file/ytsearch b/example-config-file/ytsearch @@ -2,7 +2,8 @@ #https://invidious.13ad.de/ #https://invidious.snopyta.org/ #https://vid.mint.lgbt/ +#https://invidious.tube/ s_website = https://invidious.snopyta.org/ s_results = 10 -s_format = 22/18 +s_format = 22/18/best s_timeout = 20 diff --git a/ytsearch b/ytsearch @@ -1,5 +1,5 @@ #!/bin/sh -# Last Revision: Sat 24 Oct 15:20:35 BST 2020 +# Last Revision: Fri 30 Oct 22:04:00 GMT 2020 # A messy bash TUI client for YT/Invidious. # DEPENDS: youtube-dl, mpv, ffmpeg, xclip, coreutils # @@ -23,7 +23,7 @@ cat << EOF ytsearch ~~~~~~~~ -TUI client for YouTube content. +TUI client for querying YouTube content. Using Invidious to fetch results is faster, and 'friendlier' about number of server requests. When a result is chosen, it is downloaded/ @@ -54,7 +54,7 @@ Config File: Located at either \$HOME/.config/ytsearch or at \$HOME/.ytsearch. Number of results, alternate mirror, preferred youtube-dl format - (default 22/18), and search timeout (secs per loaded page - + (default 'best'), and search timeout (secs per loaded page - default 20) can be set via config file. An example: 's_results = 5' @@ -79,8 +79,13 @@ Config File: --------- Can only be set in config file. Determines video/audio quality: see 'FORMAT SELECTION' on youtube-dl's man page for more - information on options. Default corresponds to 720p for video, - and best audio quality available for audio-only. + information on options. Defaults to 'best' - combination of best + audio and video quality, youtube-dl's default. + Note #1: when you select 'audio' it will download bestaudio and no + video, no matter the value of s_format. + Note #2: I generall recommend you put a '/best' on the end of the + quality option, so that if all else fails, it chooses the best + default. s_timeout: ---------- @@ -168,17 +173,17 @@ if [[ $descend == 'd' || $descend == 'D' || $descend == 'descend' || $descend == playtmp=$(mktemp) playtmpout=$(mktemp) curlpage=1 - curlcheck=$(curl -m ${timeout} -s "${1}") + curlcheck=$(curl --http2-prior-knowledge -m ${timeout} -s "${1}") echo "${curlcheck}" >> $playtmp while [[ -n $(echo "${curlcheck}" | grep "playlist?list=.*page=$((curlpage+1))") ]]; do ((curlpage++)) - curlcheck=$(curl -m ${timeout} -s "${1}&page=${curlpage}") + curlcheck=$(curl --http2-prior-knowledge -m ${timeout} -s "${1}&page=${curlpage}") echo "${curlcheck}" >> $playtmp done [[ $? == 92 ]] && printf "\e[1;91m# ERROR: HTTP/2 stream 0 was not closed cleanly. This is a server problem, consider switching instance.\e[0m\n" && rm $tmp $playtmp $playtmpout && exit 1 process $playtmp $playtmpout [[ $(wc -l $playtmpout | awk '{print $1}') == 0 && -n $(grep "Could not extract playlist info. Instance is likely blocked." $playtmp) ]] && printf "\e[1;91m# ERROR: Could not extract playlist info. Instance is likely blocked - Consider switching instance.\e[0m\n" rm $playtmp $playtmpout $tmp && exit 1 [[ $(wc -l $playtmpout | awk '{print $1}') == 0 && -n $(grep "Read timed out" $playtmp) ]] && printf "\e[1;91m# ERROR: Read timed out - Consider switching instance.\e[0m\n" && rm $playtmp $playtmpout $tmp && exit 1 - [[ $(wc -l $playtmpout | awk '{print $1}') == 0 ]] && printf "\e[1;91m# ERROR: Could not fetch playlist.\e[0m\n" && rm $playtmp $playtmpout $tmp && exit 1 + [[ $(wc -l $playtmpout | awk '{print $1}') == 0 ]] && printf "\e[1;91m# ERROR: Could not fetch playlist. Consider increasing timeout in the config file, or switching Invidious instance.\e[0m\n" && rm $playtmp $playtmpout $tmp && exit 1 rm $playtmp lenplay=$(cat $playtmpout | wc -l) @@ -241,7 +246,7 @@ else resulttmp=$(mktemp) pagecount=0 while [ $pagecount -lt $(($num/20+1)) ]; do ((pagecount++)) - curl -m ${timeout} -s "${website}search?q=${searchhex}&page=${pagecount}" >> $resulttmp + curl --http2-prior-knowledge -m ${timeout} -s "${website}search?q=${searchhex}&page=${pagecount}" >> $resulttmp done [[ $? == 92 ]] && printf "\e[1;91m# ERROR: HTTP/2 stream 0 was not closed cleanly. This is a server problem, consider switching instance.\e[0m\n" && rm $tmp $resulttmp && exit 1 [[ -n $(grep "<title>502 Bad Gateway</title>" $resulttmp) ]] && printf "\e[1;91m# ERROR: 502 Bad Gateway - Consider switching instance.\e[0m\n" && rm $tmp $resulttmp && exit 1 @@ -313,38 +318,38 @@ if [[ $confirm == 'D' || $confirm == 'd' || $confirm == 'download' || $confirm = if [[ $count == 0 && -n $url ]]; then printf '\n' copy "${website}${url}" - youtube-dl -i -f "${vformat}" "https://www.youtube.com/${url}" + [ $vformat ] && youtube-dl -i -f "${vformat}" "${streambase}${url}" || youtube-dl -i "${streambase}${url}" else printf '\n' while [ $(( $matchcount + 1 )) -le $count ]; do copy "${website}${url[$matchcount]}" - youtube-dl -i -f "${vformat}" "https://www.youtube.com/${url[$matchcount]}" + [ $vformat ] && youtube-dl -i -f "${vformat}" "${streambase}${url[$matchcount]}" || youtube-dl -i "${streambase}${url[$matchcount]}" ((matchcount++)) done fi while [[ $playmatchcount -lt ${#playurl[@]} ]]; do fullurl="${playurl[$playmatchcount]}" copy "${website}${fullurl}" - youtube-dl -i -f "${vformat}" "https://www.youtube.com/${fullurl}" + [ $vformat ] && youtube-dl -i -f "${vformat}" "${streambase}${fullurl}" || youtube-dl -i "${streambase}${fullurl}" ((playmatchcount++)) done elif [[ $vid == 'a' || $vid == 'A' || $vid == 'audio' || $vid == 'Audio' ]]; then if [[ $count == 0 && -n $url ]]; then printf '\n' copy "${website}${url}" - youtube-dl -ix --audio-format "mp3" "https://www.youtube.com/${url}" + youtube-dl -ix --audio-format "mp3" "${streambase}${url}" else printf '\n' while [ $(( $matchcount + 1 )) -le $count ]; do copy "${website}${url[$matchcount]}" - youtube-dl -ix --audio-format "mp3" "https://www.youtube.com/${url[$matchcount]}" + youtube-dl -ix --audio-format "mp3" "${streambase}${url[$matchcount]}" ((matchcount++)) done fi while [[ $playmatchcount -lt ${#playurl[@]} ]]; do fullurl="${playurl[$playmatchcount]}" copy "${website}${fullurl}" - youtube-dl -ix --audio-format "mp3" "https://www.youtube.com/${fullurl}" + youtube-dl -ix --audio-format "mp3" "${streambase}${fullurl}" ((playmatchcount++)) done else @@ -357,38 +362,38 @@ elif [[ $confirm == 'S' || $confirm == 's' || $confirm == 'stream' || $confirm = if [[ $count == 0 && -n $url ]]; then printf '\n' copy "${website}${url}" - mpv --ytdl-format="${vformat}" --ytdl "https://www.youtube.com/${url}" + [ $vformat ] && mpv --ytdl-format="${vformat}" --ytdl "${streambase}${url}" || mpv --ytdl "${streambase}${url}" else printf '\n' while [ $(( $matchcount + 1 )) -le $count ]; do copy "${website}${url[$matchcount]}" - mpv --ytdl-format="${vformat}" --ytdl "https://www.youtube.com/${url[$matchcount]}" + [ $vformat ] && mpv --ytdl-format="${vformat}" --ytdl "${streambase}${url[$matchcount]}" || mpv --ytdl "${streambase}${url[$matchcount]}" ((matchcount++)) done fi while [[ $playmatchcount -lt ${#playurl[@]} ]]; do fullurl="${playurl[$playmatchcount]}" copy "${website}${fullurl}" - mpv --ytdl-format="${vformat}" --ytdl "https://www.youtube.com/${fullurl}" + [ $vformat ] && mpv --ytdl-format="${vformat}" --ytdl "${streambase}${fullurl}" || mpv --ytdl "${streambase}${fullurl}" ((playmatchcount++)) done elif [[ $vid == 'a' || $vid == 'A' || $vid == 'audio' || $vid == 'Audio' ]]; then if [[ $count == 0 && -n $url ]]; then printf '\n' copy "${website}${url}" - mpv --ytdl-format=bestaudio --no-video --ytdl "https://www.youtube.com/${url}" + mpv --ytdl-format=bestaudio --no-video --ytdl "${streambase}${url}" else printf '\n' while [ $(( $matchcount + 1 )) -le $count ]; do copy "${website}${url[$matchcount]}" - mpv --ytdl-format=bestaudio --no-video --ytdl "https://www.youtube.com/${url[$matchcount]}" + mpv --ytdl-format=bestaudio --no-video --ytdl "${streambase}${url[$matchcount]}" ((matchcount++)) done fi while [[ $playmatchcount -lt ${#playurl[@]} ]]; do fullurl="${playurl[$playmatchcount]}" copy "${website}${fullurl}" - mpv --ytdl-format=bestaudio --no-video --ytdl "https://www.youtube.com/${fullurl}" + mpv --ytdl-format=bestaudio --no-video --ytdl "${streambase}${fullurl}" ((playmatchcount++)) done else @@ -443,6 +448,10 @@ fi [[ $1 == '-h' || $1 == *'-help'* || $# -gt 3 ]] && message && exit 0 website="${3}" +# This is the site streamed from, typically YouTube. +# If YouTube ever rejects youtube-dl, this can be switched to Invidious. +# Ideally you should never have to change this. +streambase="https://www.youtube.com/" if [[ -z $website ]]; then find ~/.config/ytsearch >/dev/null 2>&1 [[ $? == 0 ]] && configf=~/.config/ytsearch @@ -461,7 +470,7 @@ else num=$2 fi [[ -n $configf && -n $(grep "s_timeout" "${configf}") ]] && timeout=$(grep "s_timeout" "${configf}" | awk '{print $3}') || timeout=20 -[[ -n $configf && -n $(grep "s_format" "${configf}") ]] && vformat=$(grep "s_format" "${configf}" | awk '{print $3}') || vformat="22/18" +[[ -n $configf && -n $(grep "s_format" "${configf}") ]] && vformat=$(grep "s_format" "${configf}" | awk '{print $3}') search="${1}" again=0