scripts

various script and utils
git clone git://z3bra.org/scripts
Log | Files | Refs

commit dd6615f0fd58247658098d0c66917f0d40a579f2
parent 229b7c14c83657ee2fcde73e35f8d3370effa693
Author: z3bra <willy@mailoo.org>
Date:   Mon May 26 12:01:12 +0200

Download and extract an audio track from youtube using search terms

Diffstat:
ydl | 35+++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+), 0 deletions(-)
diff --git a/ydl b/ydl @@ -0,0 +1,35 @@ +#!/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=$(~/bin/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