-
Notifications
You must be signed in to change notification settings - Fork 0
/
searcher.sh
executable file
·86 lines (75 loc) · 1.64 KB
/
searcher.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# Search Google Videos for the search term and times specified below:
# Separate muliple search terms with + i.e.: 'albert+einstein'
SEARCH_LONG='y'
SEARCH_MED='y'
SEARCH_SHORT='n'
while getopts lms OPT; do
case $OPT in
+l)
SEARCH_LONG=y
;;
l)
SEARCH_LONG=n
;;
+m)
SEARCH_MED=y
;;
m)
SEARCH_MED=n
;;
+s)
SEARCH_SHORT=y
;;
s)
SEARCH_SHORT=n
;;
*)
echo "usage: `basename $0` [+-lms] [--] ARGS..."
exit 2
esac
done
shift `expr $OPTIND - 1`
OPTIND=1
if [ $# -lt 1 ]; then
echo "At least one search term is required"
exit 2
fi
searching () {
rm -f "$BASENAME$2"
for i in `seq 0 10 990 `; do
curl --silent -A "AT, Bitches" "http://www.google.com/search?q=$2+site:video.google.com&hl=en&safe=off&tbs=dur:$1&tbm=vid&start=$i&sa=N" | grep -o "docid=[0-9-]*" | tee -a "$BASENAME$2"
done
}
search () {
SEARCH=`echo "$@" | tr ' ' '+'`
echo "Searching for term '$SEARCH'..."
# Select which lengths of video you want
##
# Subsequently return all the videos in one, sorted, deduped list of ID's
#
BASENAME='seed_videos_'
OUTNAME='_dedupe'
NAME=$BASENAME$SEARCH
OUT=$NAME$OUTNAME
if [ $SEARCH_LONG = 'y' ]; then
searching "l" "$SEARCH"
fi
if [ $SEARCH_MED = 'y' ]; then
searching "m" "$SEARCH"
fi
if [ $SEARCH_SHORT = 'y' ]; then
searching "s" "$SEARCH"
fi
sort -u $NAME | tee $OUT
SEARCHCOUNT=$(cat $OUT | wc -l)
echo "Search term '$SEARCH' returned $SEARCHCOUNT deduped results."
}
rest=$*
if [ ${rest:0:1} == "@" ]; then
cat ${rest:1} | while read terms; do
search $terms
done
else
search $rest
fi