| 1 |
#!/usr/bin/env sh |
| 2 |
|
| 3 |
# Description: Fetches the lyrics of the track currently playing in MOC |
| 4 |
# |
| 5 |
# Dependencies: ddgr (https://github.com/jarun/ddgr) |
| 6 |
# |
| 7 |
# Shell: POSIX compliant |
| 8 |
# Author: Arun Prakash Jana |
| 9 |
|
| 10 |
# Check if MOC server is running |
| 11 |
cmd=$(pgrep -x mocp 2>/dev/null) |
| 12 |
ret=$cmd |
| 13 |
if [ -z "$ret" ]; then |
| 14 |
exit |
| 15 |
fi |
| 16 |
|
| 17 |
# Grab the output |
| 18 |
out="$(mocp -i)" |
| 19 |
|
| 20 |
# Check if anything is playing |
| 21 |
state=$(echo "$out" | grep "State:" | cut -d' ' -f2) |
| 22 |
if ! [ "$state" = 'PLAY' ]; then |
| 23 |
exit |
| 24 |
fi |
| 25 |
|
| 26 |
# Try by Artist and Song Title first |
| 27 |
ARTIST="$(echo "$out" | grep 'Artist:' | cut -d':' -f2 | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')" |
| 28 |
TITLE="$(echo "$out" | grep 'SongTitle:' | cut -d':' -f2 | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')" |
| 29 |
|
| 30 |
if [ -n "$ARTIST" ] && [ -n "$TITLE" ]; then |
| 31 |
ddgr -w azlyrics.com --ducky "$ARTIST" "$TITLE" |
| 32 |
else |
| 33 |
# Try by file name |
| 34 |
FILENAME="$(basename "$(echo "$out" | grep 'File:' | cut -d':' -f2)")" |
| 35 |
FILENAME="$(echo "${FILENAME%%.*}" | tr -d -)" |
| 36 |
|
| 37 |
if [ -n "$FILENAME" ]; then |
| 38 |
ddgr -w azlyrics.com --ducky "$FILENAME" |
| 39 |
fi |
| 40 |
fi |