]> Sergey Matveev's repositories - nnn.git/commitdiff
Plugin moclyrics
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 14 Aug 2019 23:43:35 +0000 (05:13 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Thu, 15 Aug 2019 03:45:03 +0000 (09:15 +0530)
plugins/README.md
plugins/moclyrics [new file with mode: 0755]

index 182e248511fd91745c88a67ebec46f0a571ad8e0..5cf6ca72da2861a987496d9ff632ca423f9ce1c2 100644 (file)
@@ -14,6 +14,7 @@ The currently available plugins are listed below.
 | imgur | bash | - | Upload an image to imgur (from [imgur-screenshot](https://github.com/jomo/imgur-screenshot)) |
 | ipinfo | sh | curl, whois | Fetch external IP address and whois information |
 | kdeconnect | sh | kdeconnect-cli | Send selected files to an Android device |
+| moclyrics | sh | [ddgr](https://github.com/jarun/ddgr), moc | Show lyrics of current track in moc |
 | mocplay | sh | [moc](http://moc.daper.net/) | Appends (and plays, see script) selection/dir/file in moc|
 | ndiff | sh | vimdiff | Diff for selection (limited to 2 for directories) |
 | nmount | sh | pmount, udisks2 | Toggle mount status of a device as normal user |
diff --git a/plugins/moclyrics b/plugins/moclyrics
new file mode 100755 (executable)
index 0000000..36bf785
--- /dev/null
@@ -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