You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ydl 810B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/sh
  2. #
  3. # z3bra - (c) wtfpl 2014
  4. # download the audio track of the first result of a youtube search
  5. # and add it to MPD library (will end up with a .mp3, for tags)
  6. # Require : ys (youtube search)
  7. MPD_DOWNLOAD_DIR=~/usr/msc/youtube/
  8. usage() {
  9. echo "`basename $0` [-h] <query>"
  10. }
  11. # don't process if no argument given
  12. test $# -eq 0 && usage && exit 1
  13. # you can either pass MULTIPLE search terms or a SINGLE url
  14. test $# -gt 1 && uri=$(ys -n1 -u $@) || uri=$1
  15. # give up if we got no uri
  16. if test -z "$uri"; then
  17. echo "no result found"
  18. exit 1
  19. fi
  20. # change to target dir if it exists
  21. test -d $MPD_DOWNLOAD_DIR && cd $MPD_DOWNLOAD_DIR
  22. # download and extract audio track
  23. youtube-dl -q -x -o '%(title)s.%(ext)s' "$uri"
  24. # update mpd lib if running
  25. pgrep mpd >/dev/null 2>&1&& mpc -q update
  26. exit 0