-
Notifications
You must be signed in to change notification settings - Fork 0
/
change_state_song.sh
executable file
·88 lines (87 loc) · 2.09 KB
/
change_state_song.sh
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
#!/bin/bash
lyrdir="$HOME/.lyrics"
check_dir(){
if ! [ -d "$lyrdir" ];then
echo "'$lyrdir' doesn't exists"
exit 1
fi
}
ch(){
check_dir
i=0
IFS=$'\n'
filename="${lyrdir}/$(mpc current).txt"
if [ -f "$filename" ];then
lstart=$(($(grep -n Tracklist "${filename}" | cut -f1 -d:)+1))
lend=$(($(grep -n Endtr "${filename}" | cut -f1 -d:)))
for line in $(sed -n -e "${lstart},${lend}p" "${filename}");do
if [ "$line" == "Endtr" ];then
mpc next
fi
timec=$(mpc status | sed -n -e '2p' | awk '{gsub(/\/.*/,"",$3);print $3}')
mc=$(echo $timec | awk -F':' '{print $(NF-1)}')
sc=$(echo $timec | awk -F':' '{print $(NF-0)}')
timef=$(echo $line | awk -F'=' '{gsub(/[ \t]+$/, "", $1);print $1}')
title=$(echo $line | awk -F'=' '{gsub(/[ \t]+$/, "", $2);print $2}')
#echo $mc $sc
#echo $timef
#echo $lasttc
mf=$(echo $timef | awk -F: '{s=$NF;m=$(NF-1);if($(NF-2) != $0)m+=($(NF-2)*60);print m}')
sf=$(echo $timef | awk -F: '{s=$NF;m=$(NF-1);if($(NF-2) != $0)m+=($(NF-2)*60);print s}')
echo $mf $sf
mc=$((10#$mc))
sc=$((10#$sc))
mf=$((10#$mf))
sf=$((10#$sf))
if [[ $mc -lt $mf ]];then
if [ "$1" == "prev" ];then
echo seek ${lasttc[i-2]}
if [ "${lasttc[i-2]}" == "00:00" ];then
mpc prev
else
mpc seek ${lasttc[i-2]}
fi
songstate_change_notif " - ${lasttt[i-2]}"
elif [ "$1" == "next" ];then
echo seek $timef
#length=$(mpc status | sed -n -e '2p' | awk '{gsub(/.*\//,"",$3);print $3}')
#if [ "$timef" == "$length" ];then
# mpc next
#else
# mpc seek $timef
#fi
mpc seek $timef
songstate_change_notif " - $title"
fi
return 0
fi
lasttc[i]=$timef #time start, for prev
lasttt[i]=$title #time start, for prev
let i++
done
else
dunstify -t 3000 -u LOW -r 3 -p -a change_stage_song.sh "no lyrics file"
fi
}
cur=$(mpc current)
if [[ "$cur" =~ "[Full OST]"$ ]];then
case $1 in
next)
ch next
echo next
if [ $? -ne 0 ];then
mpc next
fi
;;
prev)
ch prev
if [ $? -ne 0 ];then
mpc prev
fi
echo prev
;;
*)mpc $@;;
esac
else
mpc $@
fi