scripts

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

commit 229b7c14c83657ee2fcde73e35f8d3370effa693
parent cbaecede0900106f1e1158fa6cd638bbcf4a4390
Author: z3bra <willy@mailoo.org>
Date:   Thu May 22 20:06:30 +0200

improved youtube searcher

Diffstat:
ypl | 10----------
ys | 31+++++++++++++++++++++++++++++--
2 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/ypl b/ypl @@ -1,10 +0,0 @@ -#!/bin/sh -# See the LICENSE file for copyright and license details. - -MCMD="mplayer %u" -if [ -z "$CACA_DRIVER" -a -z "$DISPLAY" ]; -then - export CACA_DRIVER=ncurses - MCMD="mplayer -vo caca %u" -fi -quvi --exec "$MCMD" "$1" diff --git a/ys b/ys @@ -3,9 +3,36 @@ # z3bra - (c) wtfpl 2014 # perform a search on youtube and return the best result (title + link) +usage() { + echo "`basename $0` [-htu] [-n <num>] <query>" + + test -z "$1" && return + + cat <<EOF + -h : display this help + -t : output titles only (default 'title - uri') + -u : output uris only + -n : print only <num> results (default: 3) +EOF +} + num=3 +regex='^.*title="\([^"]*\)".*href="\(/watch[^"]*\)".*$' +output='\1 - http://youtube.com\2' + +while getopts "hn:tu" OPT; do + case $OPT in + n) num=$OPTARG;; + t) output='\1';; + u) output='http://youtube.com\2';; + h) usage long; exit 0;; + *) usage; exit 1;; + esac +done + +shift $((OPTIND - 1)) + query=$(echo $@ | tr ' ' '+') url="http://www.youtube.com/results?search_query=${query}" -regex='s,^.*title="\([^"]*\)".*href="\(/watch[^"]*\)".*$,\1 - http://youtube.com\2,p' -curl -s "$url" | sed -n "$regex" | sed ${num}q +curl -s "$url" | sed -n "s,$regex,$output,p" | sed ${num}q