tMerge branch 'master' of z3bra.org:scripts - scripts - various script and utils
(HTM) git clone git://z3bra.org/scripts
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) commit a1b619a5eae6d74857195606015ad0636747144c
(DIR) parent 476ec4b15877a3bd7c7bbcc6ff667ab74e859058
(HTM) Author: z3bra <willy@mailoo.org>
Date: Wed, 9 Jul 2014 22:49:32 +0200
Merge branch 'master' of z3bra.org:scripts
Diffstat:
A ydl | 35 +++++++++++++++++++++++++++++++
M ys | 8 ++++----
2 files changed, 39 insertions(+), 4 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=$(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
(DIR) diff --git a/ys b/ys
t@@ -17,14 +17,14 @@ EOF
}
num=3
-regex='^.*title="\([^"]*\)".*href="\(/watch[^"]*\)".*$'
-output='\1 - http://youtube.com\2'
+regex='^.*<a href="\(/watch[^"]*\)"[^>]*>\([^<]*\)</a>.*$'
+output='\2 - http://youtube.com\1'
while getopts "hn:tu" OPT; do
case $OPT in
n) num=$OPTARG;;
- t) output='\1';;
- u) output='http://youtube.com\2';;
+ t) output='\2';;
+ u) output='http://youtube.com\1';;
h) usage long; exit 0;;
*) usage; exit 1;;
esac