fixed pick + formatting

This commit is contained in:
Emma Tebibyte 2023-11-21 22:38:23 -07:00
parent b18ff53a8e
commit f237ab7e1e
Signed by: emma
GPG Key ID: 6D661C738815E7DD

15
yt
View File

@ -38,8 +38,8 @@ add() { # adds a video to a playlist file
while test -f "$YT_PL_DIR/$2.m3u"; do while test -f "$YT_PL_DIR/$2.m3u"; do
file="$YT_PL_DIR/$2.m3u" file="$YT_PL_DIR/$2.m3u"
video="$(printf '%s\n' "$1" \ video="$(printf '%s\n' "$1" \
| sed -e 's/youtu\.be\//www.youtube\.com\/watch?v=/g' -e 's/\?[^v].*$//g')" | sed -e 's/youtu\.be\//www.youtube\.com\/watch?v=/g' \
printf '%s\n' "$video" -e 's/\?[^v].*$//g')"
if test -n "$(grep -e "$video" "$file")" if test -n "$(grep -e "$video" "$file")"
then then
@ -161,11 +161,14 @@ pick() { # Pick a video to play from a playlist of videos
list="$(printf '%s\n%s' "$list" "$(grep "$line" "$cachefile")")" list="$(printf '%s\n%s' "$list" "$(grep "$line" "$cachefile")")"
fi fi
done done
fi
chosen="$(printf '%s\n' "$list" | $YTPICK | sed -e 's/.*\[//g' -e 's/\]//g')" chosen="$(printf '%s\n' "$list" \
printf "%s: %s: Playing stream.\n" "$argv0" "$chosen" 1>&2 | $YTPICK | sed -e 's/.*\[//g' -e 's/\]//g')"
test -n "$chosen" && mpv "$chosen"
test -z "$chosen" \
|| printf "%s: %s: Playing stream.\n" "$argv0" "$chosen" 1>&2 \
&& mpv "$chosen"
fi
} }
play() { # play a video after caching its title play() { # play a video after caching its title