executable_yt 574 B

12345678910111213141516171819202122232425262728
  1. #!/bin/sh
  2. #
  3. # http://github.com/mitchweaver/bin
  4. #
  5. # search for and/or play youtube videos with mpv
  6. #
  7. # shellcheck disable=2086
  8. #
  9. case ${1#-} in
  10. h)
  11. >&2 echo "Usage: ${0##*/} [-s] [-m] [search terms]"
  12. exit 1
  13. ;;
  14. s)
  15. shift
  16. exec youtube-dl -e --default-search ytsearch8 \
  17. -- "$(printf '%s\n' "$*" | tr ' ' '+')"
  18. ;;
  19. m)
  20. shift
  21. MPV_OPTS="$MPV_OPTS"
  22. esac
  23. exec mpv $MPV_OPTS --no-loop \
  24. --script-opts=ytdl_hook-try_ytdl_first=yes \
  25. -- ytdl://ytsearch:"$(printf '%s\n' "$*" | tr ' ' '+')"