minor changes to search and queue

This commit is contained in:
Emma Tebibyte 2023-11-19 23:02:05 -07:00
parent b47033a965
commit f4b32f84a6
Signed by: emma
GPG Key ID: 6D661C738815E7DD

69
yt
View File

@ -101,14 +101,25 @@ lines() {
}
list() {
selection="$(ls "$YT_PL_DIR" | sed 's/\.m3u//g' | $YTPICK)"
if test -z "$YTPICK"; then
printf "%s: Please set \$YTPICK to your preferred picking tool." \
"$argv0" 1>&2
exit 78 # sysexits.h(3) EX_CONFIG
fi
while test -d "$YT_PL_DIR/$selection"; do
dir="$selection"
selection="$(ls "$YT_PL_DIR/$selection" | sed 's/\.m3u//g' | $YTPICK)"
done
pick "$(menu)"
}
pick "$dir/$selection"
menu() {
playlist="$(ls "$YT_PL_DIR" | sed 's/\.m3u//g' | $YTPICK)"
while test -d "$YT_PL_DIR/$playlist"; do
dir="$playlist"
playlist="$(ls "$YT_PL_DIR/$playlist" | sed 's/\.m3u//g' | $YTPICK \
|| printf '')"
done
printf '%s/%s\n' "$dir" "$playlist"
}
music() { # downloads a video, splitting by chapter and only saving the audio
@ -158,12 +169,50 @@ play() { # play a video after caching its title
}
queue() {
if test -z "$1"; then
queue "$(menu)"
fi
while test -f "$YT_PL_DIR/$1.m3u"; do
mpv "$YT_PL_DIR/$1.m3u"
shift
done
}
search() {
if test -z "$YTPICK"; then
printf "%s: Please set \$YTPICK to your preferred picking tool." \
"$argv0" 1>&2
exit 78 # sysexits.h(3) EX_CONFIG
fi
results="$(yt-dlp "ytsearch$2:$1" --print "$FMT")"
selection="$(printf '%s\n' "$results" \
| $YTPICK \
| cut -d'[' -f2 \
| tr -d ']')"
if test -n "$selection"; then
option="$(printf 'copy\nmusic\nplay\nsave\n' | $YTPICK)"
case "$option" in
"copy")
wl-copy "$selection"
;;
"music")
music "$selection"
;;
"play")
play "$selection"
;;
"save")
add "$selection" "$(menu)"
;;
esac
fi
}
usage() {
printf "Usage: %s %s\n" "$argv0" "$@" 1>&2
exit 64 # sysexits.h(3) EX_USAGE
@ -255,13 +304,17 @@ case "$com" in
pick "$@"
;;
play)
shift 2>/dev/null || usage 'uri...'
shift 2>/dev/null || usage 'play uri...'
play "$@"
;;
queue)
shift 2>/dev/null || usage 'file...'
shift 2>/dev/null || usage 'queue file...'
queue "$@"
;;
search)
shift 2>/dev/null || usage 'search term count'
search "$@"
;;
verify)
shift 2>/dev/null || usage 'file...'
verify "$@"