File: moclyrics

package info (click to toggle)
nnn 5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,184 kB
  • sloc: ansic: 11,902; sh: 3,585; makefile: 512; cpp: 80; python: 31; csh: 2
file content (40 lines) | stat: -rwxr-xr-x 1,064 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env sh

# Description: Fetches the lyrics of the track currently playing in MOC
#
# Dependencies: 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 [ -n "$ARTIST" ] && [ -n "$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 [ -n "$FILENAME" ]; then
        ddgr -w azlyrics.com --ducky "$FILENAME"
    fi
fi