youtube-tui

Shell scripts to query YouTube from a terminal.
git clone git://git.concealed.world/youtube-tui
Log | Files | Refs | README | LICENSE

commit 5b126fa06ac224f81aa6c8e38c59c77019b67df8
parent c07a1b4811eb13d891a7e035d1cfdf85c0a3228e
Author: Nixx <nixx@firemail.cc>
Date:   Sat, 16 Oct 2021 12:22:47 +0100

Now supports both youtube-dl and yt-dlp

Diffstat:
Mexample-config-file/ytsearch | 2+-
Mytsearch | 45+++++++++++++++++++++++++--------------------
2 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/example-config-file/ytsearch b/example-config-file/ytsearch @@ -4,6 +4,6 @@ #https://invidious.tube/ #https://invidious.fdn.fr/ s_website = https://invidious.snopyta.org/ -s_results = 10 +s_results = 20 s_format = 22/18/best s_timeout = 5 diff --git a/ytsearch b/ytsearch @@ -1,6 +1,6 @@ #!/bin/bash # A messy bash TUI client for YT/Invidious. -# DEPENDS: youtube-dl, mpv, ffmpeg, xclip, coreutils +# DEPENDS: youtube-dl/yt-dlp, mpv, ffmpeg, xclip, coreutils # # Copyright (C) <2020> <nixx@firemail.cc> # @@ -52,7 +52,7 @@ Config File: Located at either \$HOME/.config/ytsearch or at \$HOME/.ytsearch. - Number of results, alternate mirror, preferred youtube-dl format + Number of results, alternate mirror, preferred download format (default 'best'), and search timeout (secs per loaded page - default 20) can be set via config file. An example: @@ -77,9 +77,9 @@ Config File: s_format: --------- Can only be set in config file. Determines video/audio quality: - see 'FORMAT SELECTION' on youtube-dl's man page for more + see 'FORMAT SELECTION' on youtube-dl's/yt-dlp's man page for more information on options. Defaults to 'best' - combination of best - audio and video quality, youtube-dl's default. + audio and video quality, youtube-dl's/yt-dlp'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 generally recommend you put a '/best' on the end of the @@ -244,7 +244,7 @@ main () { tmp=$(mktemp) if [[ $website == "https://www.youtube.com/" ]]; then - youtube-dl --get-id --get-duration -e ytsearch${num}:"${1}" 1> $tmp 2>/dev/null + ${downloader} --get-id --get-duration -e ytsearch${num}:"${1}" 1> $tmp 2>/dev/null else searchhex=$(hexformat "${1}") resulttmp=$(mktemp) @@ -322,38 +322,38 @@ if [[ $confirm == 'D' || $confirm == 'd' || $confirm == 'download' || $confirm = if [[ $count == 0 && -n $url ]]; then printf '\n' copy "${website}${url}" - [ $vformat ] && youtube-dl -i -f "${vformat}" "${streambase}${url}" || youtube-dl -i "${streambase}${url}" + [ $vformat ] && ${downloader} -i -f "${vformat}" "${streambase}${url}" || ${downloader} -i "${streambase}${url}" else printf '\n' while [ $(( $matchcount + 1 )) -le $count ]; do copy "${website}${url[$matchcount]}" - [ $vformat ] && youtube-dl -i -f "${vformat}" "${streambase}${url[$matchcount]}" || youtube-dl -i "${streambase}${url[$matchcount]}" + [ $vformat ] && ${downloader} -i -f "${vformat}" "${streambase}${url[$matchcount]}" || ${downloader} -i "${streambase}${url[$matchcount]}" ((matchcount++)) done fi while [[ $playmatchcount -lt ${#playurl[@]} ]]; do fullurl="${playurl[$playmatchcount]}" copy "${website}${fullurl}" - [ $vformat ] && youtube-dl -i -f "${vformat}" --no-playlist "${streambase}${fullurl}" || youtube-dl -i --no-playlist "${streambase}${fullurl}" + [ $vformat ] && ${downloader} -i -f "${vformat}" --no-playlist "${streambase}${fullurl}" || ${downloader} -i --no-playlist "${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" "${streambase}${url}" + ${downloader} -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" "${streambase}${url[$matchcount]}" + ${downloader} -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" --no-playlist "${streambase}${fullurl}" + ${downloader} -ix --audio-format "mp3" --no-playlist "${streambase}${fullurl}" ((playmatchcount++)) done else @@ -366,38 +366,38 @@ elif [[ $confirm == 'S' || $confirm == 's' || $confirm == 'stream' || $confirm = if [[ $count == 0 && -n $url ]]; then printf '\n' copy "${website}${url}" - [ $vformat ] && mpv --ytdl-format="${vformat}" --ytdl "${streambase}${url}" || mpv --ytdl "${streambase}${url}" + [ $vformat ] && ${player} --ytdl-format="${vformat}" --ytdl "${streambase}${url}" || ${player} --ytdl "${streambase}${url}" else printf '\n' while [ $(( $matchcount + 1 )) -le $count ]; do copy "${website}${url[$matchcount]}" - [ $vformat ] && mpv --ytdl-format="${vformat}" --ytdl "${streambase}${url[$matchcount]}" || mpv --ytdl "${streambase}${url[$matchcount]}" + [ $vformat ] && ${player} --ytdl-format="${vformat}" --ytdl "${streambase}${url[$matchcount]}" || ${player} --ytdl "${streambase}${url[$matchcount]}" ((matchcount++)) done fi while [[ $playmatchcount -lt ${#playurl[@]} ]]; do fullurl="${playurl[$playmatchcount]}" copy "${website}${fullurl}" - [ $vformat ] && mpv --ytdl-format="${vformat}" --ytdl "${streambase}${fullurl}" || mpv --ytdl "${streambase}${fullurl}" + [ $vformat ] && ${player} --ytdl-format="${vformat}" --ytdl "${streambase}${fullurl}" || ${player} --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 "${streambase}${url}" + ${player} --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 "${streambase}${url[$matchcount]}" + ${player} --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 "${streambase}${fullurl}" + ${player} --ytdl-format=bestaudio --no-video --ytdl "${streambase}${fullurl}" ((playmatchcount++)) done else @@ -452,9 +452,6 @@ 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 @@ -476,6 +473,14 @@ 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}') +if [[ $(which yt-dlp > /dev/null 2>&1) ]]; then + player="mpv" + downloader="youtube-dl" +else + player="mpv --script-opts=ytdl_hook-ytdl_path=yt-dlp" + downloader="yt-dlp" +fi + search="${1}" again=0 clear