Init
This commit is contained in:
commit
ab87df6086
|
@ -0,0 +1,32 @@
|
||||||
|
===============================================================================
|
||||||
|
AZLYRICS-FETCH
|
||||||
|
===============================================================================
|
||||||
|
|
||||||
|
Fetch lyrics from azlyrics.com.
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
PRE-REQUISITES
|
||||||
|
----------------------------------------
|
||||||
|
* curl
|
||||||
|
* lynx
|
||||||
|
* a shell
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
USAGE
|
||||||
|
----------------------------------------
|
||||||
|
AZLYRICS
|
||||||
|
--------------------
|
||||||
|
You can get the lyrics of a specific song with
|
||||||
|
|
||||||
|
azlyrics.sh https://www.azlyrics.com/lyrics/$ARTIST/$SONG.html
|
||||||
|
|
||||||
|
You can get a list of all song URLs of an artist with:
|
||||||
|
|
||||||
|
azlyrics.sh https://www.azlyrics.com/$A/$ARTIST.*.html
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
BORING STUFF
|
||||||
|
----------------------------------------
|
||||||
|
License is CC-0
|
||||||
|
Author is Jaidyn Ann <jadedctrl@teknik.io>
|
||||||
|
Sauce is at https://git.feneas.org/detruota/azlyrics-fetch.git
|
|
@ -0,0 +1,80 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# --------------------------------------
|
||||||
|
# name: azlyric.sh
|
||||||
|
# lisc: CC0
|
||||||
|
# date: 2020
|
||||||
|
# desc: fetches lyrics from artist/song
|
||||||
|
# azlyrics URL
|
||||||
|
# --------------------------------------
|
||||||
|
|
||||||
|
USER_AGENT="Mozilla/5.0 (Linux; Android 8.1.0) AppleWebKit/537.36 (KHTML, like"
|
||||||
|
USER_AGENT="${USER_AGENT} Gecko) Chrome/67.0.3396.68 Mobile Safari/537.36"
|
||||||
|
|
||||||
|
function fetch {
|
||||||
|
local url="$1"
|
||||||
|
curl -s --user-agent "$USER_AGENT" "$url"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ======================================
|
||||||
|
# ARTIST
|
||||||
|
# ======================================
|
||||||
|
function is_artist_url {
|
||||||
|
local url="$1"
|
||||||
|
test -n "$(echo "$url" | awk -F '/' '{print $5}')" \
|
||||||
|
-a -z "$(echo "$url" | awk -F '/' '{print $6}')"
|
||||||
|
return "$?"
|
||||||
|
}
|
||||||
|
|
||||||
|
function artist_song_urls {
|
||||||
|
grep "../lyrics/" \
|
||||||
|
| sed 's%.*href="..%%' \
|
||||||
|
| sed 's%".*%%' \
|
||||||
|
| sed 's%^%https://www.azlyrics.com%'
|
||||||
|
}
|
||||||
|
|
||||||
|
# ======================================
|
||||||
|
# SONG
|
||||||
|
# ======================================
|
||||||
|
function is_song_url {
|
||||||
|
local url="$1"
|
||||||
|
test -n "$(echo "$url" | awk -F '/' '{print $6}')"
|
||||||
|
return "$?"
|
||||||
|
}
|
||||||
|
|
||||||
|
function song_lyrics {
|
||||||
|
sed '1,/Sorry about that/d' \
|
||||||
|
| sed '1,/<\/div>/!d' \
|
||||||
|
| sed 's%<br>%%' \
|
||||||
|
| sed 's%<.*>%%' \
|
||||||
|
| awk 'BEGIN { print "<pre>" } END { print "</pre>"} {print $0}' \
|
||||||
|
| lynx -stdin -dump
|
||||||
|
}
|
||||||
|
|
||||||
|
# ======================================
|
||||||
|
# INVOCATION
|
||||||
|
# ======================================
|
||||||
|
function usage {
|
||||||
|
echo 'usage: azlyric.sh URL ... URL'
|
||||||
|
echo
|
||||||
|
echo 'If a URL is of an artist (e.g., https://www.azlyrics.com/X/X.*.html),'
|
||||||
|
echo 'then the URLs of each song page will be printed.'
|
||||||
|
echo
|
||||||
|
echo 'If a URL is of a song (e.g., https://www.azlyrics.com/lyrics/X/Y.html),'
|
||||||
|
echo 'then the lyrics will be printed.'
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
|
||||||
|
if test -z "$1"; then usage; fi
|
||||||
|
|
||||||
|
for url in $@; do
|
||||||
|
if is_artist_url "$url"; then
|
||||||
|
fetch "$url" \
|
||||||
|
| artist_song_urls
|
||||||
|
elif is_song_url "$url"; then
|
||||||
|
fetch "$url" \
|
||||||
|
| song_lyrics
|
||||||
|
else
|
||||||
|
echo "Invalid URL: $url"
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
done
|
Ŝarĝante…
Reference in New Issue