@@ -68,39 +68,42 @@ function show_help() {
68
68
}
69
69
70
70
function download_sound() {
71
- printf " $DEFAULT_COLOR "
71
+ printf -- " $DEFAULT_COLOR "
72
72
printf " Preparing music for video $ID_COLOR $1 \n"
73
73
74
74
if [[ -f " $DOWNLOAD_DIR /$1 " ]]; then
75
- printf " $DEFAULT_COLOR \tUsing cached $ID_COLOR $1 $DEFAULT_COLOR \n"
75
+ printf -- " $DEFAULT_COLOR \tUsing cached $ID_COLOR $1 $DEFAULT_COLOR \n"
76
+ if [[ -f " $DOWNLOAD_DIR /$1 .invalid" ]]; then
77
+ rm -- " $DOWNLOAD_DIR /$1 .invalid"
78
+ fi
76
79
return 0
77
80
elif [[ -f " $DOWNLOAD_DIR /$1 .invalid" ]]; then
78
- printf " $ERROR_COLOR \tError: $ID_COLOR $1 $DEFAULT_COLOR has been marked as invalid.\n" >&2
81
+ printf -- " $ERROR_COLOR \tError: $ID_COLOR $1 $DEFAULT_COLOR has been marked as invalid.\n" >&2
79
82
printf " \tTo try to redownload, delete the file $ID_COLOR$DOWNLOAD_DIR /$1 .invalid$DEFAULT_COLOR \n" >&2
80
83
return 1
81
84
fi
82
85
printf " \t$ID_COLOR $1 $DEFAULT_COLOR is not present in cache. Downloading it.\n"
83
86
84
87
local audio_formats=$( youtube-dl --no-warnings -F -- " $1 " | grep " audio only" 2> /dev/null)
85
- local format_count=$( echo " $audio_formats " | wc -l)
88
+ local format_count=$( printf -- " $audio_formats " | wc -l)
86
89
87
90
if [[ $format_count -gt 1 ]]; then
88
- local audio_formats_2=$( echo " $audio_formats " | grep -v " worst" )
89
- local format_count=$( echo " $audio_formats " | wc -l)
91
+ local audio_formats_2=$( printf -- " $audio_formats " | grep -v " worst" )
92
+ local format_count=$( printf -- " $audio_formats " | wc -l)
90
93
91
94
if [[ $format_count -ge 1 ]]; then
92
95
local audio_formats=" $audio_formats_2 "
93
- local audio_formats_2=$( echo " $audio_formats " | grep " m4a" )
94
- local format_count=$( echo " $audio_formats " | wc -l)
96
+ local audio_formats_2=$( printf -- " $audio_formats " | grep " m4a" )
97
+ local format_count=$( printf -- " $audio_formats " | wc -l)
95
98
96
99
if [[ $format_count -ge 1 ]]; then
97
100
local audio_formats=" $audio_formats_2 "
98
101
fi
99
102
fi
100
103
fi
101
104
102
- local format=$( echo " $audio_formats " | head -n1 | cut -d ' ' -f 1)
103
- local extension=$( echo " $audio_formats " | head -n1 | sed ' s/[0-9]\+ \+//' | cut -d ' ' -f 1)
105
+ local format=$( printf -- " $audio_formats " | head -n1 | cut -d ' ' -f 1)
106
+ local extension=$( printf -- " $audio_formats " | head -n1 | sed ' s/[0-9]\+ \+//' | cut -d ' ' -f 1)
104
107
105
108
youtube-dl --no-warnings -q -f $format --add-metadata -o " $DOWNLOAD_DIR /$1 .$extension " -- " $1 " > /dev/null 2> /dev/null
106
109
@@ -110,24 +113,24 @@ function download_sound() {
110
113
if [[ $NORMALIZE == " true" ]]; then
111
114
printf " \t$ID_COLOR $1 $DEFAULT_COLOR : normalizing.\n"
112
115
local file_info=$( ffmpeg -y -i " $DOWNLOAD_DIR /$1 .$extension " -pass 1 -filter:a loudnorm=print_format=json -f null - 2>&1 )
113
- local lra=$( echo $file_info | grep " input_lra" | sed ' s/.*"input_lra" : "\(-\?[0-9]*\.[0-9]*\)".*/\1/' )
114
- local tp=$( echo $file_info | grep " input_tp" | sed ' s/.*"input_tp" : "\(-\?[0-9]*\.[0-9]*\)".*/\1/' )
115
- local thresh=$( echo $file_info | grep " input_thresh" | sed ' s/.*"input_thresh" : "\(-\?[0-9]*\.[0-9]*\)".*/\1/' )
116
- local i=$( echo $file_info | grep " input_i" | sed ' s/.*"input_i" : "\(-\?[0-9]*\.[0-9]*\)".*/\1/' )
116
+ local lra=$( printf -- " $file_info " | grep " input_lra" | sed ' s/.*"input_lra" : "\(-\?[0-9]*\.[0-9]*\)".*/\1/' )
117
+ local tp=$( printf -- " $file_info " | grep " input_tp" | sed ' s/.*"input_tp" : "\(-\?[0-9]*\.[0-9]*\)".*/\1/' )
118
+ local thresh=$( printf -- " $file_info " | grep " input_thresh" | sed ' s/.*"input_thresh" : "\(-\?[0-9]*\.[0-9]*\)".*/\1/' )
119
+ local i=$( printf -- " $file_info " | grep " input_i" | sed ' s/.*"input_i" : "\(-\?[0-9]*\.[0-9]*\)".*/\1/' )
117
120
118
121
yes | ffmpeg -loglevel panic -i " $DOWNLOAD_DIR /$1 .$extension " -pass 2 -filter:a dynaudnorm=f=1000,loudnorm=linear=true:measured_I=$i :measured_LRA=$lra :measured_tp=$tp :measured_thresh=$thresh " $DOWNLOAD_DIR /$1 .norm.$extension "
119
122
120
- rm " $DOWNLOAD_DIR /$1 .$extension " 2> /dev/null
121
- mv " $DOWNLOAD_DIR /$1 .norm.$extension " " $DOWNLOAD_DIR /$1 " 2> /dev/null
123
+ rm -- " $DOWNLOAD_DIR /$1 .$extension " 2> /dev/null
124
+ mv -- " $DOWNLOAD_DIR /$1 .norm.$extension " " $DOWNLOAD_DIR /$1 " 2> /dev/null
122
125
else
123
- mv " $DOWNLOAD_DIR /$1 .$extension " " $DOWNLOAD_DIR /$1 "
126
+ mv -- " $DOWNLOAD_DIR /$1 .$extension " " $DOWNLOAD_DIR /$1 "
124
127
fi
125
- printf " $ID_COLOR $1 $DEFAULT_COLOR : ready.\n"
128
+ printf -- " $ID_COLOR $1 $DEFAULT_COLOR : ready.\n"
126
129
127
130
return 0
128
131
else
129
132
130
- printf " $ERROR_COLOR \tError$DEFAULT_COLOR downloading $ID_COLOR $1 $DEFAULT_COLOR .\n" >&2
133
+ printf -- " $ERROR_COLOR \tError$DEFAULT_COLOR downloading $ID_COLOR $1 $DEFAULT_COLOR .\n" >&2
131
134
touch " $DOWNLOAD_DIR /$1 .invalid"
132
135
return 1
133
136
fi
@@ -149,7 +152,7 @@ function readable_size() {
149
152
let " size = size / 1024"
150
153
suffix=" Gio"
151
154
fi
152
- printf " $size $suffix "
155
+ printf -- " $size $suffix "
153
156
}
154
157
155
158
function readable_time() {
@@ -164,71 +167,71 @@ function readable_time() {
164
167
let " hours = hours - 24 * days"
165
168
166
169
if [[ $days -gt 0 ]]; then
167
- printf " $days "
170
+ printf -- " $days "
168
171
printf " d "
169
172
fi
170
173
171
174
if [[ $hours -lt 10 ]]; then
172
175
printf " 0$hours :"
173
176
else
174
- printf " $hours :"
177
+ printf -- " $hours :"
175
178
fi
176
179
177
180
if [[ $minutes -lt 10 ]]; then
178
181
printf " 0$minutes '"
179
182
else
180
- printf " $minutes '"
183
+ printf -- " $minutes '"
181
184
fi
182
185
183
186
if [[ $seconds -eq 0 ]]; then
184
187
printf " 00"
185
188
elif [[ $seconds -lt 10 ]]; then
186
189
printf " 0$seconds "
187
190
else
188
- printf " $seconds "
191
+ printf -- " $seconds "
189
192
fi
190
193
}
191
194
192
195
function skip_sig() {
193
- printf " $REQUEST_COLOR "
196
+ printf -- " $REQUEST_COLOR "
194
197
printf " Received: next. ASAP Master\n"
195
- printf " $DEFAULT_COLOR "
198
+ printf -- " $DEFAULT_COLOR "
196
199
SKIP=" true"
197
200
PREV=" false"
198
201
}
199
202
200
203
function prev_sig() {
201
- printf " $REQUEST_COLOR "
204
+ printf -- " $REQUEST_COLOR "
202
205
printf " Received: prev. ASAP Master\n"
203
- printf " $DEFAULT_COLOR "
206
+ printf -- " $DEFAULT_COLOR "
204
207
PREV=" true"
205
208
SKIP=" false"
206
209
}
207
210
208
211
function bye_sig() {
209
- printf " $REQUEST_COLOR "
212
+ printf -- " $REQUEST_COLOR "
210
213
printf " Received: quit. Good bye\n"
211
- printf " $DEFAULT_COLOR "
214
+ printf -- " $DEFAULT_COLOR "
212
215
213
- rm " $PID_FILE "
216
+ rm -- " $PID_FILE "
214
217
if [[ -f " $TEMPORARY_FILE " ]]; then
215
- rm " $TEMPORARY_FILE "
218
+ rm -- " $TEMPORARY_FILE "
216
219
fi
217
220
218
221
if [[ $CACHING == " false" ]]; then
219
- rm " $DOWNLOAD_DIR /$id " 2> /dev/null
220
- rm " $DOWNLOAD_DIR /$current_id " 2> /dev/null
222
+ rm -- " $DOWNLOAD_DIR /$id " 2> /dev/null
223
+ rm -- " $DOWNLOAD_DIR /$current_id " 2> /dev/null
221
224
fi
222
225
223
- rm " $DOWNLOAD_DIR /" * .* 2> /dev/null
226
+ rm -- " $DOWNLOAD_DIR /" * .* 2> /dev/null
224
227
stop_player
225
228
exit
226
229
}
227
230
228
231
function play_sig() {
229
- printf " $REQUEST_COLOR "
232
+ printf -- " $REQUEST_COLOR "
230
233
printf " Received: play\n"
231
- printf " $DEFAULT_COLOR "
234
+ printf -- " $DEFAULT_COLOR "
232
235
233
236
if [[ $STATE == " pause" ]]; then
234
237
STATE_CHANGED=" true"
@@ -253,9 +256,9 @@ function toggle_sig() {
253
256
}
254
257
255
258
function pause_sig() {
256
- printf " $REQUEST_COLOR "
259
+ printf -- " $REQUEST_COLOR "
257
260
printf " Received: pause\n"
258
- printf " $DEFAULT_COLOR "
261
+ printf -- " $DEFAULT_COLOR "
259
262
260
263
if [[ $STATE == " play" ]]; then
261
264
STATE_CHANGED=" true"
@@ -283,16 +286,16 @@ function show_cache() {
283
286
printf " Cache folder: $DOWNLOAD_DIR \n"
284
287
printf " File list:\n"
285
288
for i in $( ls " $DOWNLOAD_DIR " ) ; do
286
- if [[ $( echo $i | cut -d ' .' -f 2) == " invalid" ]]; then
287
- printf " $ID_COLOR $( echo $i | cut -d ' .' -f 1) $ERROR_COLOR \tVideo is unavailable\n"
289
+ if [[ $( printf -- " $i " | cut -d ' .' -f 2) == " invalid" ]]; then
290
+ printf -- " $ID_COLOR $( printf -- " $i " | cut -d ' .' -f 1) $ERROR_COLOR \tVideo is unavailable\n"
288
291
let " invalid_count++"
289
292
290
- elif [[ $( echo $i | cut -d ' .' -f 2) == " $i " ]]; then
293
+ elif [[ $( printf -- " $i " | cut -d ' .' -f 2) == " $i " ]]; then
291
294
local dur_title=$( ffprobe -i $DOWNLOAD_DIR /$i -v quiet -print_format json -show_format | jq -r ' .format.duration,.format.tags.title' )
292
- local title=$( echo $dur_title | cut -d ' ' -f 2- )
293
- local this_duration=$( echo $dur_title | cut -d ' .' -f 1)
295
+ local title=$( printf -- " $dur_title " | tail -n 1 )
296
+ local this_duration=$( printf -- " $dur_title " | head -n 1 | cut -d ' .' -f 1)
294
297
295
- printf " $ID_COLOR$i \t$TITLE_COLOR$title \n"
298
+ printf -- " $ID_COLOR$i \t$TITLE_COLOR$title \n"
296
299
297
300
duration=$(( $duration + $this_duration ))
298
301
if [[ $this_duration -gt $longest ]]; then
@@ -310,19 +313,19 @@ function show_cache() {
310
313
let " valid_count++"
311
314
fi
312
315
done
313
- printf " $DEFAULT_COLOR "
316
+ printf -- " $DEFAULT_COLOR "
314
317
printf " \nValid tracks: $valid_count "
315
318
printf " \nBad tracks: $invalid_count "
316
319
printf " \nTotal cache size: "
317
320
readable_size $size
318
321
printf " \nTotal duration: "
319
322
readable_time $duration
320
- printf " \nHeaviest file: $ID_COLOR $heaviest_id$DEFAULT_COLOR - $TITLE_COLOR $( ffprobe -i $DOWNLOAD_DIR /$heaviest_id -show_format -v quiet | grep TAG:title | cut -d ' = ' -f 2 ) "
321
- printf " $DEFAULT_COLOR ["
323
+ printf " \nHeaviest file: $ID_COLOR $heaviest_id$DEFAULT_COLOR - $TITLE_COLOR $( ffprobe -i $DOWNLOAD_DIR /$heaviest_id -show_format -v quiet -print_format json | jq -r ' .format.tags.title ' ) "
324
+ printf -- " $DEFAULT_COLOR ["
322
325
readable_size $heaviest
323
326
printf " ]"
324
- printf " \nLongest music: $ID_COLOR $longest_id$DEFAULT_COLOR - $TITLE_COLOR $( ffprobe -i $DOWNLOAD_DIR /$heaviest_id -show_format -v quiet | grep TAG:title | cut -d ' = ' -f 2 ) "
325
- printf " $DEFAULT_COLOR ["
327
+ printf " \nLongest music: $ID_COLOR $longest_id$DEFAULT_COLOR - $TITLE_COLOR $( ffprobe -i $DOWNLOAD_DIR /$longest_id -show_format -v quiet -print_format json | jq -r ' .format.tags.title ' ) "
328
+ printf -- " $DEFAULT_COLOR ["
326
329
readable_time $longest
327
330
printf " ]\n"
328
331
}
@@ -333,7 +336,7 @@ function search_cache() {
333
336
local matching=0
334
337
local total=0
335
338
for i in $( ls " $DOWNLOAD_DIR " ) ; do
336
- if [[ $( echo $i | cut -d ' .' -f 2) == " $i " ]]; then
339
+ if [[ $( printf -- " $i " | cut -d ' .' -f 2) == " $i " ]]; then
337
340
let " total++"
338
341
local title=$( ffprobe -i $DOWNLOAD_DIR /$i -v quiet -print_format json -show_format | jq -r ' .format.tags.title' )
339
342
if [[ $title =~ $1 ]]; then
@@ -350,7 +353,7 @@ function search_cache() {
350
353
}
351
354
352
355
function init() {
353
- COMMAND=$( echo $0 | sed ' s/.*\/\(.*\)/\1/' )
356
+ COMMAND=$( printf -- " $0 " | sed ' s/.*\/\(.*\)/\1/' )
354
357
355
358
ID_COLOR=" \e[38;5;14m"
356
359
ERROR_COLOR=" \e[38;5;9m"
@@ -553,7 +556,7 @@ function parse_args() {
553
556
exit 0
554
557
;;
555
558
* )
556
- printf " $COMMAND : $1 : Unknow field.\nTry $COMMAND --help.\n" >&2
559
+ printf -- " $COMMAND : $1 : Unknow field.\nTry $COMMAND --help.\n" >&2
557
560
exit 1
558
561
esac
559
562
@@ -566,7 +569,7 @@ function start_up() {
566
569
567
570
if [[ -f " $PID_FILE " ]]; then
568
571
if [[ $( ps -ef | grep $( cat $PID_FILE ) | grep ymph | wc -l) -eq 0 && $( ps -ef | grep $( cat $PID_FILE ) | grep $COMMAND | wc -l) -eq 0 ]]; then
569
- printf " $ERROR_COLOR " >&2
572
+ printf -- " $ERROR_COLOR " >&2
570
573
printf " Error:$DEFAULT_COLOR ymph seems to have died, but didn't clean up after him.\n" >&2
571
574
printf " If that is the case, delete the file $PID_FILE \n"
572
575
exit 3
@@ -601,12 +604,12 @@ function start_up() {
601
604
fi
602
605
603
606
if [[ ! -f " $PLAYLIST_FILE " ]]; then
604
- printf " $ERROR_COLOR " >&2
607
+ printf -- " $ERROR_COLOR " >&2
605
608
printf " Error:$DEFAULT_COLOR Failed to open playlist file.\n" >&2
606
609
exit 3
607
610
fi
608
611
if [[ $( wc -l " $PLAYLIST_FILE " | cut -d ' ' -f 1) -eq 0 ]]; then
609
- printf " $ERROR_COLOR " >&2
612
+ printf -- " $ERROR_COLOR " >&2
610
613
printf " Error:$DEFAULT_COLOR the playlist is empty!\n" >&2
611
614
exit 3
612
615
fi
@@ -659,7 +662,7 @@ function try_sleep() {
659
662
660
663
function main_loop() {
661
664
start_player
662
- echo " $$ " > " $PID_FILE "
665
+ printf " $$ " > " $PID_FILE "
663
666
664
667
COUNT=0
665
668
AHEAD_COUNT=$(( $AHEAD_LOADING - 1 ))
@@ -694,7 +697,7 @@ function main_loop() {
694
697
fi
695
698
current_id=" $ID "
696
699
697
- printf " $ID_COLOR "
700
+ printf -- " $ID_COLOR "
698
701
printf " Now playing $TITLE_COLOR $( ffprobe -i $DOWNLOAD_DIR /$current_id -show_format -v quiet | grep TAG:title | cut -d ' =' -f 2) $DEFAULT_COLOR [$ID_COLOR$current_id$DEFAULT_COLOR ]\n"
699
702
700
703
while [[ $STATE == " pause" && $SKIP == " false" ]]; do
@@ -801,7 +804,7 @@ function main_loop() {
801
804
802
805
function check_dependency() {
803
806
printf " \t\t$1 :"
804
- for i in $( seq $( echo $1 | wc -c) 10) ; do
807
+ for i in $( seq $( printf -- " $1 " | wc -c) 10) ; do
805
808
printf " "
806
809
done
807
810
@@ -818,7 +821,6 @@ function check_dependencies() {
818
821
check_dependency cat
819
822
check_dependency cut
820
823
check_dependency date
821
- check_dependency echo
822
824
check_dependency head
823
825
check_dependency mkdir
824
826
check_dependency mv
0 commit comments