This commit is contained in:
Emma Tebibyte 2023-12-12 22:23:59 -07:00
parent 7797c47195
commit 70127c6918
Signed by: emma
GPG Key ID: 06FA419A1698C270

58
yt
View File

@ -30,6 +30,18 @@ test -n "$YT_PL_DIR" \
test -d "$YT_PL_DIR" \ test -d "$YT_PL_DIR" \
|| mkdir -p "$YT_PL_DIR" || mkdir -p "$YT_PL_DIR"
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
if test -z "$PLAYER"; then
printf "%s: Please set \$PLAYER to your preferred video player." \
"$argv0" 1>&2
exit 78 # sysexits.h(3) EX_CONFIG
fi
# formatted $YT_PL_DIR for use with sed # formatted $YT_PL_DIR for use with sed
P="$(printf '%s\n' "$YT_PL_DIR" | sed 's;\/;\\/;g')" P="$(printf '%s\n' "$YT_PL_DIR" | sed 's;\/;\\/;g')"
@ -133,20 +145,13 @@ lines() {
list() { list() {
test -n "$1" && usage 'list' test -n "$1" && usage 'list'
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
choices="$(menu)" choices="$(menu)"
test -z "$choices" || pick "$choices" test -z "$choices" || pick "$choices"
} }
menu() { menu() {
playlist="$(ls "$YT_PL_DIR" | sed 's/\.m3u//g' | sed -n '/[^.old]/p' | $YTPICK)" playlist="$(ls "$YT_PL_DIR" | sed 's/\.m3u//g' | sed -n '/[^.old]/p' \
| $YTPICK)"
while test -d "$YT_PL_DIR/$playlist"; do while test -d "$YT_PL_DIR/$playlist"; do
dir="$playlist" dir="$playlist"
@ -174,12 +179,6 @@ new() {
pick() { # Pick a video to play from a playlist of videos pick() { # Pick a video to play from a playlist of videos
test -z "$1" && usage 'pick playlist...' test -z "$1" && usage 'pick playlist...'
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
if test -f "$YT_PL_DIR/$1.m3u"; then if test -f "$YT_PL_DIR/$1.m3u"; then
file="$YT_PL_DIR/$1.m3u" file="$YT_PL_DIR/$1.m3u"
@ -210,12 +209,6 @@ pick() { # Pick a video to play from a playlist of videos
play() { # play a video after caching its title play() { # play a video after caching its title
test -z "$1" && usage 'play uri...' test -z "$1" && usage 'play uri...'
if test -z "$PLAYER"; then
printf "%s: Please set \$PLAYER to your preferred video player." \
"$argv0" 1>&2
exit 78 # sysexits.h(3) EX_CONFIG
fi
cache "$@" & cache "$@" &
"$PLAYER" "$@" "$PLAYER" "$@"
} }