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