-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeech
executable file
·158 lines (125 loc) · 5.63 KB
/
speech
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env bash
## By Davoud Arsalani
## https://github.com/davoudarsalani/scripts
## https://github.com/davoudarsalani/scripts/blob/master/speech
## https://raw.githubusercontent.com/davoudarsalani/scripts/master/speech
## https://davoudarsalani.ir
source "$HOME"/main/scripts/gb
source "$HOME"/main/scripts/gb-audacious
function update_audacious {
"$HOME"/main/scripts/awesome-widgets audacious
}
function if_empty { ## JUMP_1 the same used in "$HOME"/main/scripts/movie
local count
read count directory <<< "$directory" ## 8 pargar
## check if count is an int
[ "$count" -eq "$count" ] || {
msgc 'ERROR' "<span color=\"${orange}\">${count}</span> is invalid count" "$HOME"/main/linux/themes/alert-w.png
exit
}
(( count > 0 )) || {
msgn 'nothing here'
exit
}
}
function if_no_dir { ## JUMP_1
[ -d "$HOME"/main/speech/"$directory" ] || {
msgc 'ERROR' "no such directory as <span color=\"${orange}\">\$HOME/main/speech/${directory}</span>" "$HOME"/main/linux/themes/alert-w.png
exit
}
}
function success_moving {
local text
text="$(printf "moved to <span color=\"%s\">LISTENED</span>\n<span color=\"%s\">%s</span>\n" "$blue" "$orange" "$no_suffix")"
msgn "$text" '' "$HOME"/main/linux/themes/delete-w.png
}
function error_moving {
msgc 'ERROR' "moving <span color=\"${orange}\">${no_suffix}</span>" "$HOME"/main/linux/themes/alert-w.png
exit
}
declare -a directories_plus_count
readarray -t directories < <(find "$HOME"/main/speech -mindepth 1 -maxdepth 1 -type d | sort)
## get audio count in each directory and prepend it to the directory name
for tmp_directory in "${directories[@]}"; {
audios_count="$(wc -l < <(find "$tmp_directory" -mindepth 1 -maxdepth 1 -type f -iname '*.mp3'))"
## decide how many spaces to add
if (( audios_count < 10 )); then
spaces=' '
elif (( audios_count < 100 )); then
spaces=' '
elif (( audios_count < 1000 )); then
spaces=' '
else
spaces=' '
fi
directories_plus_count+=( "${audios_count}${spaces}${tmp_directory##*/}" )
}
case "$1" in
play )
directory="$(pipe_to_rofi "${directories_plus_count[@]}" 'header=speech')" || exit 37 ## '8 pargar'
if_empty ## NOTE JUMP_2 if_empty must precede if_no_dir (i.e. JUMP_3)
if_no_dir ## JUMP_3
turn_off_shuffle; sleep 0.1
clear_playlist ; sleep 0.1
msgn 'playing' "<span color=\"${orange}\">${directory}</span>" "$HOME"/main/linux/themes/user-w.png
readarray -t first_five_files < <(find "$HOME"/main/speech/"$directory" -mindepth 1 -maxdepth 1 -iname '*.mp3' | sort | head -n 5)
audacious -E "${first_five_files[@]}" # &
sleep 0.1
"$HOME"/main/scripts/awesome-widgets audacious resume ;;
move )
if [ "$2" == 'auto' ]; then
## NOTE the auto option is called directly by audacious when starting a new song
[ "$album" == 'speech' ] || exit ## NOTE do NOT combine with the parent condition
directory="${current_song_dir##*/}" ## pargar
else
directory="$(pipe_to_rofi "${directories_plus_count[@]}" 'header=speech' 'bg=red')" || exit 37
if_empty ## NOTE JUMP_2 if_empty must precede if_no_dir (i.e. JUMP_4)
fi
if_no_dir ## JUMP_4
first_file="$(find "$HOME"/main/speech/"$directory" -mindepth 1 -maxdepth 1 -iname '*.mp3' | sort | head -n 1)" ## /home/nnnn/main/speech/pargar/709.mp3
first_kaddy_file="$(get_kaddy_counterpart "$first_file")" ## /home/nnnn/kaddy/speech/pargar/709.mp3
base="${first_file##*/}"
no_suffix="${base%.*}"
## exit if first file is the same as the current song
[ "$current_song" == "$first_file" ] && exit
listened_dir="$HOME"/main/speech/"$directory"/LISTENED
listened_kaddy_dir="$(get_kaddy_counterpart "$listened_dir")"
[ -d "$listened_dir" ] || mkdir "$listened_dir"
[ -d "$listened_kaddy_dir" ] || mkdir "$listened_kaddy_dir"
mv "$first_file" "$listened_dir" && success_moving || error_moving
mv "$first_kaddy_file" "$listened_kaddy_dir" || error_moving
## trigger add_4 only if current playing file is the last file in playlist
if (( playlist_length == position_in_playlist )); then
"$HOME"/main/scripts/speech add_4
else
update_audacious
fi ;;
add_4 )
if [ ! "$album" ] || [ "$album" == 'speech' ]; then
## remove previous files from playlist
if (( position_in_playlist == 1 )); then
:
elif (( position_in_playlist > 1 )); then
for ((i=1; i<"$position_in_playlist"; i++)); {
audtool --playlist-delete 1
sleep 0.01
}
elif [ ! "$position_in_playlist" ]; then
clear_playlist
"$HOME"/main/scripts/speech play &
exit
fi
## add 4 new files to playlist
readarray -t first_five_files < <(find "$current_song_dir" -mindepth 1 -maxdepth 1 -iname '*.mp3' | sort | head -n 5)
current_songs="$(audtool --playlist-display)"
for file in "${first_five_files[@]}"; {
base="${file##*/}"
no_suffix="${base%.*}"
if ! \grep -qi "$no_suffix" <<< "$current_songs"; then
audacious -e "$file"
msgn "added <span color=\"${orange}\">${no_suffix}</span>"
fi
}
update_audacious
fi ;;
esac