Browse code

Switch from wikia to songlyrics.com

Jaidyn Levesque authored on 2019-12-09 18:29:17
Showing 2 changed files
... ...
@@ -2,9 +2,11 @@
2 2
 WYRICS                                                          Git some lyrics
3 3
 ===============================================================================
4 4
 
5
-Fetch lyrics for a song from lyrics.fandom.com with this script.
5
+Fetch lyrics for a song from songlyrics.com with this script.
6 6
 You can fetch them by search queries, or by their URL.
7 7
 
8
+This used to use lyrics.wikia.com, but that's defunct now. ;c
9
+
8 10
 
9 11
 
10 12
 ----------------------------------------
... ...
@@ -2,7 +2,7 @@
2 2
 ########################################
3 3
 # name: wyrics
4 4
 # desc: fetch lyrics by URL or query
5
-#       from lyrics.fandom.com
5
+#       from songlyrics.com
6 6
 # main: Jaidyn Ann
7 7
 #       <jadedctrl@teknik.io>
8 8
 # lisc: CC 0
... ...
@@ -71,9 +71,10 @@ function search {
71 71
 	local query="$1"
72 72
 	local query="$(echo "$query" | sed 's/ /+/g')"
73 73
 
74
-	gendl "https://lyrics.fandom.com/wiki/Special:Search?query=${query}" \
75
-	| sed '1,/Results/d' \
76
-	| grep "result-link" \
74
+	gendl "https://songlyrics.com/index.php?section=search&searchW=${query}" \
75
+	| sed '1,/serpresult/d' \
76
+	| grep "title=" \
77
+	| grep -v "<h3" \
77 78
 	| search_parse
78 79
 }
79 80
 
... ...
@@ -90,10 +91,10 @@ function search_parse {
90 91
 		i=$(add $i 1)
91 92
 		local url="$(echo "$line" \
92 93
 				| sed 's/.*href=\"//' \
93
-				| sed 's/\" class.*//')"
94
+				| sed 's/\".*//')"
94 95
 		local title="$(echo "$line" \
95
-				| sed 's%.*">%%' \
96
-				| sed 's%</a>%%')"
96
+				| sed 's%.*title="%%' \
97
+				| sed 's%".*%%')"
97 98
 
98 99
 		if echo "$title" | grep "http" > /dev/null; then
99 100
 			i=$(subtract $i 1)
... ...
@@ -181,15 +182,23 @@ function result_choose {
181 182
 
182 183
 # --------------------------------------
183 184
 
185
+function blank_lines {
186
+	local html="$(reade)"
187
+
188
+	echo "$html" \
189
+	| sed 's%^<br />%<p></p>%' \
190
+	| sed 's%^<br/>%<p></p>%' 
191
+}
192
+
184 193
 # STRING --> STRING
185 194
 # return the lyrics of a given URL
186 195
 function lyrics {
187 196
 	local url="$1"
188 197
 
189 198
 	gendl "$url" \
190
-	| grep "class=\'lyricbox" \
191
-	| sed 's/.*lyricbox.>//' \
192
-	| sed 's/;<div.*//' \
199
+	| sed '1,/iComment-text">/d' \
200
+	| sed '/<\/div>/,$d' \
201
+	| blank_lines \
193 202
 	| lynx -stdin -dump \
194 203
 	| sed 's/^   //g'
195 204
 }
... ...
@@ -221,8 +230,8 @@ case "$1" in
221 230
 
222 231
 		lyrics "$url"
223 232
 		;;
224
-#	*)
225
-#		usage
226
-#		;;
233
+# #	*)
234
+# #		usage
235
+# #		;;
227 236
 
228 237
 esac