nnn/plugins/moclyrics

41 lines
1 KiB
Plaintext
Raw Normal View History

2019-08-14 23:43:35 +00:00
#!/usr/bin/env sh
2019-08-15 05:36:41 +00:00
# Description: Fetches the lyrics of the track currently playing in MOC
2021-05-15 17:32:01 +00:00
#
2020-05-06 05:29:57 +00:00
# Dependencies: ddgr (https://github.com/jarun/ddgr)
2019-08-14 23:43:35 +00:00
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana
# Check if MOC server is running
cmd=$(pgrep -x mocp 2>/dev/null)
ret=$cmd
if [ -z "$ret" ]; then
exit
fi
# Grab the output
out="$(mocp -i)"
# Check if anything is playing
state=$(echo "$out" | grep "State:" | cut -d' ' -f2)
2019-11-21 20:44:25 +00:00
if ! [ "$state" = 'PLAY' ]; then
2019-08-14 23:43:35 +00:00
exit
fi
# Try by Artist and Song Title first
ARTIST="$(echo "$out" | grep 'Artist:' | cut -d':' -f2 | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')"
TITLE="$(echo "$out" | grep 'SongTitle:' | cut -d':' -f2 | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')"
2020-11-22 14:39:14 +00:00
if [ -n "$ARTIST" ] && [ -n "$TITLE" ]; then
2019-08-14 23:43:35 +00:00
ddgr -w azlyrics.com --ducky "$ARTIST" "$TITLE"
else
# Try by file name
FILENAME="$(basename "$(echo "$out" | grep 'File:' | cut -d':' -f2)")"
FILENAME="$(echo "${FILENAME%%.*}" | tr -d -)"
2020-11-22 14:39:14 +00:00
if [ -n "$FILENAME" ]; then
2019-08-14 23:43:35 +00:00
ddgr -w azlyrics.com --ducky "$FILENAME"
fi
fi