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 816ccff0484bd77b398692ab72b467b7b992827f
parent 5e928019f1c219d4db8b17918fe9254c27b65796
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed, 15 Jan 2020 12:03:25 +0100

Simplify script

Diffstat:
M.local/bin/lyrics | 36++++++++++--------------------------
1 file changed, 10 insertions(+), 26 deletions(-)

diff --git a/.local/bin/lyrics b/.local/bin/lyrics @@ -33,20 +33,16 @@ die() exit 1 } -string_to_artist_and_song() -{ - artist="${1% - *}" - song="$(echo "$1" | sed 's/.* - //')" - if [ "$artist" = "$song" ]; then - die 'no artist specified' - fi -} - fetch_lyrics_lyricwiki() { local _a, _s, _qanswer - _a="$(echo "$1" | sed 's/ /_/g')" - _s="$(echo "$2" | sed 's/ /_/g')" + _a="$(echo "$1" | sed 's/ - .*//;s/ /_/g')" + _s="$(echo "$1" | sed 's/.* - //;s/ /_/g')" + if [ -z "$_a" ]; then + die 'artist name not specified' + elif [ -z "$_s" ]; then + die 'song title not specified' + fi _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' @@ -62,15 +58,6 @@ fetch_lyrics_lyricwiki() $fetcher "$_url" | grep "class='lyricbox'" | w3m -dump -T text/html } -fetch_lyrics() -{ - if [ "$backend" = "lyricwiki" ]; then - fetch_lyrics_lyricwiki "$1" "$2" - else - die "unknown backend: $backend" - fi -} - if command -v hurl >/dev/null 2>&1; then fetcher=hurl elif command -v curl >/dev/null 2>&1; then @@ -81,7 +68,6 @@ fi verbose=0 mpd=0 -backend="lyricwiki" while :; do case "$1" in -h|-\?|--help) @@ -112,13 +98,11 @@ while :; do done if [ "$mpd" = 1 ]; then - string_to_artist_and_song "$(mpc | head -1)" + fetch_lyrics_lyricwiki "$(mpc | head -1)" else if [ $# -lt 1 ]; then - string_to_artist_and_song "$(cat)" + fetch_lyrics_lyricwiki "$(cat)" else - string_to_artist_and_song "$*" + fetch_lyrics_lyricwiki "$*" fi fi - -fetch_lyrics "$artist" "$song"