wyrics/wyrics

49 lines
956 B
Plaintext
Raw Normal View History

2019-01-20 23:41:10 -06:00
#!/bin/sh
########################################
# name: wyrics
2020-12-25 22:29:09 -06:00
# desc: fetch lyrics from lyrics.ovh
2019-12-09 11:48:22 -06:00
# main: Jaidyn Ann
2024-01-29 13:42:43 -06:00
# <jadedctrl@posteo.at>
2019-01-20 23:41:10 -06:00
# lisc: CC 0
########################################
2020-12-25 22:29:09 -06:00
# return lyrics for given query, if available
2019-01-20 23:41:10 -06:00
function search {
2020-12-25 22:29:09 -06:00
local artist="$(sanitize "$1")"
local song="$(sanitize "$2")"
2019-01-20 23:41:10 -06:00
2020-12-25 22:29:09 -06:00
curl -Ls "https://api.lyrics.ovh/v1/${artist}/${song}" \
| sed 's%^{"lyrics":"%%' \
| sed 's%"}$%%' \
| sed 's%\\n\\n%\n%g' \
| sed 's%\\n%\n%g'
# | sed 's%\\r%%g'
2019-01-20 23:41:10 -06:00
}
2020-12-25 22:29:09 -06:00
# sanitize search strings
function sanitize {
2021-01-30 21:05:49 -06:00
local str="$1"
2019-01-20 23:41:10 -06:00
2021-01-30 21:05:49 -06:00
if echo "$str" | grep ',the' >/dev/null; then
str="the%2A$(echo "$str" | sed 's%,the%%')"
2020-12-25 22:29:09 -06:00
fi
2019-01-20 23:41:10 -06:00
2021-01-30 21:05:49 -06:00
echo "$str" \
| sed 's/ /%2A/g' \
| sed 's/_/%2A/g'
2019-01-20 23:41:10 -06:00
}
# --------------------------------------
# print usage and abort
function usage {
2020-12-25 22:29:09 -06:00
echo "usage: wyrics artist title"
2019-01-20 23:41:10 -06:00
exit 2
}
2020-12-25 22:29:09 -06:00
ARTIST="$1"
SONG="$2"
if test -z "$ARTIST" -o -z "$SONG"; then usage; fi
2019-01-20 23:41:10 -06:00
2020-12-25 22:29:09 -06:00
search "$ARTIST" "$SONG"