49 lines
956 B
Bash
Executable File
49 lines
956 B
Bash
Executable File
#!/bin/sh
|
|
########################################
|
|
# name: wyrics
|
|
# desc: fetch lyrics from lyrics.ovh
|
|
# main: Jaidyn Ann
|
|
# <jadedctrl@teknik.io>
|
|
# lisc: CC 0
|
|
########################################
|
|
|
|
# return lyrics for given query, if available
|
|
function search {
|
|
local artist="$(sanitize "$1")"
|
|
local song="$(sanitize "$2")"
|
|
|
|
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'
|
|
}
|
|
|
|
# sanitize search strings
|
|
function sanitize {
|
|
local str="$1"
|
|
|
|
if echo "$str" | grep ',the' >/dev/null; then
|
|
str="the%2A$(echo "$str" | sed 's%,the%%')"
|
|
fi
|
|
|
|
echo "$str" \
|
|
| sed 's/ /%2A/g' \
|
|
| sed 's/_/%2A/g'
|
|
}
|
|
|
|
# --------------------------------------
|
|
|
|
# print usage and abort
|
|
function usage {
|
|
echo "usage: wyrics artist title"
|
|
exit 2
|
|
}
|
|
|
|
ARTIST="$1"
|
|
SONG="$2"
|
|
if test -z "$ARTIST" -o -z "$SONG"; then usage; fi
|
|
|
|
search "$ARTIST" "$SONG"
|