-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.sh
executable file
·83 lines (73 loc) · 2.24 KB
/
process.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
#!/bin/bash
# WMFO Lyrics Flagger
# WMFO - Tufts Freeform Radio
# Version 2.0
# Copyright 2010, 2011 Ben Yu, Andy Sayler, Phil Tang
# Distributed under the terms of the GNU General Public License
# Including additional terms as listed in file TERMS
#
# process.sh - main program script
#
# Please maintain attribution/contribution list where praticle
#
# ---Contributors---
# Ben Yu
# Andy Sayler
# Phil Tang
#
# ---File History---
# 10/16/11 - Place under git VCS and added to github repo
#
mysql_result=`mysql -u <user> <schema> <<< "SELECT NUMBER,ARTIST,TITLE,ALBUM FROM CART WHERE SCHED_CODES IS NULL"`
mysql_result=`echo "$mysql_result" | sed 's/\t/\n/g'`
let c=0
while read number
do
read artist
read title
read album
#Display the name for debugging
echo -e "\n$artist\n$title\n$album"
#Urlencode artist, title, and album. Then send the request.
artist=`echo -n "$artist" | ./urlencode`
title=`echo -n "$title" | ./urlencode`
album=`echo -n "$album" | ./urlencode`
lookup="http://lyrics.wikia.com/api.php?artist=$artist&song=$title&fmt=xml"
#Strip out the response and the url.
xml_response=`wget -o /dev/null -O - "$lookup"`
xml_response=`echo -n "$xml_response" | tr '\n' ' '`
lyrics=`echo "$xml_response" | grep -o "<lyrics>.*</lyrics>"`
lyrics=`echo -n "$lyrics" | sed -e 's/<lyrics>//g' -e 's/<\/lyrics>//g'`
let lyrics_b=$?
url=`echo -n "$xml_response" | grep -o "<url>.*</url>" | sed -e 's/<url>//g' -e 's/<\/url>//g' -e 's/amp;//g'`
if [ $lyrics_b -eq 1 ]
then
echo "Closing down due to failure to find lyric tag."
exit
fi
if [ "$lyrics" = "Not found" ]
then
echo "No lyrics found for this song."
query="UPDATE CART SET SCHED_CODES='U .' WHERE NUMBER='$number'"
else
content=`wget -o /dev/null -O - "$url" | grep -o "</a></div>.*<!--" |sed -f html_decode.sed`
echo -n "$content" | egrep -o -f filter.regex
if [ $? -eq 0 ]
then
echo "This song is explicit!"
query="UPDATE CART SET SCHED_CODES='E .' WHERE NUMBER='$number'"
else
echo "This song is safe for play."
query="UPDATE CART SET SCHED_CODES='S .' WHERE NUMBER='$number'"
fi
fi
if [ $c -ne 0 ]
then
mysql -u <user> <schema> <<< "$query"
else
let c=1
fi
done <<< "$mysql_result"