diff --git a/yt b/yt index 7a49dfe..fd23dee 100755 --- a/yt +++ b/yt @@ -30,6 +30,18 @@ test -n "$YT_PL_DIR" \ test -d "$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 P="$(printf '%s\n' "$YT_PL_DIR" | sed 's;\/;\\/;g')" @@ -133,20 +145,13 @@ lines() { 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)" - test -z "$choices" || pick "$choices" } 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 dir="$playlist" @@ -174,12 +179,6 @@ new() { pick() { # Pick a video to play from a playlist of videos 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 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 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 "$@" & "$PLAYER" "$@" } @@ -223,12 +216,6 @@ play() { # play a video after caching its title queue() { test -z "$1" && usage 'queue playlist...' - 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 - while test -f "$YT_PL_DIR/$1.m3u"; do "$PLAYER" "$YT_PL_DIR/$1.m3u" shift @@ -238,12 +225,6 @@ queue() { search() { test -z "$1" && usage 'search term [count]' - 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")" cache "$(printf '%s\n' "$results" | sed -e 's/.*\[//g' -e 's/\]/ /g' \ @@ -274,15 +255,8 @@ search() { fi } -searchlocal() { - test -n "$1" && usage 'searchlocal' - - 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 - +localsearch() { + test -n "$1" && usage 'localsearch' $YTPICK <"$cachefile" }