aboutsummaryrefslogtreecommitdiffhomepage
path: root/X11/eww/scripts/music_info
diff options
context:
space:
mode:
Diffstat (limited to 'X11/eww/scripts/music_info')
-rwxr-xr-xX11/eww/scripts/music_info97
1 files changed, 97 insertions, 0 deletions
diff --git a/X11/eww/scripts/music_info b/X11/eww/scripts/music_info
new file mode 100755
index 0000000..e5a7283
--- /dev/null
+++ b/X11/eww/scripts/music_info
@@ -0,0 +1,97 @@
1#!/bin/bash
2
3## Get data
4STATUS="$(mpc status)"
5COVER="/tmp/.music_cover.jpg"
6MUSIC_DIR="$HOME/Music"
7
8## Get status
9get_status() {
10 if [[ $STATUS == *"[playing]"* ]]; then
11 echo ""
12 else
13 echo "喇"
14 fi
15}
16
17## Get song
18get_song() {
19 song=`mpc -f %title% current`
20 if [[ -z "$song" ]]; then
21 echo "Offline"
22 else
23 echo "$song"
24 fi
25}
26
27## Get artist
28get_artist() {
29 artist=`mpc -f %artist% current`
30 if [[ -z "$artist" ]]; then
31 echo "Offline"
32 else
33 echo "$artist"
34 fi
35}
36
37## Get time
38get_time() {
39 time=`mpc status | grep "%)" | awk '{print $4}' | tr -d '(%)'`
40 if [[ -z "$time" ]]; then
41 echo "0"
42 else
43 echo "$time"
44 fi
45}
46get_ctime() {
47 ctime=`mpc status | grep "#" | awk '{print $3}' | sed 's|/.*||g'`
48 if [[ -z "$ctime" ]]; then
49 echo "0:00"
50 else
51 echo "$ctime"
52 fi
53}
54get_ttime() {
55 ttime=`mpc -f %time% current`
56 if [[ -z "$ttime" ]]; then
57 echo "0:00"
58 else
59 echo "$ttime"
60 fi
61}
62
63## Get cover
64get_cover() {
65 ffmpeg -i "${MUSIC_DIR}/$(mpc current -f %file%)" "${COVER}" -y &> /dev/null
66 STATUS=$?
67
68 # Check if the file has a embbeded album art
69 if [ "$STATUS" -eq 0 ];then
70 echo "$COVER"
71 else
72 echo "images/music.png"
73 fi
74}
75
76## Execute accordingly
77if [[ "$1" == "--song" ]]; then
78 get_song
79elif [[ "$1" == "--artist" ]]; then
80 get_artist
81elif [[ "$1" == "--status" ]]; then
82 get_status
83elif [[ "$1" == "--time" ]]; then
84 get_time
85elif [[ "$1" == "--ctime" ]]; then
86 get_ctime
87elif [[ "$1" == "--ttime" ]]; then
88 get_ttime
89elif [[ "$1" == "--cover" ]]; then
90 get_cover
91elif [[ "$1" == "--toggle" ]]; then
92 mpc -q toggle
93elif [[ "$1" == "--next" ]]; then
94 { mpc -q next; get_cover; }
95elif [[ "$1" == "--prev" ]]; then
96 { mpc -q prev; get_cover; }
97fi