diff options
Diffstat (limited to 'X11/eww/scripts/music_info')
-rwxr-xr-x | X11/eww/scripts/music_info | 97 |
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 | ||
4 | STATUS="$(mpc status)" | ||
5 | COVER="/tmp/.music_cover.jpg" | ||
6 | MUSIC_DIR="$HOME/Music" | ||
7 | |||
8 | ## Get status | ||
9 | get_status() { | ||
10 | if [[ $STATUS == *"[playing]"* ]]; then | ||
11 | echo "" | ||
12 | else | ||
13 | echo "喇" | ||
14 | fi | ||
15 | } | ||
16 | |||
17 | ## Get song | ||
18 | get_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 | ||
28 | get_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 | ||
38 | get_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 | } | ||
46 | get_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 | } | ||
54 | get_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 | ||
64 | get_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 | ||
77 | if [[ "$1" == "--song" ]]; then | ||
78 | get_song | ||
79 | elif [[ "$1" == "--artist" ]]; then | ||
80 | get_artist | ||
81 | elif [[ "$1" == "--status" ]]; then | ||
82 | get_status | ||
83 | elif [[ "$1" == "--time" ]]; then | ||
84 | get_time | ||
85 | elif [[ "$1" == "--ctime" ]]; then | ||
86 | get_ctime | ||
87 | elif [[ "$1" == "--ttime" ]]; then | ||
88 | get_ttime | ||
89 | elif [[ "$1" == "--cover" ]]; then | ||
90 | get_cover | ||
91 | elif [[ "$1" == "--toggle" ]]; then | ||
92 | mpc -q toggle | ||
93 | elif [[ "$1" == "--next" ]]; then | ||
94 | { mpc -q next; get_cover; } | ||
95 | elif [[ "$1" == "--prev" ]]; then | ||
96 | { mpc -q prev; get_cover; } | ||
97 | fi | ||