1
1
mirror of https://github.com/jarun/nnn.git synced 2024-09-17 15:57:17 +03:00
nnn/plugins/moclyrics

41 lines
1.0 KiB
Plaintext
Raw Normal View History

2019-08-15 02:43:35 +03:00
#!/usr/bin/env sh
2019-08-15 08:36:41 +03:00
# Description: Fetches the lyrics of the track currently playing in MOC
2021-05-15 20:32:01 +03:00
#
2020-05-06 08:29:57 +03:00
# Dependencies: ddgr (https://github.com/jarun/ddgr)
2019-08-15 02:43:35 +03: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 23:44:25 +03:00
if ! [ "$state" = 'PLAY' ]; then
2019-08-15 02:43:35 +03: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 17:39:14 +03:00
if [ -n "$ARTIST" ] && [ -n "$TITLE" ]; then
2019-08-15 02:43:35 +03: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 17:39:14 +03:00
if [ -n "$FILENAME" ]; then
2019-08-15 02:43:35 +03:00
ddgr -w azlyrics.com --ducky "$FILENAME"
fi
fi