tys - scripts - various script and utils
(HTM) git clone git://z3bra.org/scripts
(DIR) Log
(DIR) Files
(DIR) Refs
---
tys (878B)
---
1 #!/bin/sh
2 #
3 # z3bra - (c) wtfpl 2014
4 # perform a search on youtube and return the best result (title + link)
5
6 usage() {
7 echo "`basename $0` [-htu] [-n <num>] <query>"
8
9 test -z "$1" && return
10
11 cat <<EOF
12 -h : display this help
13 -t : output titles only (default 'title - uri')
14 -u : output uris only
15 -n : print only <num> results (default: 3)
16 EOF
17 }
18
19 num=3
20 regex='^.*<a href="\(/watch[^"]*\)"[^>]*>\([^<]*\)</a>.*$'
21 output='\2 - http://youtube.com\1'
22
23 while getopts "hn:tu" OPT; do
24 case $OPT in
25 n) num=$OPTARG;;
26 t) output='\2';;
27 u) output='http://youtube.com\1';;
28 h) usage long; exit 0;;
29 *) usage; exit 1;;
30 esac
31 done
32
33 shift $((OPTIND - 1))
34
35 query=$(echo $@ | tr ' ' '+')
36 url="https://www.youtube.com/results?search_query=${query}"
37
38 curl -s "$url" | sed -n "s,$regex,$output,p" | sed ${num}q