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