dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 4ed7eddeb24b431b1fe28e288013d4998aba8445
parent 7274d19cb452264dbc6ccade4ed51c98df4bddbd
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed, 15 Jan 2020 11:22:09 +0100

Make artist mandatory, improve error handling

Diffstat:
M.local/bin/lyrics | 13+++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/.local/bin/lyrics b/.local/bin/lyrics @@ -4,7 +4,7 @@ version=0.1.0 show_help() { - echo "usage: ${0##*/} [OPTIONS] [[artist -] song]" + echo "usage: ${0##*/} [OPTIONS] [artist - song]" echo "fetches lyrics from lyricwiki." echo echo "OPTIONS are one or more of the following:" @@ -34,7 +34,7 @@ string_to_artist_and_song() artist="${1% - *}" song="$(echo "$1" | sed 's/.* - //')" if [ "$artist" = "$song" ]; then - artist="" + die 'no artist specified' fi } @@ -42,11 +42,16 @@ fetch_lyrics_lyricwiki() { local _a="$(echo "$1" | sed 's/ /_/g')" local _s="$(echo "$2" | sed 's/ /_/g')" - local _url="$($fetcher "https://lyrics.fandom.com/api.php?fmt=json&func=getSong&artist=${_a}&song=${_s}" | \ - grep "'url'" | sed "s/.*http:/https:/;s/'$//;s/wikia\.com/fandom.com\/wiki/" )" + local _qanswer="$($fetcher "https://lyrics.fandom.com/api.php?fmt=json&func=getSong&artist=${_a}&song=${_s}")" + if echo "$_qanswer" | grep -q "'lyrics':'Not found'"; then + die 'no lyrics found' + fi + local _url="$(echo "$_qanswer" | grep "'url'" | \ + sed "s/.*http:/https:/;s/'$//;s/wikia\.com/fandom.com\/wiki/" )" if [ "$verbose" = 1 ]; then echo "artist: $_a" echo "song: $_s" + echo "query answer: $_qanswer" echo "lyricwiki url: $_url" fi $fetcher "$_url" | grep "class='lyricbox'" | w3m -dump -T text/html