diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2019-08-15 05:13:35 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2019-08-15 09:15:03 +0530 |
commit | 4ab13b1b349e7ebac9d393660a06f4050eaf4a68 (patch) | |
tree | 81e69227d4f1f413de1ff1813f70d5f19b263be9 /plugins/moclyrics | |
parent | 8fff4643f50d37d90a1e7efde32d80436aa8e00a (diff) | |
download | nnn-4ab13b1b349e7ebac9d393660a06f4050eaf4a68.tar.gz |
Plugin moclyrics
Diffstat (limited to 'plugins/moclyrics')
-rwxr-xr-x | plugins/moclyrics | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/plugins/moclyrics b/plugins/moclyrics new file mode 100755 index 0000000..36bf785 --- /dev/null +++ b/plugins/moclyrics @@ -0,0 +1,39 @@ +#!/usr/bin/env sh + +# Description: Fetches the lyrics of the currently playing track in MOC +# Requires ddgr (https://github.com/jarun/ddgr) +# +# 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) +if ! [ $state = 'PLAY' ]; then + 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:]]*$//')" + +if ! [ -z "$ARTIST" ] && ! [ -z "$TITLE" ]; then + 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 -)" + + if ! [ -z "$FILENAME" ]; then + ddgr -w azlyrics.com --ducky "$FILENAME" + fi +fi |