File size: 60,374 Bytes
d44e1e3
 
d7d98b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d44e1e3
d7d98b9
 
 
 
 
 
 
 
 
0cfe7b7
 
 
 
 
d7d98b9
 
 
 
 
 
 
 
 
 
d44e1e3
 
d7d98b9
 
 
 
 
e99018f
d7d98b9
 
 
 
 
 
 
d44e1e3
 
 
 
 
 
 
 
 
 
 
d7d98b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e99018f
d7d98b9
 
 
 
 
 
 
 
 
 
 
 
 
e99018f
 
 
d7d98b9
 
 
 
 
d44e1e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e99018f
 
 
 
 
0cfe7b7
e99018f
 
0cfe7b7
 
e99018f
0cfe7b7
 
e99018f
 
0cfe7b7
 
 
e99018f
b32dc46
 
e99018f
 
 
0cfe7b7
 
e99018f
 
 
0cfe7b7
 
 
e99018f
0cfe7b7
 
e99018f
 
 
 
0cfe7b7
 
e99018f
 
 
0cfe7b7
 
 
e99018f
0cfe7b7
 
e99018f
 
 
 
0cfe7b7
 
e99018f
 
 
0cfe7b7
 
 
e99018f
0cfe7b7
 
e99018f
 
 
b32dc46
e99018f
 
 
0cfe7b7
 
e99018f
0cfe7b7
 
e99018f
 
0cfe7b7
 
 
e99018f
0cfe7b7
 
e99018f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d44e1e3
e99018f
 
 
 
 
 
 
 
d44e1e3
e99018f
 
 
 
 
 
 
 
 
 
 
 
 
 
d44e1e3
e99018f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25ad6b2
 
 
e99018f
25ad6b2
e99018f
 
 
 
 
 
 
 
 
 
25ad6b2
e99018f
 
 
 
 
 
 
0cfe7b7
e99018f
0cfe7b7
0ea28f3
b32dc46
 
e99018f
 
 
d44e1e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b32dc46
 
d44e1e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b32dc46
d44e1e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b32dc46
 
d44e1e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e99018f
d7d98b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d44e1e3
d7d98b9
 
 
d44e1e3
d7d98b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b15a0fe
d7d98b9
 
 
 
 
0ea28f3
d7d98b9
 
 
 
 
 
 
 
 
 
 
 
 
 
e99018f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25ad6b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7d98b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e99018f
d7d98b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e99018f
 
 
b32dc46
 
 
 
 
 
 
 
 
e99018f
 
 
 
 
 
 
 
b32dc46
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
document.body.style.paddingRight = `${window.innerWidth - document.body.clientWidth}px`;
document.body.style.overflow = 'hidden';
const internalConfig = {
  'network': {
    'userAgent': {
      'chromeWindows': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
      'curl': 'curl/8.4.0',
      'curlUnity': 'UnityPlayer/2021.3.14f1 (UnityWebRequest/1.0, libcurl/7.84.0-DEV)'
    },
    'timeout': 15000
  }
};
const apiConnectDefaultHeader = {
  'Access-Controll-Allow-Origin': '*'
}
const appSettingsStorageName = '018d2fc7-d0bb-7393-9ebc-6f6ec26b03ce_appSettings';
let appSettingsSaveData = new Object();
const appSettingsSaveDataDefault = {
  'ui': {
    'uiThemeMode': 'light'
  }
};
let apiDataMasterDB = new Object();
let apiDataConfig = new Object();
let bootstrapTooltipList = null;

//!========== ページ読み込み時に実行する処理 ==========

window.addEventListener('load', async function(){
  if (checkAppSettingsExistsOnStorage() === true) {
    loadAppSettingsFromLocalStorage();
  } else {
    loadAppSettingsFromLocalStorage();
    if (window.matchMedia('(prefers-color-scheme:dark)').matches === true) {
      console.warn(`prefers-color-scheme:dark detected`);
      if (appSettingsSaveData.ui.uiThemeMode !== 'dark') {
        appSettingsSaveData.ui.uiThemeMode = 'dark';
        writeAppSettingsToLocalStorage();
      }
    } else {
      appSettingsSaveData.ui.uiThemeMode = 'light';
      writeAppSettingsToLocalStorage();
    }
  }
  appSettingsCheckedUiUpdate();
  appSettingsApply();
  await loadRequiredDatabase();
  await decryptConfig();
  pushToTrackListGroupUi();
  pushToAlbumListGroupUi();
  fsOverlayLoadingScrControl();
});

document.querySelector('#loadDatabaseTestButton').addEventListener('click', async function() {
  console.log('loadDatabaseTestButton clicked!');
  await loadRequiredDatabase();
  await decryptConfig();
});

document.querySelector('#trackListingTestButton').addEventListener('click', () => {
  console.log('trackListingTestButton clicked!');
  pushToTrackListGroupUi();
});

// ========== fsOverlayLoadingScr制御 ==========

function fsOverlayLoadingScrControl () {
  document.getElementById('fsOverlayLoadingScr').style.backgroundColor = 'rgba(0,0,0,0)';
  document.getElementById('fsOverlayLoadingScr').style.visibility = 'hidden';
  document.getElementById('fsOverlayLoadingScr').style.backdropFilter = 'blur(0)';
  document.getElementById('fsOverlayLoadingScr_loadingSpinner').style.opacity = 0;
  document.body.style.paddingRight = 0;
  document.body.style.overflow = 'auto';
}

// ========== 全てのトラックのリストをTrack Listing TestのListGroupに表示 ==========

function pushToTrackListGroupUi () {
  const trackAllListGroup = document.querySelector('#trackAllListGroup');
  while(trackAllListGroup.firstChild) {
    trackAllListGroup.removeChild(trackAllListGroup.firstChild);
  }
  let headerElObj = new Object();
  headerElObj.buttonNodeEl = document.createElement('button');
  headerElObj.divArtistNodeEl = document.createElement('div');
  headerElObj.divAlbumNodeEl = document.createElement('div');
  headerElObj.divTrackNodeEl = document.createElement('div');
  headerElObj.buttonNodeEl.classList.add('list-group-item', 'list-group-item-action', 'd-flex');
  headerElObj.buttonNodeEl.setAttribute('type', 'button');
  headerElObj.buttonNodeEl.disabled = true;
  headerElObj.divArtistNodeEl.classList.add('flex-fill', 'w-100');
  headerElObj.divAlbumNodeEl.classList.add('flex-fill', 'w-100');
  headerElObj.divTrackNodeEl.classList.add('flex-fill', 'w-100');
  headerElObj.divArtistNodeEl.innerHTML = 'Artist';
  headerElObj.divAlbumNodeEl.innerHTML = 'Album';
  headerElObj.divTrackNodeEl.innerHTML = 'Track';
  headerElObj.buttonNodeEl.appendChild(headerElObj.divArtistNodeEl);
  headerElObj.buttonNodeEl.appendChild(headerElObj.divAlbumNodeEl);
  headerElObj.buttonNodeEl.appendChild(headerElObj.divTrackNodeEl);
  trackAllListGroup.appendChild(headerElObj.buttonNodeEl);
  apiDataMasterDB.response.data.albums.forEach((albumObject) => {
    albumObject.tracks.forEach((trackObject) => {
      let buttonNodeEl = document.createElement('button');
      let divArtistNodeEl = document.createElement('div');
      let divAlbumNodeEl = document.createElement('div');
      let divTrackNodeEl = document.createElement('div');
      buttonNodeEl.classList.add('list-group-item', 'list-group-item-action', 'd-flex');
      buttonNodeEl.setAttribute('type', 'button');
      buttonNodeEl.setAttribute('data-track-uuid', trackObject.uuid);
      divArtistNodeEl.classList.add('flex-fill', 'w-100');
      divAlbumNodeEl.classList.add('flex-fill', 'w-100');
      divTrackNodeEl.classList.add('flex-fill', 'w-100');
      let albumArtistFilteredList = new Array();
      albumObject.artist.forEach((str) => {
        albumArtistFilteredList.push(apiDataMasterDB.response.data.artists.filter((obj) => obj.uuid === str)[0].name);
      });
      divArtistNodeEl.innerHTML = albumArtistFilteredList.join(', ');
      divAlbumNodeEl.innerHTML = albumObject.title;
      divTrackNodeEl.innerHTML = trackObject.title;
      buttonNodeEl.appendChild(divArtistNodeEl);
      buttonNodeEl.appendChild(divAlbumNodeEl);
      buttonNodeEl.appendChild(divTrackNodeEl);
      buttonNodeEl.addEventListener('click', () => {
        loadTrackInfoModal(trackObject.uuid);
      });
      trackAllListGroup.appendChild(buttonNodeEl);
    });
  });
}

// ========== Album Listをビルド ==========

function pushToAlbumListGroupUi () {
  const albumAllCardGroup = document.getElementById('albumAllCardGroup');
  while(albumAllCardGroup.firstChild) {
    albumAllCardGroup.removeChild(albumAllCardGroup.firstChild);
  }
  apiDataMasterDB.response.data.albums.forEach((albumObject) => {
    let albumParsedObject = getParsedAlbumObjectFromAlbumUuid(albumObject.uuid);
    let elementObj = new Object();
    elementObj.colDiv = document.createElement('div');
    elementObj.cardDiv = document.createElement('div');
    elementObj.cardBodyDiv = document.createElement('div');
    elementObj.cardImgDiv = document.createElement('div');
    elementObj.cardImg = document.createElement('img');
    elementObj.cardTitle = document.createElement('h5');
    elementObj.cardText = document.createElement('p');
    elementObj.colDiv.classList.add('col');
    elementObj.cardDiv.classList.add('card', 'h-100');
    elementObj.cardBodyDiv.classList.add('card-body');
    elementObj.cardImgDiv.classList.add('object-fit-cover', 'cs_card-img-wrapper')
    elementObj.cardImg.classList.add('card-img-top', 'object-fit-cover', 'lazyload', 'customlazyload-blur', 'user-select-none', 'user-drag-none', 'pe-none');
    elementObj.cardTitle.classList.add('card-title');
    elementObj.cardText.classList.add('card-text');
    elementObj.cardImg.src = `data:image/webp;base64,${albumObject.coverArtPotatoWebp16pxBase64}`;
    // elementObj.cardImg.src = `data:image/bmp;base64,${albumObject.coverArtPotatoBmp8pxBase64}`;
    elementObj.cardImg.setAttribute('data-src', `${apiDataConfig.response.config.decrypted.rawMediaUrlBase64}/media/${albumParsedObject.uuid}/${albumParsedObject.coverArts.slice(-1)[0].fileName}.${albumParsedObject.coverArts.slice(-1)[0].format[0].extension}`);
    // elementObj.cardImg.setAttribute('loading', 'lazy');
    elementObj.cardTitle.innerHTML = albumParsedObject.title;
    elementObj.cardText.innerHTML = albumParsedObject.artist.map((obj) => obj.name).join(', ');
    elementObj.cardBodyDiv.appendChild(elementObj.cardTitle);
    elementObj.cardBodyDiv.appendChild(elementObj.cardText);
    elementObj.cardImgDiv.appendChild(elementObj.cardImg);
    elementObj.cardDiv.appendChild(elementObj.cardImgDiv);
    elementObj.cardDiv.appendChild(elementObj.cardBodyDiv);
    elementObj.cardDiv.addEventListener('click', () => {loadAlbumInfoModal(albumParsedObject.uuid)});
    elementObj.colDiv.appendChild(elementObj.cardDiv);
    albumAllCardGroup.appendChild(elementObj.colDiv);
  });
}

// ========== trackInfoModalの処理 ==========

function loadTrackInfoModal (trackUuid) {
  const albumParsedObject = getParsedAlbumObjectFromAlbumUuid(getAlbumUuidFromTrackUuid(trackUuid));
  const trackParsedObject = albumParsedObject.tracks.find((obj) => obj.uuid === trackUuid);
  if (bootstrapTooltipList !== null) {bootstrapTooltipList.forEach(el => el.dispose())}
  document.getElementById('trackInfoModal-metadataTable-trackTitle').innerHTML = trackParsedObject.title;
  if (trackParsedObject.titleLatin === null) {
    document.getElementById('trackInfoModal-metadataTable-trackTitle').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal-metadataTable-trackTitle').removeAttribute('data-bs-title');
  } else {
    document.getElementById('trackInfoModal-metadataTable-trackTitle').setAttribute('data-bs-toggle', 'tooltip');
    document.getElementById('trackInfoModal-metadataTable-trackTitle').setAttribute('data-bs-title', trackParsedObject.titleLatin);
  }
  document.getElementById('trackInfoModal-metadataTable-artists').innerHTML = trackParsedObject.artist.map((obj) => obj.name).join(', ');
  if (trackParsedObject.artist.some((obj) => obj.nameLatin !== null)) {
    document.getElementById('trackInfoModal-metadataTable-artists').setAttribute('data-bs-toggle', 'tooltip');
    document.getElementById('trackInfoModal-metadataTable-artists').setAttribute('data-bs-title', trackParsedObject.artist.map((obj) => {if (obj.nameLatin !== null) {return obj.nameLatin} else {return obj.name}}).join(', '));
  } else {
    document.getElementById('trackInfoModal-metadataTable-artists').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal-metadataTable-artists').removeAttribute('data-bs-title');
  }
  if (trackParsedObject.lyricist === null) {
    document.getElementById('trackInfoModal-metadataTable-lyricist').parentNode.classList.add('d-none');
    document.getElementById('trackInfoModal-metadataTable-lyricist').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal-metadataTable-lyricist').removeAttribute('data-bs-title');
  } else {
    document.getElementById('trackInfoModal-metadataTable-lyricist').parentNode.classList.remove('d-none');
    document.getElementById('trackInfoModal-metadataTable-lyricist').innerHTML = trackParsedObject.lyricist.map((obj) => obj.name).join(', ');
    if (trackParsedObject.lyricist.some((obj) => obj.nameLatin !== null)) {
      document.getElementById('trackInfoModal-metadataTable-lyricist').setAttribute('data-bs-toggle', 'tooltip');
      document.getElementById('trackInfoModal-metadataTable-lyricist').setAttribute('data-bs-title', trackParsedObject.lyricist.map((obj) => {if (obj.nameLatin !== null) {return obj.nameLatin} else {return obj.name}}).join(', '));
    } else {
      document.getElementById('trackInfoModal-metadataTable-lyricist').removeAttribute('data-bs-toggle');
      document.getElementById('trackInfoModal-metadataTable-lyricist').removeAttribute('data-bs-title');
    }
  }
  if (trackParsedObject.composer === null) {
    document.getElementById('trackInfoModal-metadataTable-composer').parentNode.classList.add('d-none');
    document.getElementById('trackInfoModal-metadataTable-composer').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal-metadataTable-composer').removeAttribute('data-bs-title');
  } else {
    document.getElementById('trackInfoModal-metadataTable-composer').parentNode.classList.remove('d-none');
    document.getElementById('trackInfoModal-metadataTable-composer').innerHTML = trackParsedObject.composer.map((obj) => obj.name).join(', ');
    if (trackParsedObject.composer.some((obj) => obj.nameLatin !== null)) {
      document.getElementById('trackInfoModal-metadataTable-composer').setAttribute('data-bs-toggle', 'tooltip');
      document.getElementById('trackInfoModal-metadataTable-composer').setAttribute('data-bs-title', trackParsedObject.composer.map((obj) => {if (obj.nameLatin !== null) {return obj.nameLatin} else {return obj.name}}).join(', '));
    } else {
      document.getElementById('trackInfoModal-metadataTable-composer').removeAttribute('data-bs-toggle');
      document.getElementById('trackInfoModal-metadataTable-composer').removeAttribute('data-bs-title');
    }
  }
  if (trackParsedObject.arranger === null) {
    document.getElementById('trackInfoModal-metadataTable-arranger').parentNode.classList.add('d-none');
    document.getElementById('trackInfoModal-metadataTable-arranger').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal-metadataTable-arranger').removeAttribute('data-bs-title');
  } else {
    document.getElementById('trackInfoModal-metadataTable-arranger').parentNode.classList.remove('d-none');
    document.getElementById('trackInfoModal-metadataTable-arranger').innerHTML = trackParsedObject.arranger.map((obj) => obj.name).join(', ');
    if (trackParsedObject.arranger.some((obj) => obj.nameLatin !== null)) {
      document.getElementById('trackInfoModal-metadataTable-arranger').setAttribute('data-bs-toggle', 'tooltip');
      document.getElementById('trackInfoModal-metadataTable-arranger').setAttribute('data-bs-title', trackParsedObject.arranger.map((obj) => {if (obj.nameLatin !== null) {return obj.nameLatin} else {return obj.name}}).join(', '));
    } else {
      document.getElementById('trackInfoModal-metadataTable-arranger').removeAttribute('data-bs-toggle');
      document.getElementById('trackInfoModal-metadataTable-arranger').removeAttribute('data-bs-title');
    }
  }
  document.getElementById('trackInfoModal-metadataTable-trackDurationReadable').innerHTML = msecToReadableTime(trackParsedObject.durationMsecs);
  document.getElementById('trackInfoModal-metadataTable-trackDurationMsec').innerHTML = `${Math.ceil(trackParsedObject.durationMsecs)} ms`;
  document.getElementById('trackInfoModal-metadataTable-trackDurationSamples').innerHTML = `${trackParsedObject.durationSamples} samples`;
  document.getElementById('trackInfoModal-metadataTable-albumTitle').innerHTML = albumParsedObject.title;
  if (albumParsedObject.titleLatin === null) {
    document.getElementById('trackInfoModal-metadataTable-albumTitle').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal-metadataTable-albumTitle').removeAttribute('data-bs-title');
  } else {
    document.getElementById('trackInfoModal-metadataTable-albumTitle').setAttribute('data-bs-toggle', 'tooltip');
    document.getElementById('trackInfoModal-metadataTable-albumTitle').setAttribute('data-bs-title', albumParsedObject.titleLatin);
  }
  document.getElementById('trackInfoModal-metadataTable-albumArtist').innerHTML = albumParsedObject.artist.map((obj) => obj.name).join(', ');
  if (albumParsedObject.artist.some((obj) => obj.nameLatin !== null)) {
    document.getElementById('trackInfoModal-metadataTable-albumArtist').setAttribute('data-bs-toggle', 'tooltip');
    document.getElementById('trackInfoModal-metadataTable-albumArtist').setAttribute('data-bs-title', albumParsedObject.artist.map((obj) => {if (obj.nameLatin !== null) {return obj.nameLatin} else {return obj.name}}).join(', '));
  } else {
    document.getElementById('trackInfoModal-metadataTable-albumArtist').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal-metadataTable-albumArtist').removeAttribute('data-bs-title');
  }
  document.getElementById('trackInfoModal-metadataTable-albumReleaseDate').innerHTML = moment(albumParsedObject.releaseDate).format('YYYY/MM/DD');
  document.getElementById('trackInfoModal-metadataTable-albumBarcode').innerHTML = albumParsedObject.barCode;
  document.getElementById('trackInfoModal-metadataTable-albumCopyright').innerHTML = albumParsedObject.copyright;
  while(document.getElementById('trackInfoModal-externalLinkTable').firstChild) {
    document.getElementById('trackInfoModal-externalLinkTable').removeChild(document.getElementById('trackInfoModal-externalLinkTable').firstChild);
  }
  while(document.getElementById('trackInfoModal-coverArtLinkDiv').firstChild) {
    document.getElementById('trackInfoModal-coverArtLinkDiv').removeChild(document.getElementById('trackInfoModal-coverArtLinkDiv').firstChild);
  }
  while(document.getElementById('trackInfoModal-downloadTable').firstChild) {
    document.getElementById('trackInfoModal-downloadTable').removeChild(document.getElementById('trackInfoModal-downloadTable').firstChild);
  }
  if (albumParsedObject.link.itunes !== null || albumParsedObject.link.spotify !== null) {
    let temp_extLinkAlbumTrEl = document.createElement('tr');
    let temp_extLinkAlbumTdKeyEl = document.createElement('td');
    let temp_extLinkAlbumTdValueEl = document.createElement('td');
    let temp_extLinkAlbumA1El = document.createElement('a');
    let temp_extLinkAlbumA2El = document.createElement('a');
    temp_extLinkAlbumTdKeyEl.innerHTML = 'Album Link';
    if (albumParsedObject.link.itunes !== null) {
      temp_extLinkAlbumA1El.classList.add('btn','btn-outline-primary','btn-sm','me-2');
      temp_extLinkAlbumA1El.setAttribute('href', `https://music.apple.com/album/${albumParsedObject.link.itunes}`);
      temp_extLinkAlbumA1El.setAttribute('role', 'button');
      temp_extLinkAlbumA1El.setAttribute('target', '_blank');
      temp_extLinkAlbumA1El.setAttribute('rel', 'noopener noreferrer');
      temp_extLinkAlbumA1El.innerHTML = 'Apple Music';
      temp_extLinkAlbumTdValueEl.appendChild(temp_extLinkAlbumA1El);
    }
    if (albumParsedObject.link.spotify !== null) {
      temp_extLinkAlbumA2El.classList.add('btn','btn-outline-primary','btn-sm','me-2');
      temp_extLinkAlbumA2El.setAttribute('href', `https://open.spotify.com/album/${albumParsedObject.link.spotify}`);
      temp_extLinkAlbumA2El.setAttribute('role', 'button');
      temp_extLinkAlbumA2El.setAttribute('target', '_blank');
      temp_extLinkAlbumA2El.setAttribute('rel', 'noopener noreferrer');
      temp_extLinkAlbumA2El.innerHTML = 'Spotify';
      temp_extLinkAlbumTdValueEl.appendChild(temp_extLinkAlbumA2El);
    }
    temp_extLinkAlbumTrEl.appendChild(temp_extLinkAlbumTdKeyEl);
    temp_extLinkAlbumTrEl.appendChild(temp_extLinkAlbumTdValueEl);
    document.getElementById('trackInfoModal-externalLinkTable').appendChild(temp_extLinkAlbumTrEl);
  }
  albumParsedObject.coverArts.forEach((obj1) => {
    obj1.format.forEach((obj2) => {
      let temp_coverArtAEl = document.createElement('a');
      temp_coverArtAEl.classList.add('btn','btn-primary','btn-sm','me-2','mb-2');
      temp_coverArtAEl.setAttribute('href', `${apiDataConfig.response.config.decrypted.rawMediaUrlBase64}/media/${albumParsedObject.uuid}/${obj1.fileName}.${obj2.extension}`);
      temp_coverArtAEl.setAttribute('role', 'button');
      temp_coverArtAEl.setAttribute('target', '_blank');
      temp_coverArtAEl.setAttribute('rel', 'noopener noreferrer');
      temp_coverArtAEl.innerHTML = `${obj2.name} ${obj1.height}px`;
      document.getElementById('trackInfoModal-coverArtLinkDiv').appendChild(temp_coverArtAEl);
    });
  });
  let temp_codecListImported = new Array();
  if (albumParsedObject.isAllTrackSameCodecs === false) {temp_codecListImported = trackParsedObject.codecs} else {temp_codecListImported = albumParsedObject.codecs}
  temp_codecListImported.forEach((obj) => {
    let temp_dlTrEl = document.createElement('tr');
    let temp_dlTdCodecEl = document.createElement('td');
    let temp_dlTdInfoEl = document.createElement('td');
    let temp_dlTdBtnEl = document.createElement('td');
    let temp_dlButtonGroupEl = document.createElement('div');
    let temp_dlButtonEl = document.createElement('button');
    let temp_dlButtonExtEl = document.createElement('a');
    let temp_dlButtonIconEl = document.createElement('i');
    let temp_dlButtonExtIconEl = document.createElement('i');
    let temp_codecBitrateTemporal = null;
    temp_dlTdCodecEl.innerHTML = obj.nameBasic;
    temp_dlTdCodecEl.setAttribute('data-bs-toggle', 'tooltip');
    temp_dlTdCodecEl.setAttribute('data-bs-title', obj.nameLong);
    if ((obj.bitRateAvg !== null && obj.bitRateMax !== null) || (obj.bitRateAvg !== null && obj.bitRateMax === null)) {
      temp_codecBitrateTemporal = obj.bitRateAvg;
    } else {
      temp_codecBitrateTemporal = obj.bitRateMax;
    }
    if (obj.bitDepth === null) {
      temp_dlTdInfoEl.innerHTML = `${obj.sampleRate / 1000}kHz ${obj.channelCount}ch ${temp_codecBitrateTemporal / 1000}kbps`;
    } else {
      temp_dlTdInfoEl.innerHTML = `${obj.bitDepth}bit ${obj.sampleRate / 1000}kHz ${obj.channelCount}ch ${temp_codecBitrateTemporal / 1000}kbps`;
    }
    if (obj.isOriginal === true) {
      temp_dlButtonEl.classList.add('btn', 'btn-primary');
      temp_dlButtonExtEl.classList.add('btn', 'btn-primary', 'text-center');
    } else {
      temp_dlButtonEl.classList.add('btn', 'btn-secondary');
      temp_dlButtonExtEl.classList.add('btn', 'btn-secondary', 'text-center');
    }
    temp_dlButtonEl.setAttribute('type', 'button');
    // temp_dlButtonEl.addEventListener('click', async () => {
    //   await downloadAudioDataToBlob (trackParsedObject.uuid, obj.uuid)
    // })
    temp_dlButtonExtEl.setAttribute('href', `${apiDataConfig.response.config.decrypted.rawMediaUrlBase64}/media/${albumParsedObject.uuid}/${obj.path}/${trackParsedObject.uuid}.${obj.extension}`);
    temp_dlButtonExtEl.setAttribute('download', determineDownloadFileName(trackParsedObject.uuid, obj.uuid));
    temp_dlButtonExtEl.setAttribute('role', 'button');
    temp_dlButtonExtEl.setAttribute('target', '_blank');
    temp_dlButtonExtEl.setAttribute('rel', 'noopener noreferrer');
    temp_dlButtonGroupEl.setAttribute('role', 'group');
    temp_dlButtonGroupEl.classList.add('btn-group');
    temp_dlButtonIconEl.classList.add('bi', 'bi-download');
    temp_dlButtonExtIconEl.classList.add('bi', 'bi-box-arrow-up-right');
    temp_dlTdBtnEl.classList.add('text-end');
    temp_dlButtonEl.appendChild(temp_dlButtonIconEl);
    temp_dlButtonExtEl.appendChild(temp_dlButtonExtIconEl);
    // temp_dlButtonGroupEl.appendChild(temp_dlButtonEl);
    temp_dlButtonGroupEl.appendChild(temp_dlButtonExtEl);
    temp_dlTdBtnEl.appendChild(temp_dlButtonGroupEl);
    temp_dlTrEl.appendChild(temp_dlTdCodecEl);
    temp_dlTrEl.appendChild(temp_dlTdInfoEl);
    temp_dlTrEl.appendChild(temp_dlTdBtnEl);
    document.getElementById('trackInfoModal-downloadTable').appendChild(temp_dlTrEl);
  });
  document.getElementById('trackInfoModal-previewAudio').src = `${apiDataConfig.response.config.decrypted.rawMediaUrlBase64}/media/${albumParsedObject.uuid}/${temp_codecListImported.slice(-1)[0].path}/${trackParsedObject.uuid}.${temp_codecListImported.slice(-1)[0].extension}`;
  const bootstrapTooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
  bootstrapTooltipList = [...bootstrapTooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
  document.getElementById('trackInfoModal-DebugAcdOutputEl').innerHTML = JSON.stringify(albumParsedObject, '', '  ');
  document.getElementById('trackInfoModal-ModalCloseButton').addEventListener('click', () => {allAudioElementStop()});
  document.getElementById('trackInfoModal-ModalCloseIconButton').addEventListener('click', () => {allAudioElementStop()});
  const trackInfoModal = new bootstrap.Modal(document.getElementById('trackInfoModal'));
  trackInfoModal.show();
}
function loadTrackInfoModal2 (trackUuid) {
  const albumParsedObject = getParsedAlbumObjectFromAlbumUuid(getAlbumUuidFromTrackUuid(trackUuid));
  const trackParsedObject = albumParsedObject.tracks.find((obj) => obj.uuid === trackUuid);
  if (bootstrapTooltipList !== null) {bootstrapTooltipList.forEach(el => el.dispose())}
  document.getElementById('trackInfoModal2-metadataTable-trackTitle').innerHTML = trackParsedObject.title;
  if (trackParsedObject.titleLatin === null) {
    document.getElementById('trackInfoModal2-metadataTable-trackTitle').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal2-metadataTable-trackTitle').removeAttribute('data-bs-title');
  } else {
    document.getElementById('trackInfoModal2-metadataTable-trackTitle').setAttribute('data-bs-toggle', 'tooltip');
    document.getElementById('trackInfoModal2-metadataTable-trackTitle').setAttribute('data-bs-title', trackParsedObject.titleLatin);
  }
  document.getElementById('trackInfoModal2-metadataTable-artists').innerHTML = trackParsedObject.artist.map((obj) => obj.name).join(', ');
  if (trackParsedObject.artist.some((obj) => obj.nameLatin !== null)) {
    document.getElementById('trackInfoModal2-metadataTable-artists').setAttribute('data-bs-toggle', 'tooltip');
    document.getElementById('trackInfoModal2-metadataTable-artists').setAttribute('data-bs-title', trackParsedObject.artist.map((obj) => {if (obj.nameLatin !== null) {return obj.nameLatin} else {return obj.name}}).join(', '));
  } else {
    document.getElementById('trackInfoModal2-metadataTable-artists').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal2-metadataTable-artists').removeAttribute('data-bs-title');
  }
  if (trackParsedObject.lyricist === null) {
    document.getElementById('trackInfoModal2-metadataTable-lyricist').parentNode.classList.add('d-none');
    document.getElementById('trackInfoModal2-metadataTable-lyricist').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal2-metadataTable-lyricist').removeAttribute('data-bs-title');
  } else {
    document.getElementById('trackInfoModal2-metadataTable-lyricist').parentNode.classList.remove('d-none');
    document.getElementById('trackInfoModal2-metadataTable-lyricist').innerHTML = trackParsedObject.lyricist.map((obj) => obj.name).join(', ');
    if (trackParsedObject.lyricist.some((obj) => obj.nameLatin !== null)) {
      document.getElementById('trackInfoModal2-metadataTable-lyricist').setAttribute('data-bs-toggle', 'tooltip');
      document.getElementById('trackInfoModal2-metadataTable-lyricist').setAttribute('data-bs-title', trackParsedObject.lyricist.map((obj) => {if (obj.nameLatin !== null) {return obj.nameLatin} else {return obj.name}}).join(', '));
    } else {
      document.getElementById('trackInfoModal2-metadataTable-lyricist').removeAttribute('data-bs-toggle');
      document.getElementById('trackInfoModal2-metadataTable-lyricist').removeAttribute('data-bs-title');
    }
  }
  if (trackParsedObject.composer === null) {
    document.getElementById('trackInfoModal2-metadataTable-composer').parentNode.classList.add('d-none');
    document.getElementById('trackInfoModal2-metadataTable-composer').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal2-metadataTable-composer').removeAttribute('data-bs-title');
  } else {
    document.getElementById('trackInfoModal2-metadataTable-composer').parentNode.classList.remove('d-none');
    document.getElementById('trackInfoModal2-metadataTable-composer').innerHTML = trackParsedObject.composer.map((obj) => obj.name).join(', ');
    if (trackParsedObject.composer.some((obj) => obj.nameLatin !== null)) {
      document.getElementById('trackInfoModal2-metadataTable-composer').setAttribute('data-bs-toggle', 'tooltip');
      document.getElementById('trackInfoModal2-metadataTable-composer').setAttribute('data-bs-title', trackParsedObject.composer.map((obj) => {if (obj.nameLatin !== null) {return obj.nameLatin} else {return obj.name}}).join(', '));
    } else {
      document.getElementById('trackInfoModal2-metadataTable-composer').removeAttribute('data-bs-toggle');
      document.getElementById('trackInfoModal2-metadataTable-composer').removeAttribute('data-bs-title');
    }
  }
  if (trackParsedObject.arranger === null) {
    document.getElementById('trackInfoModal2-metadataTable-arranger').parentNode.classList.add('d-none');
    document.getElementById('trackInfoModal2-metadataTable-arranger').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal2-metadataTable-arranger').removeAttribute('data-bs-title');
  } else {
    document.getElementById('trackInfoModal2-metadataTable-arranger').parentNode.classList.remove('d-none');
    document.getElementById('trackInfoModal2-metadataTable-arranger').innerHTML = trackParsedObject.arranger.map((obj) => obj.name).join(', ');
    if (trackParsedObject.arranger.some((obj) => obj.nameLatin !== null)) {
      document.getElementById('trackInfoModal2-metadataTable-arranger').setAttribute('data-bs-toggle', 'tooltip');
      document.getElementById('trackInfoModal2-metadataTable-arranger').setAttribute('data-bs-title', trackParsedObject.arranger.map((obj) => {if (obj.nameLatin !== null) {return obj.nameLatin} else {return obj.name}}).join(', '));
    } else {
      document.getElementById('trackInfoModal2-metadataTable-arranger').removeAttribute('data-bs-toggle');
      document.getElementById('trackInfoModal2-metadataTable-arranger').removeAttribute('data-bs-title');
    }
  }
  document.getElementById('trackInfoModal2-metadataTable-trackDurationReadable').innerHTML = msecToReadableTime(trackParsedObject.durationMsecs);
  document.getElementById('trackInfoModal2-metadataTable-trackDurationMsec').innerHTML = `${Math.ceil(trackParsedObject.durationMsecs)} ms`;
  document.getElementById('trackInfoModal2-metadataTable-trackDurationSamples').innerHTML = `${trackParsedObject.durationSamples} samples`;
  document.getElementById('trackInfoModal2-metadataTable-albumTitle').innerHTML = albumParsedObject.title;
  if (albumParsedObject.titleLatin === null) {
    document.getElementById('trackInfoModal2-metadataTable-albumTitle').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal2-metadataTable-albumTitle').removeAttribute('data-bs-title');
  } else {
    document.getElementById('trackInfoModal2-metadataTable-albumTitle').setAttribute('data-bs-toggle', 'tooltip');
    document.getElementById('trackInfoModal2-metadataTable-albumTitle').setAttribute('data-bs-title', albumParsedObject.titleLatin);
  }
  document.getElementById('trackInfoModal2-metadataTable-albumArtist').innerHTML = albumParsedObject.artist.map((obj) => obj.name).join(', ');
  if (albumParsedObject.artist.some((obj) => obj.nameLatin !== null)) {
    document.getElementById('trackInfoModal2-metadataTable-albumArtist').setAttribute('data-bs-toggle', 'tooltip');
    document.getElementById('trackInfoModal2-metadataTable-albumArtist').setAttribute('data-bs-title', albumParsedObject.artist.map((obj) => {if (obj.nameLatin !== null) {return obj.nameLatin} else {return obj.name}}).join(', '));
  } else {
    document.getElementById('trackInfoModal2-metadataTable-albumArtist').removeAttribute('data-bs-toggle');
    document.getElementById('trackInfoModal2-metadataTable-albumArtist').removeAttribute('data-bs-title');
  }
  document.getElementById('trackInfoModal2-metadataTable-albumReleaseDate').innerHTML = moment(albumParsedObject.releaseDate).format('YYYY/MM/DD');
  document.getElementById('trackInfoModal2-metadataTable-albumBarcode').innerHTML = albumParsedObject.barCode;
  document.getElementById('trackInfoModal2-metadataTable-albumCopyright').innerHTML = albumParsedObject.copyright;
  while(document.getElementById('trackInfoModal2-externalLinkTable').firstChild) {
    document.getElementById('trackInfoModal2-externalLinkTable').removeChild(document.getElementById('trackInfoModal2-externalLinkTable').firstChild);
  }
  while(document.getElementById('trackInfoModal2-coverArtLinkDiv').firstChild) {
    document.getElementById('trackInfoModal2-coverArtLinkDiv').removeChild(document.getElementById('trackInfoModal2-coverArtLinkDiv').firstChild);
  }
  while(document.getElementById('trackInfoModal2-downloadTable').firstChild) {
    document.getElementById('trackInfoModal2-downloadTable').removeChild(document.getElementById('trackInfoModal2-downloadTable').firstChild);
  }
  if (albumParsedObject.link.itunes !== null || albumParsedObject.link.spotify !== null) {
    let temp_extLinkAlbumTrEl = document.createElement('tr');
    let temp_extLinkAlbumTdKeyEl = document.createElement('td');
    let temp_extLinkAlbumTdValueEl = document.createElement('td');
    let temp_extLinkAlbumA1El = document.createElement('a');
    let temp_extLinkAlbumA2El = document.createElement('a');
    temp_extLinkAlbumTdKeyEl.innerHTML = 'Album Link';
    if (albumParsedObject.link.itunes !== null) {
      temp_extLinkAlbumA1El.classList.add('btn','btn-outline-primary','btn-sm','me-2');
      temp_extLinkAlbumA1El.setAttribute('href', `https://music.apple.com/album/${albumParsedObject.link.itunes}`);
      temp_extLinkAlbumA1El.setAttribute('role', 'button');
      temp_extLinkAlbumA1El.setAttribute('target', '_blank');
      temp_extLinkAlbumA1El.setAttribute('rel', 'noopener noreferrer');
      temp_extLinkAlbumA1El.innerHTML = 'Apple Music';
      temp_extLinkAlbumTdValueEl.appendChild(temp_extLinkAlbumA1El);
    }
    if (albumParsedObject.link.spotify !== null) {
      temp_extLinkAlbumA2El.classList.add('btn','btn-outline-primary','btn-sm','me-2');
      temp_extLinkAlbumA2El.setAttribute('href', `https://open.spotify.com/album/${albumParsedObject.link.spotify}`);
      temp_extLinkAlbumA2El.setAttribute('role', 'button');
      temp_extLinkAlbumA2El.setAttribute('target', '_blank');
      temp_extLinkAlbumA2El.setAttribute('rel', 'noopener noreferrer');
      temp_extLinkAlbumA2El.innerHTML = 'Spotify';
      temp_extLinkAlbumTdValueEl.appendChild(temp_extLinkAlbumA2El);
    }
    temp_extLinkAlbumTrEl.appendChild(temp_extLinkAlbumTdKeyEl);
    temp_extLinkAlbumTrEl.appendChild(temp_extLinkAlbumTdValueEl);
    document.getElementById('trackInfoModal2-externalLinkTable').appendChild(temp_extLinkAlbumTrEl);
  }
  albumParsedObject.coverArts.forEach((obj1) => {
    obj1.format.forEach((obj2) => {
      let temp_coverArtAEl = document.createElement('a');
      temp_coverArtAEl.classList.add('btn','btn-primary','btn-sm','me-2','mb-2');
      temp_coverArtAEl.setAttribute('href', `${apiDataConfig.response.config.decrypted.rawMediaUrlBase64}/media/${albumParsedObject.uuid}/${obj1.fileName}.${obj2.extension}`);
      temp_coverArtAEl.setAttribute('role', 'button');
      temp_coverArtAEl.setAttribute('target', '_blank');
      temp_coverArtAEl.setAttribute('rel', 'noopener noreferrer');
      temp_coverArtAEl.innerHTML = `${obj2.name} ${obj1.height}px`;
      document.getElementById('trackInfoModal2-coverArtLinkDiv').appendChild(temp_coverArtAEl);
    });
  });
  let temp_codecListImported = new Array();
  if (albumParsedObject.isAllTrackSameCodecs === false) {temp_codecListImported = trackParsedObject.codecs} else {temp_codecListImported = albumParsedObject.codecs}
  temp_codecListImported.forEach((obj) => {
    let temp_dlTrEl = document.createElement('tr');
    let temp_dlTdCodecEl = document.createElement('td');
    let temp_dlTdInfoEl = document.createElement('td');
    let temp_dlTdBtnEl = document.createElement('td');
    let temp_dlButtonGroupEl = document.createElement('div');
    let temp_dlButtonEl = document.createElement('button');
    let temp_dlButtonExtEl = document.createElement('a');
    let temp_dlButtonIconEl = document.createElement('i');
    let temp_dlButtonExtIconEl = document.createElement('i');
    let temp_codecBitrateTemporal = null;
    temp_dlTdCodecEl.innerHTML = obj.nameBasic;
    temp_dlTdCodecEl.setAttribute('data-bs-toggle', 'tooltip');
    temp_dlTdCodecEl.setAttribute('data-bs-title', obj.nameLong);
    if ((obj.bitRateAvg !== null && obj.bitRateMax !== null) || (obj.bitRateAvg !== null && obj.bitRateMax === null)) {
      temp_codecBitrateTemporal = obj.bitRateAvg;
    } else {
      temp_codecBitrateTemporal = obj.bitRateMax;
    }
    if (obj.bitDepth === null) {
      temp_dlTdInfoEl.innerHTML = `${obj.sampleRate / 1000}kHz ${obj.channelCount}ch ${temp_codecBitrateTemporal / 1000}kbps`;
    } else {
      temp_dlTdInfoEl.innerHTML = `${obj.bitDepth}bit ${obj.sampleRate / 1000}kHz ${obj.channelCount}ch ${temp_codecBitrateTemporal / 1000}kbps`;
    }
    if (obj.isOriginal === true) {
      temp_dlButtonEl.classList.add('btn', 'btn-primary');
      temp_dlButtonExtEl.classList.add('btn', 'btn-primary', 'text-center');
    } else {
      temp_dlButtonEl.classList.add('btn', 'btn-secondary');
      temp_dlButtonExtEl.classList.add('btn', 'btn-secondary', 'text-center');
    }
    temp_dlButtonEl.setAttribute('type', 'button');
    // temp_dlButtonEl.addEventListener('click', async () => {
    //   await downloadAudioDataToBlob (trackParsedObject.uuid, obj.uuid)
    // })
    temp_dlButtonExtEl.setAttribute('href', `${apiDataConfig.response.config.decrypted.rawMediaUrlBase64}/media/${albumParsedObject.uuid}/${obj.path}/${trackParsedObject.uuid}.${obj.extension}`);
    temp_dlButtonExtEl.setAttribute('download', determineDownloadFileName(trackParsedObject.uuid, obj.uuid));
    temp_dlButtonExtEl.setAttribute('role', 'button');
    temp_dlButtonExtEl.setAttribute('target', '_blank');
    temp_dlButtonExtEl.setAttribute('rel', 'noopener noreferrer');
    temp_dlButtonGroupEl.setAttribute('role', 'group');
    temp_dlButtonGroupEl.classList.add('btn-group');
    temp_dlButtonIconEl.classList.add('bi', 'bi-download');
    temp_dlButtonExtIconEl.classList.add('bi', 'bi-box-arrow-up-right');
    temp_dlTdBtnEl.classList.add('text-end');
    temp_dlButtonEl.appendChild(temp_dlButtonIconEl);
    temp_dlButtonExtEl.appendChild(temp_dlButtonExtIconEl);
    // temp_dlButtonGroupEl.appendChild(temp_dlButtonEl);
    temp_dlButtonGroupEl.appendChild(temp_dlButtonExtEl);
    temp_dlTdBtnEl.appendChild(temp_dlButtonGroupEl);
    temp_dlTrEl.appendChild(temp_dlTdCodecEl);
    temp_dlTrEl.appendChild(temp_dlTdInfoEl);
    temp_dlTrEl.appendChild(temp_dlTdBtnEl);
    document.getElementById('trackInfoModal2-downloadTable').appendChild(temp_dlTrEl);
  });
  document.getElementById('trackInfoModal2-previewAudio').src = `${apiDataConfig.response.config.decrypted.rawMediaUrlBase64}/media/${albumParsedObject.uuid}/${temp_codecListImported.slice(-1)[0].path}/${trackParsedObject.uuid}.${temp_codecListImported.slice(-1)[0].extension}`;
  const bootstrapTooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
  bootstrapTooltipList = [...bootstrapTooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
  document.getElementById('trackInfoModal2-DebugAcdOutputEl').innerHTML = JSON.stringify(albumParsedObject, '', '  ');
  document.getElementById('trackInfoModal2-ModalCloseButton').addEventListener('click', () => {allAudioElementStop()});
  document.getElementById('trackInfoModal2-ModalCloseIconButton').addEventListener('click', () => {allAudioElementStop()});
  const trackInfoModal2 = new bootstrap.Modal(document.getElementById('trackInfoModal2'));
  trackInfoModal2.show();
}

// ========== albumInfoModalの処理 ==========

function loadAlbumInfoModal (albumUuid) {
  // Parse Album from DB
  const albumParsedObject = getParsedAlbumObjectFromAlbumUuid(albumUuid);
  // Metadata label build
  if (bootstrapTooltipList !== null) {bootstrapTooltipList.forEach(el => el.dispose())};
  document.getElementById('albumInfoModal-metadataTable-albumTitle').innerHTML = albumParsedObject.title;
  if (albumParsedObject.titleLatin === null) {
    document.getElementById('albumInfoModal-metadataTable-albumTitle').removeAttribute('data-bs-toggle');
    document.getElementById('albumInfoModal-metadataTable-albumTitle').removeAttribute('data-bs-title');
  } else {
    document.getElementById('albumInfoModal-metadataTable-albumTitle').setAttribute('data-bs-toggle', 'tooltip');
    document.getElementById('albumInfoModal-metadataTable-albumTitle').setAttribute('data-bs-title', albumParsedObject.titleLatin);
  }
  document.getElementById('albumInfoModal-metadataTable-albumArtist').innerHTML = albumParsedObject.artist.map((obj) => obj.name).join(', ');
  if (albumParsedObject.artist.some((obj) => obj.nameLatin !== null)) {
    document.getElementById('albumInfoModal-metadataTable-albumArtist').setAttribute('data-bs-toggle', 'tooltip');
    document.getElementById('albumInfoModal-metadataTable-albumArtist').setAttribute('data-bs-title', albumParsedObject.artist.map((obj) => {if (obj.nameLatin !== null) {return obj.nameLatin} else {return obj.name}}).join(', '));
  } else {
    document.getElementById('albumInfoModal-metadataTable-albumArtist').removeAttribute('data-bs-toggle');
    document.getElementById('albumInfoModal-metadataTable-albumArtist').removeAttribute('data-bs-title');
  }
  document.getElementById('albumInfoModal-metadataTable-albumReleaseDate').innerHTML = moment(albumParsedObject.releaseDate).format('YYYY/MM/DD');
  document.getElementById('albumInfoModal-metadataTable-albumBarcode').innerHTML = albumParsedObject.barCode;
  document.getElementById('albumInfoModal-metadataTable-albumCopyright').innerHTML = albumParsedObject.copyright;
  // Table clear el
  while(document.getElementById('albumInfoModal-externalLinkTable').firstChild) {
    document.getElementById('albumInfoModal-externalLinkTable').removeChild(document.getElementById('albumInfoModal-externalLinkTable').firstChild);
  }
  while(document.getElementById('albumInfoModal-coverArtLinkDiv').firstChild) {
    document.getElementById('albumInfoModal-coverArtLinkDiv').removeChild(document.getElementById('albumInfoModal-coverArtLinkDiv').firstChild);
  }
  // External link table build
  if (albumParsedObject.link.itunes !== null || albumParsedObject.link.spotify !== null) {
    let temp_extLinkAlbumTrEl = document.createElement('tr');
    let temp_extLinkAlbumTdKeyEl = document.createElement('td');
    let temp_extLinkAlbumTdValueEl = document.createElement('td');
    let temp_extLinkAlbumA1El = document.createElement('a');
    let temp_extLinkAlbumA2El = document.createElement('a');
    temp_extLinkAlbumTdKeyEl.innerHTML = 'Album Link';
    if (albumParsedObject.link.itunes !== null) {
      temp_extLinkAlbumA1El.classList.add('btn','btn-outline-primary','btn-sm','me-2');
      temp_extLinkAlbumA1El.setAttribute('href', `https://music.apple.com/album/${albumParsedObject.link.itunes}`);
      temp_extLinkAlbumA1El.setAttribute('role', 'button');
      temp_extLinkAlbumA1El.setAttribute('target', '_blank');
      temp_extLinkAlbumA1El.setAttribute('rel', 'noopener noreferrer');
      temp_extLinkAlbumA1El.innerHTML = 'Apple Music';
      temp_extLinkAlbumTdValueEl.appendChild(temp_extLinkAlbumA1El);
    }
    if (albumParsedObject.link.spotify !== null) {
      temp_extLinkAlbumA2El.classList.add('btn','btn-outline-primary','btn-sm','me-2');
      temp_extLinkAlbumA2El.setAttribute('href', `https://open.spotify.com/album/${albumParsedObject.link.spotify}`);
      temp_extLinkAlbumA2El.setAttribute('role', 'button');
      temp_extLinkAlbumA2El.setAttribute('target', '_blank');
      temp_extLinkAlbumA2El.setAttribute('rel', 'noopener noreferrer');
      temp_extLinkAlbumA2El.innerHTML = 'Spotify';
      temp_extLinkAlbumTdValueEl.appendChild(temp_extLinkAlbumA2El);
    }
    temp_extLinkAlbumTrEl.appendChild(temp_extLinkAlbumTdKeyEl);
    temp_extLinkAlbumTrEl.appendChild(temp_extLinkAlbumTdValueEl);
    document.getElementById('albumInfoModal-externalLinkTable').appendChild(temp_extLinkAlbumTrEl);
  }
  // Cover art button build
  albumParsedObject.coverArts.forEach((obj1) => {
    obj1.format.forEach((obj2) => {
      let temp_coverArtAEl = document.createElement('a');
      temp_coverArtAEl.classList.add('btn','btn-primary','btn-sm','me-2','mb-2');
      temp_coverArtAEl.setAttribute('href', `${apiDataConfig.response.config.decrypted.rawMediaUrlBase64}/media/${albumParsedObject.uuid}/${obj1.fileName}.${obj2.extension}`);
      temp_coverArtAEl.setAttribute('role', 'button');
      temp_coverArtAEl.setAttribute('target', '_blank');
      temp_coverArtAEl.setAttribute('rel', 'noopener noreferrer');
      temp_coverArtAEl.innerHTML = `${obj2.name} ${obj1.height}px`;
      document.getElementById('albumInfoModal-coverArtLinkDiv').appendChild(temp_coverArtAEl);
    });
  });
  // Tooltip initialize
  const bootstrapTooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
  bootstrapTooltipList = [...bootstrapTooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
  // Modal Initialize
  const albumInfoModal = new bootstrap.Modal(document.getElementById('albumInfoModal'));

  // Track List build
  const albumTrackAllListGroup = document.querySelector('#albumInfoModal-trackAllListGroup');
  while(albumTrackAllListGroup.firstChild) {
    albumTrackAllListGroup.removeChild(albumTrackAllListGroup.firstChild);
  }
  let headerElObj = new Object();
  headerElObj.buttonNodeEl = document.createElement('button');
  headerElObj.divArtistNodeEl = document.createElement('div');
  headerElObj.divTrackNodeEl = document.createElement('div');
  headerElObj.buttonNodeEl.classList.add('list-group-item', 'list-group-item-action', 'd-flex');
  headerElObj.buttonNodeEl.setAttribute('type', 'button');
  headerElObj.buttonNodeEl.disabled = true;
  headerElObj.divArtistNodeEl.classList.add('flex-fill', 'w-100');
  headerElObj.divTrackNodeEl.classList.add('flex-fill', 'w-100');
  headerElObj.divArtistNodeEl.innerHTML = 'Artist';
  headerElObj.divTrackNodeEl.innerHTML = 'Track';
  headerElObj.buttonNodeEl.appendChild(headerElObj.divArtistNodeEl);
  headerElObj.buttonNodeEl.appendChild(headerElObj.divTrackNodeEl);
  albumTrackAllListGroup.appendChild(headerElObj.buttonNodeEl);
  albumParsedObject.tracks.forEach((trackParsedObject) => {
    let buttonNodeEl = document.createElement('button');
    let divArtistNodeEl = document.createElement('div');
    let divTrackNodeEl = document.createElement('div');
    buttonNodeEl.classList.add('list-group-item', 'list-group-item-action', 'd-flex');
    buttonNodeEl.setAttribute('type', 'button');
    buttonNodeEl.setAttribute('data-track-uuid', trackParsedObject.uuid);
    divArtistNodeEl.classList.add('flex-fill', 'w-100');
    divTrackNodeEl.classList.add('flex-fill', 'w-100');
    divArtistNodeEl.innerHTML = trackParsedObject.artist.map((obj) => obj.name).join(', ');
    divTrackNodeEl.innerHTML = trackParsedObject.title;
    buttonNodeEl.appendChild(divArtistNodeEl);
    buttonNodeEl.appendChild(divTrackNodeEl);
    buttonNodeEl.addEventListener('click', () => {
      albumInfoModal.hide();
      loadTrackInfoModal2(trackParsedObject.uuid)
    });
    albumTrackAllListGroup.appendChild(buttonNodeEl);
  });
  
  // Show modal
  albumInfoModal.show();
}

// ========== 設定画面のイベントリスナー登録など ==========

document.querySelector('#settingsApplyButton').addEventListener('click', () => {appSettingsApply()});
document.querySelector('#settingsUiSwitchUiModeDiv').addEventListener('click', function () {
  appSettingsSaveData.ui.uiThemeMode = document.querySelector('#settingsUiSwitchUiMode').elements['settingsUiSwitchUiMode'].value;
  console.log('settingsUiSwitchUiMode div clicked!');
});


// ========== 設定を変更後に保存、反映させる(ボタン押したときの動作) ==========

function appSettingsApply () {
  writeAppSettingsToLocalStorage();
  switch (appSettingsSaveData.ui.uiThemeMode) {
    case 'light':
      document.querySelector('html').setAttribute('data-bs-theme', 'light');
      document.querySelector('html').setAttribute('data-mdb-theme', 'light');
      break;
    case 'dark':
      document.querySelector('html').setAttribute('data-bs-theme', 'dark');
      document.querySelector('html').setAttribute('data-mdb-theme', 'dark');
  }
}

// ========== appSettingsを元に設定画面の選択状態を更新 ==========

function appSettingsCheckedUiUpdate () {
  const settingsUiSwitchUiModeElements = document.querySelector('#settingsUiSwitchUiMode').elements;
  for (let i = 0; i < settingsUiSwitchUiModeElements.length; i++) {
    if (settingsUiSwitchUiModeElements[i].value === appSettingsSaveData.ui.uiThemeMode) {
      settingsUiSwitchUiModeElements[i].checked = true;
    } else {
      settingsUiSwitchUiModeElements[i].checked = false;
    }
  }
}

// ========== API関連の関数など ==========

async function apiConnect (axiosObj) {
  let connectionTimerStart = performance.now();
  try {
    const response = await axios(axiosObj);
    let connectionTimerEnd = performance.now();
    return {
      'apiConnectionTime': connectionTimerEnd - connectionTimerStart,
      'response': response.data
    };
  } catch (error) {
    let connectionTimerEnd = performance.now();
    console.error(`API request failed: ${error.code}`);
    alert(`API request failed: ${error.code}`);
    throw error;
  }
}

async function loadRequiredDatabase () {
  document.querySelectorAll('.fetchingDataNowLabel').forEach((el) => {
    el.classList.remove('d-none');
  });
  apiDataMasterDB = await apiConnect({
    'method': 'get',
    'url': `./db/master.json`,
    'headers': apiConnectDefaultHeader,
    'timeout': internalConfig.network.timeout
  });
  apiDataConfig = await apiConnect({
    'method': 'get',
    'url': `./config.json`,
    'headers': apiConnectDefaultHeader,
    'timeout': internalConfig.network.timeout
  });
  if (apiDataMasterDB) {
    document.querySelector('#databaseTestInfoCodeEl').innerHTML = `OK (Time: ${Math.ceil(apiDataMasterDB.apiConnectionTime)} ms)`;
    document.querySelector('#databaseTestOutputCodeEl').innerHTML = JSON.stringify(apiDataMasterDB.response, '', '  ');
  } else {
    document.querySelector('#databaseTestInfoCodeEl').innerHTML = `Failed`;
  }
  document.querySelectorAll('.fetchingDataNowLabel').forEach((el) => {
    el.classList.add('d-none');
  });
}

// ========== データベース内部検索などの処理 ==========

function getAlbumUuidFromTrackUuid (trackUuid) {
  let albumUuid = null;
  apiDataMasterDB.response.data.albums.forEach((albumObject) => {
    if (albumObject.tracks.some((trackObject) => trackObject.uuid === trackUuid)) {
      albumUuid = albumObject.uuid;
    }
  });
  return albumUuid;
}

function getDbObjectFromUuid (uuid, type) {
  switch (type) {
    case 'album':
      if (apiDataMasterDB.response.data.albums.some((albumObject) => albumObject.uuid === uuid)) {
        return apiDataMasterDB.response.data.albums.filter((albumObject) => albumObject.uuid === uuid)[0];
      } else {
        return null;
      }
    case 'track':
      apiDataMasterDB.response.data.albums.forEach((albumObject) => {
        if (albumObject.tracks.some((trackObject) => trackObject.uuid === uuid)) {
          return albumObject.tracks.filter((trackObject) => trackObject.uuid === uuid)[0];
        }
      });
      return null;
    case 'artist':
      if (apiDataMasterDB.response.data.artists.some((artistObject) => artistObject.uuid === uuid)) {
        return apiDataMasterDB.response.data.artists.filter((artistObject) => artistObject.uuid === uuid)[0];
      } else {
        return null;
      }
    case 'codec':
      if (apiDataMasterDB.response.data.codecs.some((codecObject) => codecObject.uuid === uuid)) {
        return apiDataMasterDB.response.data.codecs.filter((codecObject) => codecObject.uuid === uuid)[0];
      } else {
        return null;
      }
    default:
      throw new Error ('unexpected type');
  }
}

function getParsedAlbumObjectFromAlbumUuid (uuid) {
  const rawAlbumObject = getDbObjectFromUuid(uuid, 'album');
  let outputObject = JSON.parse(JSON.stringify(rawAlbumObject));
  outputObject.artist = new Array();
  rawAlbumObject.artist.forEach((artistUuidStr) => {
    outputObject.artist.push(getDbObjectFromUuid(artistUuidStr, 'artist'));
  });
  if (rawAlbumObject.isAllTrackSameCodecs === true) {
    outputObject.codecs = new Array();
    rawAlbumObject.codecs.forEach((codecObj) => {
      let temp_searchedCodecObj = new Object();
      temp_searchedCodecObj = getDbObjectFromUuid(codecObj.uuid, 'codec');
      temp_searchedCodecObj.isOriginal = codecObj.isOriginal;
      temp_searchedCodecObj.path = codecObj.path;
      outputObject.codecs.push(temp_searchedCodecObj);
    });
  }
  if (rawAlbumObject.isCoverArtsUseDefault === true) {
    outputObject.coverArts = apiDataMasterDB.response.data.coverArtDefaults;
  }
  outputObject.tracks = new Array();
  rawAlbumObject.tracks.forEach((rawTrackObj) => {
    let temp_outputTrackObj = new Object();
    temp_outputTrackObj = JSON.parse(JSON.stringify(rawTrackObj));
    temp_outputTrackObj.artist = new Array();
    rawTrackObj.artist.forEach((artistUuidStr) => {
      temp_outputTrackObj.artist.push(getDbObjectFromUuid(artistUuidStr, 'artist'));
    });
    if (rawTrackObj.lyricist !== null) {
      temp_outputTrackObj.lyricist = new Array();
      rawTrackObj.lyricist.forEach((artistUuidStr) => {
        temp_outputTrackObj.lyricist.push(getDbObjectFromUuid(artistUuidStr, 'artist'));
      });
    }
    if (rawTrackObj.composer !== null) {
      temp_outputTrackObj.composer = new Array();
      rawTrackObj.composer.forEach((artistUuidStr) => {
        temp_outputTrackObj.composer.push(getDbObjectFromUuid(artistUuidStr, 'artist'));
      });
    }
    if (rawTrackObj.arranger !== null) {
      temp_outputTrackObj.arranger = new Array();
      rawTrackObj.arranger.forEach((artistUuidStr) => {
        temp_outputTrackObj.arranger.push(getDbObjectFromUuid(artistUuidStr, 'artist'));
      });
    }
    if (rawAlbumObject.isAllTrackSameCodecs === false || rawTrackObj.codecs !== null) {
      temp_outputTrackObj.codecs = new Array();
      rawTrackObj.codecs.forEach((codecObj) => {
        let temp_searchedCodecObj2 = new Object();
        temp_searchedCodecObj2 = getDbObjectFromUuid(codecObj.uuid, 'codec');
        temp_searchedCodecObj2.isOriginal = codecObj.isOriginal;
        temp_searchedCodecObj2.path = codecObj.path;
        temp_outputTrackObj.codecs.push(temp_searchedCodecObj2);
      });
      temp_outputTrackObj.durationMsecs = (rawTrackObj.durationSamples / temp_outputTrackObj.codecs.filter((t) => t.isOriginal === true)[0].sampleRate) * 1000;
    } else {
      temp_outputTrackObj.durationMsecs = (rawTrackObj.durationSamples / outputObject.codecs.filter((t) => t.isOriginal === true)[0].sampleRate) * 1000;
    }
    outputObject.tracks.push(temp_outputTrackObj);
  });
  let temp_albumTotalDurationSamples = 0;
  let temp_albumTotalDurationMsecs = 0;
  for (let i = 0; i < rawAlbumObject.tracks.length; i++) {
    temp_albumTotalDurationSamples += outputObject.tracks[i].durationSamples;
    temp_albumTotalDurationMsecs += outputObject.tracks[i].durationMsecs;
  }
  outputObject.durationSamples = temp_albumTotalDurationSamples;
  outputObject.durationMsecs = temp_albumTotalDurationMsecs;
  return outputObject;
}

// ========== ファイルをDLしてBlob化、ブラウザに開かせる ==========

async function downloadAudioDataToBlob (trackUuid, codecUuid) {
  const albumParsedObject = getParsedAlbumObjectFromAlbumUuid(getAlbumUuidFromTrackUuid(trackUuid));
  const trackParsedObject = albumParsedObject.tracks.find((obj) => obj.uuid === trackUuid);
  let codecParsedObject = null;
  if (albumParsedObject.isAllTrackSameCodecs === false) {
    codecParsedObject = trackParsedObject.codecs.find((obj) => obj.uuid === codecUuid);
  } else {
    codecParsedObject = albumParsedObject.codecs.find((obj) => obj.uuid === codecUuid);
  }
  const axiosRes = await apiConnect ({
    'method': 'get',
    'url': `${apiDataConfig.response.config.decrypted.rawMediaUrlBase64}/media/${albumParsedObject.uuid}/${codecParsedObject.path}/${trackParsedObject.uuid}.${codecParsedObject.extension}`,
    'headers': apiConnectDefaultHeader,
    'timeout': internalConfig.network.timeout,
    'responseType': 'blob'
  });
  console.log(`File downloaded to Blob\nDownload time: ${axiosRes.apiConnectionTime} ms`);
  const blobUrl = window.URL.createObjectURL(response.data);
  const link = document.createElement('a');
  let saveFileName = null;
  if (trackParsedObject.titleFileName !== null) {
    saveFileName = `${trackParsedObject.disc}_${('00' + trackParsedObject.index).slice(-2)}_${trackParsedObject.titleFileName}.${codecParsedObject.extension}`;
  } else {
    saveFileName = `${trackParsedObject.disc}_${('00' + trackParsedObject.index).slice(-2)}_${trackParsedObject.title}.${codecParsedObject.extension}`;
  }
  link.href = blobUrl;
  link.setAttribute('download', saveFileName);
  link.classList.add('d-none');
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
}

function determineDownloadFileName (trackUuid, codecUuid) {
  const albumParsedObject = getParsedAlbumObjectFromAlbumUuid(getAlbumUuidFromTrackUuid(trackUuid));
  const trackParsedObject = albumParsedObject.tracks.find((obj) => obj.uuid === trackUuid);
  let codecParsedObject = null;
  if (albumParsedObject.isAllTrackSameCodecs === false) {
    codecParsedObject = trackParsedObject.codecs.find((obj) => obj.uuid === codecUuid);
  } else {
    codecParsedObject = albumParsedObject.codecs.find((obj) => obj.uuid === codecUuid);
  }
  let saveFileName = null;
  if (trackParsedObject.titleFileName !== null) {
    saveFileName = `${trackParsedObject.disc}_${('00' + trackParsedObject.index).slice(-2)}_${trackParsedObject.titleFileName}.${codecParsedObject.extension}`;
  } else {
    saveFileName = `${trackParsedObject.disc}_${('00' + trackParsedObject.index).slice(-2)}_${trackParsedObject.title}.${codecParsedObject.extension}`;
  }
  return saveFileName;
}

// ========== MasterDB/Configの暗号化を解く ==========

async function decryptConfig () {
  apiDataConfig.response.config.decrypted = new Object();
  console.log(`Decrypting config data using AES 128-bit CBC ...`)
  const encryptKey = await CryptoJS.enc.Hex.parse(CryptoJS.enc.Base64.parse(apiDataConfig.response.config.encryption.key.split('').reverse().join('')).toString(CryptoJS.enc.Utf8));
  const encryptIv = await CryptoJS.enc.Hex.parse(CryptoJS.enc.Base64.parse(apiDataConfig.response.config.encryption.iv.split('').reverse().join('')).toString(CryptoJS.enc.Utf8));
  Object.keys(apiDataConfig.response.config.encrypted).forEach(async function (keyName) {
    apiDataConfig.response.config.decrypted[keyName] = await CryptoJS.AES.decrypt({
      'ciphertext': CryptoJS.enc.Base64.parse(apiDataConfig.response.config.encrypted[keyName])
    }, encryptKey, {
      'iv': encryptIv,
      'mode': CryptoJS.mode.CBC,
      'padding': CryptoJS.pad.Pkcs7
    }).toString(CryptoJS.enc.Utf8);
  });
  console.log(`All config data has been decrypted`);
}

// ========== ブラウザのLocalStorageにあるAppSettingsを読み書きする ==========

function loadAppSettingsFromLocalStorage () {
  if (localStorage.hasOwnProperty(appSettingsStorageName)) {
    appSettingsSaveData = JSON.parse(CryptoJS.enc.Base64.parse(localStorage.getItem(appSettingsStorageName)).toString(CryptoJS.enc.Utf8));
    console.warn(`LocalStorage key detected`);
    console.log(`Loaded appSettings:\n${JSON.stringify(appSettingsSaveData)}`);
  } else {
    appSettingsSaveData = appSettingsSaveDataDefault;
    console.warn(`LocalStorage key not found\nUsing default settings`);
    writeAppSettingsToLocalStorage();
  }
}

function checkAppSettingsExistsOnStorage () {
  if (localStorage.hasOwnProperty(appSettingsStorageName)) {
    return true
  } else {
    return false
  }
}

function writeAppSettingsToLocalStorage () {
  // CryptoJS.enc.Utf8.parseを使うことでCryptoJS内部形式を強制
  localStorage.setItem(appSettingsStorageName, CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(JSON.stringify(appSettingsSaveData))));
  console.log(`Wrote appSettings:\n${JSON.stringify(appSettingsSaveData)}`);
}

// ========== 全てのAudio要素をStop ==========

function allAudioElementStop () {
  let audioElements = document.getElementsByTagName('audio');
  for (let i = 0; i < audioElements.length; i++) {
    audioElements[i].pause();
  }
}

// ========== その他使い回す汎用関数など ==========

function msecToReadableTime (msec) {
  let msecCeiled = Math.ceil(msec);
  let sec = msec / 1000;
  let min = ('00' + Math.floor(sec / 60)).slice(-2);
  let secPart = ('00' + Math.floor(sec % 60)).slice(-2);
  return `${min}:${secPart}.${('000' + msecCeiled % 1000).slice(-3)}`;
}