aboutsummaryrefslogtreecommitdiff
path: root/.config/eww/scripts/music_info
blob: efa3a24a631341c7957337da6c3480a377eaf408 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# scripts by adi1090x

## Get data
STATUS="$(mpc status)"
COVER="/tmp/.music_cover.png"
MUSIC_DIR="$HOME/music/playlist-1"

## Get status
get_status() {
    if [[ $STATUS == *"[playing]"* ]]; then
        echo ""
    else
        echo "奈"
    fi
}

## Get song
get_song() {
    song=$(mpc -f %title% current)
    if [[ -z "$song" ]]; then
        echo "Offline"
    else
        echo "$song"
    fi
}

## Get artist
get_artist() {
    artist=$(mpc -f %artist% current)
    if [[ -z "$artist" ]]; then
        echo ""
    else
        echo "$artist"
    fi
}

## Get time
get_time() {
    time=$(mpc status | grep "%)" | awk '{print $4}' | tr -d '(%)')
    if [[ -z "$time" ]]; then
        echo "0"
    else
        echo "$time"
    fi
}
get_ctime() {
    ctime=$(mpc status | grep "#" | awk '{print $3}' | sed 's|/.*||g')
    if [[ -z "$ctime" ]]; then
        echo "0:00"
    else
        echo "$ctime"
    fi
}
get_ttime() {
    ttime=$(mpc -f %time% current)
    if [[ -z "$ttime" ]]; then
        echo "0:00"
    else
        echo "$ttime"
    fi
}

## Get cover
get_cover() {
    ffmpeg -i "${MUSIC_DIR}/$(mpc current -f %file%)" "$COVER" -y &>/dev/null
    STATUS=$?

    # Check if the file has a embbeded album art
    if [ "$STATUS" -eq 0 ]; then
        echo "$COVER"
    else
        echo "images/music.png"
    fi
}

## Execute accordingly
if [[ "$1" == "--song" ]]; then
    get_song
elif [[ "$1" == "--artist" ]]; then
    get_artist
elif [[ "$1" == "--status" ]]; then
    get_status
elif [[ "$1" == "--time" ]]; then
    get_time
elif [[ "$1" == "--ctime" ]]; then
    get_ctime
elif [[ "$1" == "--ttime" ]]; then
    get_ttime
elif [[ "$1" == "--cover" ]]; then
    get_cover
elif [[ "$1" == "--toggle" ]]; then
    mpc -q toggle
elif [[ "$1" == "--next" ]]; then
    {
        mpc -q next
        get_cover
    }
elif [[ "$1" == "--prev" ]]; then
    {
        mpc -q prev
        get_cover
    }
fi