1
0
Fork 0
mirror of https://github.com/jarun/nnn.git synced 2025-02-18 23:34:37 +00:00
nnn/plugins/moclyrics

41 lines
1 KiB
Text
Raw Normal View History

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