tDownload and extract an audio track from youtube using search terms - scripts - various script and utils
(HTM) git clone git://z3bra.org/scripts
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) commit dd6615f0fd58247658098d0c66917f0d40a579f2
(DIR) parent 229b7c14c83657ee2fcde73e35f8d3370effa693
(HTM) Author: z3bra <willy@mailoo.org>
Date: Mon, 26 May 2014 12:01:12 +0200
Download and extract an audio track from youtube using search terms
Diffstat:
A ydl | 35 +++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/ydl b/ydl
t@@ -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