-
Notifications
You must be signed in to change notification settings - Fork 0
/
glouglou.sh
executable file
·2312 lines (2044 loc) · 59.3 KB
/
glouglou.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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# shellcheck disable=SC2317,SC2086,SC2207
# glouglou
# Bad bash script for no brain, also play vgm in shuffle
#
# Author : Romain Barbarot
# https://github.com/Jocker666z/glouglou/
# Licence : Unlicense
# Setup
adplay_bin() {
local bin_name
local system_bin_location
bin_name="adplay"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
adplay_bin="$system_bin_location"
else
unset ext_adlib
fi
}
aplay_bin() {
local bin_name
local system_bin_location
bin_name="aplay"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
aplay_bin="$system_bin_location"
fi
}
cvlc_bin() {
local bin_name
local system_bin_location
bin_name="cvlc"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
cvlc_bin="$system_bin_location"
fi
}
ffplay_bin() {
local bin_name
local system_bin_location
bin_name="ffplay"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
ffplay_bin="$system_bin_location"
fi
}
fluidsynth_bin() {
local bin_name
local system_bin_location
bin_name="fluidsynth"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
fluidsynth_bin="$system_bin_location"
fi
}
gsf2wav_bin() {
local bin_name
local system_bin_location
bin_name="gsf2wav"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
gsf2wav_bin="$system_bin_location"
fi
}
mpv_bin() {
local bin_name
local system_bin_location
bin_name="mpv"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
mpv_bin="$system_bin_location"
fi
}
openmpt123_bin() {
local bin_name
local system_bin_location
bin_name="openmpt123"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
openmpt123_bin="$system_bin_location"
fi
}
sc68_bin() {
local bin_name
local system_bin_location
bin_name="sc68"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
sc68_bin="$system_bin_location"
else
unset ext_sc68
fi
if [[ -z "$aplay_bin" ]]; then
unset sc68_bin
fi
}
sidplayfp_bin() {
local bin_name
local system_bin_location
bin_name="sidplayfp"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
sidplayfp_bin="$system_bin_location"
fi
}
simple_mdx2wav_bin() {
local bin_name
local system_bin_location
bin_name="simple_mdx2wav"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
simple_mdx2wav_bin="$system_bin_location"
else
unset ext_simple_mdx2wav
fi
if [[ -z "$aplay_bin" ]]; then
unset ext_simple_mdx2wav
fi
}
spc2wav_bin() {
local bin_name
local system_bin_location
bin_name="spc2wav"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
spc2wav_bin="$system_bin_location"
fi
if [[ -z "$aplay_bin" ]]; then
unset spc2wav_bin
fi
}
timidity_bin() {
local bin_name
local system_bin_location
bin_name="timidity"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
timidity_bin="$system_bin_location"
fi
}
uade123_bin() {
local bin_name
local system_bin_location
bin_name="uade123"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
uade123_bin="$system_bin_location"
else
unset ext_uade
fi
}
vgmstream123_bin() {
local bin_name
local system_bin_location
bin_name="vgmstream123"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
vgmstream123_bin="$system_bin_location"
else
unset ext_vgmstream
fi
}
vgmplay_bin() {
local bin_name
local system_bin_location
bin_name="vgmplay"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
vgmplay_bin="$system_bin_location"
else
unset ext_vgmplay
fi
}
wildmidi_bin() {
local bin_name
local system_bin_location
bin_name="wildmidi"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
wildmidi_bin="$system_bin_location"
else
unset ext_wildmidi
fi
}
xmp_bin() {
local bin_name
local system_bin_location
bin_name="xmp"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
xmp_bin="$system_bin_location"
else
unset ext_xmp
fi
}
zxtune123_bin() {
local bin_name
local system_bin_location
bin_name="zxtune123"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
zxtune123_bin="$system_bin_location"
else
unset ext_zxtune
fi
}
multi_depend() {
# C64 .sid
if [[ -z "$sidplayfp_bin" ]] \
&& [[ -z "$zxtune123_bin" ]]; then
unset ext_sidplayfp
fi
# GBA
if [[ -z "$gsf2wav_bin" ]] \
&& [[ -z "$zxtune123_bin" ]]; then
unset ext_gba
fi
# Midi
if [[ -z "$timidity_bin" ]] \
&& [[ -z "$fluidsynth_bin" ]]; then
unset ext_midi
fi
# MPV
if [[ -z "$mpv_bin" ]] \
&& [[ -z "$ffplay_bin" ]]; then
unset ext_common
fi
# SNES .spc
if [[ -z "$spc2wav_bin" ]] \
&& [[ -z "$zxtune123_bin" ]] \
&& [[ -z "$mpv_bin" ]]; then
unset ext_snes
fi
# Tracker
if [[ -z "$xmp_bin" ]] \
&& [[ -z "$zxtune123_bin" ]] \
&& [[ -z "$openmpt123_bin" ]] \
&& [[ -z "$mpv_bin" ]]; then
unset ext_tracker
fi
}
glouglou_config() {
if [[ ! -d "$glouglou_config_dir" ]] \
&& [[ -w "$glouglou_config_dir" ]]; then
mkdir "$glouglou_config_dir"
elif [[ ! -d "$glouglou_config_dir" ]] \
&& [[ ! -w "/home/$USER/.config/" ]]; then
echo_error "glouglou was breaked."
echo_error "Impossible to create ${glouglou_config_dir}, not writable."
exit
fi
if [[ ! -f "$glouglou_config_file" ]] \
&& [[ -w "$glouglou_config_dir" ]]; then
echo "listenbrainz_token=" > "$glouglou_config_file"
echo "play_blacklist=" >> "$glouglou_config_file"
elif [[ ! -f "$glouglou_config_file" ]] \
&& [[ ! -w "$glouglou_config_dir" ]]; then
echo_error "glouglou was breaked."
echo_error "Impossible to create ${glouglou_config_file}, not writable."
exit
fi
}
various_bin() {
local bin_name
local system_bin_location
# curl
bin_name="curl"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
curl_bin="$system_bin_location"
fi
# info68
bin_name="info68"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
info68_bin="$system_bin_location"
fi
# ffmpeg
bin_name="ffmpeg"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
ffmpeg_bin="$system_bin_location"
fi
# fd find
bin_name="fd"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
fd_bin="$system_bin_location"
fi
if [[ -z "$fd_bin" ]]; then
bin_name="fdfind"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
fd_bin="$system_bin_location"
fi
fi
# mutagen-inspect
bin_name="mutagen-inspect"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
mutagen_inspect_bin="$system_bin_location"
fi
#ripgrep
bin_name="rg"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
rg_bin="$system_bin_location"
fi
# vgm_tag
bin_name="vgm_tag"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
vgm_tag_bin="$system_bin_location"
fi
# vgmstream-cli
bin_name="vgmstream-cli"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
vgmstream_cli_bin="$system_bin_location"
fi
# xxd
bin_name="xxd"
system_bin_location=$(command -v $bin_name)
if [[ -n "$system_bin_location" ]]; then
xxd_bin="$system_bin_location"
fi
}
# Tools
term_size() {
local term_size_raw
term_size_raw=$(stty size)
term_height="${term_size_raw%% *}"
term_width="${term_size_raw##* }"
term_width_trunc=$(( term_width - 3 ))
}
echo_truncate() {
local label
label="$1"
if [[ "${#label}" -gt "$term_width" ]]; then
echo -e "$label" | cut -c 1-"$term_width_trunc" | awk '{print $0"..."}'
else
echo -e "$label"
fi
}
echo_separator() {
tput dim
printf "%*s" "$term_width" "" | tr ' ' "-"; echo
tput sgr0
}
echo_playlist() {
local play_item
local playlist_bef_nb
local playlist_aft_nb_one
local playlist_aft_nb_two
local playlist_aft_nb_three
local lst_vgm_bef
local lst_vgm_current
local lst_vgm_aft_one
local lst_vgm_aft_two
local lst_vgm_aft_three
play_item="$1"
# Load & reload term size
term_size
# Constuct
playlist_bef_nb=$(( play_item - 1 ))
playlist_aft_nb_one=$(( play_item + 1 ))
playlist_aft_nb_two=$(( play_item + 2 ))
playlist_aft_nb_three=$(( play_item + 3 ))
lst_vgm_bef=$(echo "${lst_vgm[playlist_bef_nb]}" | rev | cut -d'/' -f-2 | rev)
lst_vgm_current=$(echo "${lst_vgm[play_item]}" | rev | cut -d'/' -f-2 | rev)
lst_vgm_aft_one=$(echo "${lst_vgm[playlist_aft_nb_one]}" | rev | cut -d'/' -f-2 | rev)
lst_vgm_aft_two=$(echo "${lst_vgm[playlist_aft_nb_two]}" | rev | cut -d'/' -f-2 | rev)
lst_vgm_aft_three=$(echo "${lst_vgm[playlist_aft_nb_three]}" | rev | cut -d'/' -f-2 | rev)
# Display
clear
tput bold sitm
echo -e " \u2261 glouglou playlist \u2933 $vgm_counter"/"${#lst_vgm[@]}"
tput sgr0 dim
echo_truncate " ${lst_vgm_bef}"
tput sgr0 bold
echo_truncate "\u25b6 ${lst_vgm_current}"
tput sgr0
echo_truncate " ${lst_vgm_aft_one}"
echo_truncate " ${lst_vgm_aft_two}"
echo_truncate " ${lst_vgm_aft_three}"
echo_separator
}
echo_error() {
local error_label
error_label="$1"
echo "${error_label}" >&2
}
start_loading() {
loading_task="$1"
loading_msg="$2"
# hide cursor
tput civis
loading "start" "${loading_task}" &
# spinner pid
_sp_pid=$!
disown
}
loading() {
local loading_delay=0.13
local loading_spinstr="▉░"
case $1 in
start)
while :
do
local loading_temp="${loading_spinstr#?}"
printf "\e[2K%s %s %s\r" "$loading_spinstr" "${loading_task}" "${loading_msg}"
local loading_spinstr="${loading_temp}${loading_spinstr%"$loading_temp"}"
sleep "$loading_delay"
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
printf "\e[2K ✓ %s %s\n" "${loading_task}" "${loading_msg}"
;;
stop)
kill "$_sp_pid" > /dev/null 2>&1
printf "\e[2K ✓ %s %s\n" "${loading_task}" "${loading_msg}"
;;
esac
}
stop_loading() {
# normal cursor
tput cnorm
loading "stop" "${loading_task}" "${loading_msg}" $_sp_pid
unset _sp_pid
unset loading_task
unset loading_msg
}
# Publish tags
publish_tags() {
local player
local file
local dir
local cover
player="$1"
file="$2"
dir=$(realpath "$(dirname "${file}")")
# Cover search
for img in "${cover_name[@]}"; do
if [[ -f "${dir}/${img}" ]]; then
cover="${dir}/${img}"
break
fi
done
# If no cover file, try to extract from file
if echo "|${ext_common}|" | grep -i "|${ext}|" &>/dev/null \
&& [[ -z "$cover" ]] \
&& [[ -n "$ffmpeg_bin" ]]; then
# Reset
if [[ -f "$glouglou_cover" ]]; then
rm "$glouglou_cover" &>/dev/null
fi
# Try to extract
"$ffmpeg_bin" -hide_banner -loglevel quiet -nostats\
-y -i "$file" \
-an -c:v copy "$glouglou_cover"
# Set if exist
if [[ -f "$glouglou_cover" ]]; then
cover="$glouglou_cover"
fi
fi
# Record
if [[ -n "$publish_tags" ]] \
&& [[ -n "$tag_title" ]]; then
{
echo "$tag_title"
echo "$tag_artist"
echo "$tag_album"
echo "$player"
echo "$cover"
echo "$tag_total_duration"
echo "$tag_system"
} > "$glouglou_tags"
fi
}
# ListenBrainz
listenbrainz_status() {
if nc -zw1 api.listenbrainz.org 443 &>/dev/null; then
listenbrainz_status="1"
fi
}
listenbrainz_token() {
local token_test
# If update token
if [[ -n "$listenbrainz_register" ]]; then
# Test token
token_test=$("$curl_bin" -s \
-X POST -H "Authorization: token $listenbrainz_register" \
https://api.listenbrainz.org/1/submit-listens \
| grep "401")
if [[ -n "$token_test" ]]; then
echo "${listenbrainz_register} is not a valid ListenBrainz token."
elif [[ -f "$glouglou_config_file" ]]; then
sed -i "s/\(listenbrainz_token *= *\).*/\1${listenbrainz_register}/" "$glouglou_config_file"
echo "${listenbrainz_register} has been registered as your new ListenBrainz token."
fi
fi
# If no update token = set current
if [[ -f "$glouglou_config_file" ]]; then
listenbrainz_token=$(< "$glouglou_config_file" grep "listenbrainz_token=" \
| awk -F"=" '{ print $2 }')
fi
}
listenbrainz_submit() {
if [[ -n "$curl_bin" ]] \
&& [[ -n "$listenbrainz_scrobb" ]] \
&& [[ -n "$listenbrainz_token" ]] \
&& [[ -n "$tag_title" ]]; then
local limit_scrobb_duration
local submit_diff_in_s
local unix_date
local player
# Prevent repeat scrobb, half total duration or limit to 10s
last_submit_time=$(date +%s)
submit_diff_in_s=$(( last_submit_time - new_submit_time ))
if [[ -n "$tag_total_duration" ]]; then
limit_scrobb_duration=$(( tag_total_duration / 2 ))
else
limit_scrobb_duration="10"
fi
if [[ "$submit_diff_in_s" -gt "$limit_scrobb_duration" ]]; then
new_submit_time=$(date +%s)
player="$1"
unix_date=$(date +%s)
# clean tag
tag_artist="${tag_artist//\"/\'}"
tag_title="${tag_title//\"/\'}"
tag_album="${tag_album//\"/\'}"
tag_brainz_artist_id=$(printf '"%s"\n' ${tag_brainz_artist_id// \/ / } \
| paste -sd, -)
"$curl_bin" --silent --output /dev/null \
-X POST -H "Authorization: token $listenbrainz_token" \
--header "Content-Type:application/json" \
-d '{
"listen_type": "single",
"payload": [{
"listened_at": "'"$unix_date"'",
"track_metadata": {
"additional_info": {
"media_player": "'"$player"'",
"submission_client": "glouglou",
"release_mbid": "'"$tag_brainz_album_id"'",
"artist_mbids": ['"$tag_brainz_artist_id"'],
"recording_mbid": "'"$tag_brainz_recording_id"'",
"release_group_mbid": "'"$tag_brainz_releasegroupid_id"'",
"track_mbid": "'"$tag_brainz_track_id"'",
"tags": []
},
"artist_name": "'"$tag_artist"'",
"track_name": "'"$tag_title"'",
"release_name": "'"$tag_album"'"
}}]}' \
https://api.listenbrainz.org/1/submit-listens
fi
fi
}
# vgmfdb
vgmfdb_tags() {
local i
local file
local vgmfdb_tag_path
local vgmfdb_tag_size
local vgmfdb_tag_timestamp
file="$1"
if [[ -n "$listenbrainz_scrobb" ]] \
|| [[ -n "$publish_tags" ]] \
&& [[ -n "$vgmfdb" ]]; then
# Get id
vgmfdb_tag_path="$file"
vgmfdb_tag_size=$(wc -c "$file" | awk '{print $1;}')
vgmfdb_tag_timestamp=$(date -r "$file" "+%s")
vgmfdb_tag_id=$(echo "${vgmfdb_tag_path}${vgmfdb_tag_size}${vgmfdb_tag_timestamp}" \
| sha256sum | awk '{print $1;}')
# Get all tags
mapfile -t vgmfdb_tags < <( sqlite3 "$vgmfdb_database" "SELECT * FROM vgm WHERE id = '${vgmfdb_tag_id}'" \
| awk '{gsub(/\|/,"\n")}1' )
# Assign tags
if (( "${#vgmfdb_tags[@]}" )); then
tag_title="${vgmfdb_tags[2]}"
tag_artist="${vgmfdb_tags[3]}"
tag_album="${vgmfdb_tags[4]}"
tag_total_duration="${vgmfdb_tags[8]}"
tag_system="${vgmfdb_tags[9]}"
vgmfdb_id="1"
fi
fi
}
# Tag
tag_reset() {
if [[ -n "$listenbrainz_scrobb" ]] \
|| [[ -n "$publish_tags" ]]; then
# Reset
unset tag_title
unset tag_artist
unset tag_album
unset tag_total_duration
unset tag_system
unset tag_brainz_album_id
unset tag_brainz_artist_id
unset tag_brainz_recording_id
unset tag_brainz_releasegroupid_id
unset tag_brainz_track_id
unset vgmfdb_id
fi
}
tag_default() {
local file
file="$1"
if [[ -n "$listenbrainz_scrobb" ]] \
|| [[ -n "$publish_tags" ]] \
&& [[ -z "$vgmfdb_id" ]]; then
if [[ -z "$tag_title" ]]; then
tag_title=$(basename "${file%.*}")
fi
if [[ -z "$tag_album" ]]; then
tag_album=$(dirname "$file" | rev | cut -d'/' -f-1 | rev)
if [[ "$tag_album" = "." ]]; then
tag_album=$(pwd -P | rev | cut -d'/' -f-1 | rev)
fi
fi
if [[ -z "$tag_artist" ]]; then
tag_artist="$tag_album"
fi
if [[ -z "$tag_system" ]]; then
# tag_sytem by files ext.
shopt -s nocasematch
# Adlib
if [[ "${file##*.}" = "adl" ]]; then
tag_system="Westwood ADL"
elif [[ "${file##*.}" = "amd" ]]; then
tag_system="AMusic module"
elif [[ "${file##*.}" = "bam" ]]; then
tag_system="Bob's Adlib Music"
elif [[ "${file##*.}" = "cff" ]]; then
tag_system="Boom Tracker v4.0"
elif [[ "${file##*.}" = "cmf" ]]; then
tag_system="Creative Music Format"
elif [[ "${file##*.}" = "d00" ]]; then
tag_system="EdLib packed module"
elif [[ "${file##*.}" = "dfm" ]]; then
tag_system="Digital FM"
elif [[ "${file##*.}" = "ddt" ]]; then
tag_system="Jill of the Jungle Music File"
elif [[ "${file##*.}" = "dmo" ]]; then
tag_system="Twin TrackPlayer"
elif [[ "${file##*.}" = "dtm" ]]; then
tag_system="DeFy Tracker"
elif [[ "${file##*.}" = "got" ]]; then
tag_system="God of Thunder Music"
elif [[ "${file##*.}" = "hsc" ]]; then
tag_system="HSC AdLib Composer"
elif [[ "${file##*.}" = "hsq" ]]; then
tag_system="Herbulot AdLib"
elif [[ "${file##*.}" = "imf" ]] || [[ "${file##*.}" = "wlf" ]]; then
tag_system="Apogee IMF"
elif [[ "${file##*.}" = "laa" ]]; then
tag_system="LucasArts AdLib Module"
elif [[ "${file##*.}" = "ksm" ]]; then
tag_system="Ken's AdLib"
elif [[ "${file##*.}" = "m" ]] || [[ "${file##*.}" = "tm" ]]; then
tag_system="M Format"
elif [[ "${file##*.}" = "mdi" ]]; then
tag_system="AdLib MIDIPlay Format"
elif [[ "${file##*.}" = "mtk" ]]; then
tag_system="MPU-401 Tracker"
elif [[ "${file##*.}" = "rad" ]]; then
tag_system="Reality AdLib Tracker"
elif [[ "${file##*.}" = "rol" ]]; then
tag_system="AdLib/Roland Song"
elif [[ "${file##*.}" = "sdb" ]] || [[ "${file##*.}" = "sqx" ]]; then
tag_system="Herad System"
elif [[ "${file##*.}" = "xms" ]]; then
tag_system="AMUSIC Tracker XMS"
elif [[ "${file##*.}" = "xsm" ]]; then
tag_system="eXtra Simple Music"
elif [[ "${file##*.}" = "ay" ]]; then
tag_system="AY-3-8910"
# MIDI
elif [[ "${file##*.}" = "mid" ]]; then
tag_system="MIDI"
# MIDI-like
elif [[ "${file##*.}" = "hmi" ]]; then
tag_system="Human Machine Interfaces MIDI"
elif [[ "${file##*.}" = "hmp" ]]; then
tag_system="Human Machine Interfaces MIDI P"
elif [[ "${file##*.}" = "xmi" ]]; then
tag_system="Extended Multiple Instrument Digital Interface"
# s98
elif [[ "${file##*.}" = "s98" ]]; then
tag_system="PC-Engine / TurboGrafx-16"
# sc68
elif [[ "${file##*.}" = "sc68" ]]; then
tag_system="SC 68000"
# SAP
elif [[ "${file##*.}" = "sap" ]]; then
tag_system="Atari 8-bit"
# SID
elif [[ "${file##*.}" = "sid" ]] || [[ "${file##*.}" = "prg" ]]; then
tag_system="Comomdore 64/128"
# SNES
elif [[ "${file##*.}" = "spc" ]]; then
tag_system="Super Nintendo / Super Famicom"
# Tracker (uade)
elif [[ "${file##*.}" = "ahx" ]]; then
tag_system="Abyss Highest eXperience"
elif [[ "${file##*.}" = "bp" ]]; then
tag_system="SoundMon 2.0"
elif [[ "${file##*.}" = "cm" ]] || [[ "${file##*.}" = "rk" ]]; then
tag_system="CustomMade"
elif [[ "${file##*.}" = "cus" ]]; then
tag_system="DeliTracker Custom"
elif [[ "${file##*.}" = "dw" ]]; then
tag_system="David Whittaker"
elif [[ "${file##*.}" = "fc13" ]] || [[ "${file##*.}" = "fc14" ]]; then
tag_system="Future Composer"
elif [[ "${file##*.}" = "gmc" ]]; then
tag_system="Game Music Creator"
elif [[ "${file##*.}" = "np3" ]]; then
tag_system="Noise Packer 3.0"
elif [[ "${file##*.}" = "okt" ]]; then
tag_system="Oktalyzer"
elif [[ "${file##*.}" = "pru2" ]]; then
tag_system="Prorunner 2.0"
elif [[ "${file##*.}" = "s7g" ]]; then
tag_system="Jochen Hippel 7V"
elif [[ "${file##*.}" = "sfx" ]]; then
tag_system="SoundFX"
elif [[ "${file##*.}" = "soc" ]]; then
tag_system="Hippel-COSO"
elif [[ "${file##*.}" = "tiny" ]]; then
tag_system="Sonix Music Driver"
elif [[ "${file##*.}" = "tw" ]]; then
tag_system="Sound Images"
# Tracker (xmp)
elif [[ "${file##*.}" = "669" ]]; then
tag_system="Composer 669 Module"
elif [[ "${file##*.}" = "amf" ]]; then
tag_system="Advanced Module Format"
elif [[ "${file##*.}" = "dbm" ]] || [[ "${file##*.}" = "digi" ]]; then
tag_system="DigiBooster Module"
elif [[ "${file##*.}" = "dsym" ]]; then
tag_system="Digital Symphony Module"
elif [[ "${file##*.}" = "far" ]]; then
tag_system=" Farandole Composer Module"
elif [[ "${file##*.}" = "mdl" ]]; then
tag_system="Digitrakker Module"
elif [[ "${file##*.}" = "musx" ]]; then
tag_system="Archimedes Tracker Module"
elif [[ "${file##*.}" = "psm" ]]; then
tag_system="ProTracker Studio Module"
# Tracker (zxtune)
elif [[ "${file##*.}" = "rmt" ]]; then
tag_system="Raster Music Tracker"
elif [[ "${file##*.}" = "v2m" ]]; then
tag_system="Farbrausch V2M"
elif [[ "${file##*.}" = "vt2" ]]; then
tag_system="Vortex Tracker 2"
elif [[ "${file##*.}" = "vtx" ]]; then
tag_system="Vortex Tracker"
elif [[ "${file##*.}" = "xrns" ]]; then
tag_system="Renoise"
# X68000
elif [[ "${file##*.}" = "mdx" ]]; then
tag_system="Sharp X68000"
# xfs (zxtune)
elif [[ "${file##*.}" = "psf" || "${file##*.}" = "minipsf" ]]; then
tag_system="Sony PS1"
elif [[ "${file##*.}" = "psf2" || "${file##*.}" = "minipsf2" ]]; then
tag_system="Sony PS2"
elif [[ "${file##*.}" = "2sf" || "${file##*.}" = "mini2sf" || "${file##*.}" = "minincsf" || "${file##*.}" = "ncsf" ]]; then
tag_system="Nintendo DS"
elif [[ "${file##*.}" = "ssf" || "${file##*.}" = "minissf" ]]; then
tag_system="Sega Saturn"
elif [[ "${file##*.}" = "gsf" || "${file##*.}" = "minigsf" ]]; then
tag_system="Nintendo GBA"
elif [[ "${file##*.}" = "usf" || "${file##*.}" = "miniusf" ]]; then
tag_system="Nintendo 64"
elif [[ "${file##*.}" = "dsf" || "${file##*.}" = "minidsf" ]]; then
tag_system="Sega Dreamcast"
elif [[ "${file##*.}" = "ym" ]]; then
tag_system="Yamaha Music"
# ZX Spectrum (zxtune)
elif [[ "${file##*.}" = "asc" ]]; then
tag_system="ASC Sound Master"
elif [[ "${file##*.}" = "psc" ]]; then
tag_system="Pro Sound Creator"
elif [[ "${file##*.}" = "pt1" ]] || [[ "${file##*.}" = "pt2" ]] || [[ "${file##*.}" = "pt3" ]]; then
tag_system="Pro Tracker"
elif [[ "${file##*.}" = "sqt" ]]; then
tag_system="Quartet PSG Module"
elif [[ "${file##*.}" = "stc" ]]; then
tag_system="STC Sound Trackere"
elif [[ "${file##*.}" = "stp" ]]; then
tag_system="Soundtracker Pro II Module"
elif [[ "${file##*.}" = "tap" ]]; then
tag_system="ZX Spectrum Tape Image"
fi
shopt -u nocasematch
fi
fi
}
tag_common() {
local file
local file_type
local file_kbs
local file_size
local file_hz
file="$1"
if [[ -n "$listenbrainz_scrobb" ]] \
|| [[ -n "$publish_tags" ]]; then
# According to https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html
if [[ -n "$mutagen_inspect_bin" ]]; then
"$mutagen_inspect_bin" "$file" > "$glouglou_cache_tags"
tag_title=$(< "$glouglou_cache_tags" \
grep -E -i -a "^title=|^TIT2=" \
| cut -f2- -d'=')
tag_artist=$(< "$glouglou_cache_tags" \
grep -E -i -a "^artist=|^TPE1=" \
| cut -f2- -d'=')
tag_album=$(< "$glouglou_cache_tags" \
grep -E -i -a "^album=|^TALB=" \
| cut -f2- -d'=')
tag_total_duration=$(< "$glouglou_cache_tags" \
grep "seconds" \
| head -1 \
| awk -F"seconds" '{print $1}' \
| awk '{print $NF}' \
| awk -F"." '{print $1}')
tag_brainz_album_id=$(< "$glouglou_cache_tags" \
grep -E -i -a "^MUSICBRAINZ_ALBUMID=|^TXXX:MusicBrainz Artist Id=" \
| cut -f2- -d'=')
tag_brainz_artist_id=$(< "$glouglou_cache_tags" \
grep -E -i -a "^MUSICBRAINZ_ARTISTID=|^TXXX:MusicBrainz Artist Id=" \
| cut -f2- -d'=')
tag_brainz_recording_id=$(< "$glouglou_cache_tags" \
grep -E -i -a "^MUSICBRAINZ_TRACKID=" \
| cut -f2- -d'=')
tag_brainz_releasegroupid_id=$(< "$glouglou_cache_tags" \
grep -E -i -a "^MUSICBRAINZ_RELEASEGROUPID=|^TXXX:MusicBrainz Release Group Id" \
| cut -f2- -d'=')
tag_brainz_track_id=$(< "$glouglou_cache_tags" \
grep -E -i -a "^MUSICBRAINZ_RELEASETRACKID=|^TXXX:MusicBrainz Release Track Id" \
| cut -f2- -d'=')
# tag_system type
file_type="${file##*.}"
file_type="${file_type^^}"
if [[ "$file_type" = "FLC" ]]; then
file_type="FLAC - "
elif [[ "$file_type" = "WV" ]]; then
file_type="WAVPACK"
fi
# tag_system kb/s
file_kbs=$(< "$glouglou_cache_tags" \
grep "bps" \
| head -1 \
| awk -F"bps" '{print $1}' \
| awk '{print $NF}')
if [[ $file_kbs =~ ^[0-9]+$ ]]; then
file_kbs=$(bc <<< "scale=0; $file_kbs/1000")
file_kbs="$file_kbs kb/s"
elif [[ $tag_total_duration =~ ^[0-9]+$ ]]; then
file_size=$(wc -c "$file" | awk '{print $1;}')
file_size=$(bc <<< "scale=0; $file_size / 1024")
file_kbs=$(( 8 * file_size / tag_total_duration))
file_kbs="$file_kbs kb/s"
else
unset file_kbs
fi
# tag_system kHz
if [[ "$file_type" = "OPUS" ]]; then
file_hz="48 kHz"
else
file_hz=$(< "$glouglou_cache_tags" \