-
-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathAudio.service.bash
More file actions
1842 lines (1577 loc) · 81.8 KB
/
Copy pathAudio.service.bash
File metadata and controls
1842 lines (1577 loc) · 81.8 KB
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/with-contenv bash
scriptVersion="2.5"
scriptName="Audio"
### Import Settings
source /config/extended.conf
#### Import Functions
source /config/extended/functions
AddTag () {
log "adding arr-extended tag"
lidarrProcessIt=$(curl -s "$arrUrl/api/v1/tag" --header "X-Api-Key:"${arrApiKey} -H "Content-Type: application/json" --data-raw '{"label":"arr-extended"}')
}
AddDownloadClient () {
downloadClientsData=$(curl -s "$arrUrl/api/v1/downloadclient" --header "X-Api-Key:"${arrApiKey} -H "Content-Type: application/json")
downloadClientCheck="$(echo $downloadClientsData | grep "Arr-Extended")"
if [ -z "$downloadClientCheck" ]; then
AddTag
if [ ! -d "$importPath" ]; then
mkdir -p "$importPath"
chmod 777 -R "$importPath"
fi
log "Adding download Client"
lidarrProcessIt=$(curl -s "$arrUrl/api/v1/downloadclient" --header "X-Api-Key:"${arrApiKey} -H "Content-Type: application/json" --data-raw "{\"enable\":true,\"protocol\":\"usenet\",\"priority\":10,\"removeCompletedDownloads\":true,\"removeFailedDownloads\":true,\"name\":\"Arr-Extended\",\"fields\":[{\"name\":\"nzbFolder\",\"value\":\"$importPath\"},{\"name\":\"watchFolder\",\"value\":\"$importPath\"}],\"implementationName\":\"Usenet Blackhole\",\"implementation\":\"UsenetBlackhole\",\"configContract\":\"UsenetBlackholeSettings\",\"infoLink\":\"https://wiki.servarr.com/lidarr/supported#usenetblackhole\",\"tags\":[]}")
fi
}
verifyConfig () {
### Import Settings
source /config/extended.conf
if [ "$enableAudio" != "true" ]; then
log "Script is not enabled, enable by setting enableAudio to \"true\" by modifying the \"/config/extended.conf\" config file..."
log "Sleeping (infinity)"
sleep infinity
fi
if [ -z "$audioScriptInterval" ]; then
audioScriptInterval="15m"
fi
if [ -z "$downloadPath" ]; then
downloadPath="/config/extended/downloads"
fi
if [ -z "$importPath" ]; then
importPath="/config/extended/import"
fi
if [ -z "$failedDownloadAttemptThreshold" ]; then
failedDownloadAttemptThreshold="6"
fi
if [ -z "$tidalClientTestDownloadId" ]; then
tidalClientTestDownloadId="166356219"
fi
if [ -z "$deezerClientTestDownloadId" ]; then
deezerClientTestDownloadId="197472472"
fi
if [ -z "$ignoreInstrumentalRelease" ]; then
ignoreInstrumentalRelease="true"
fi
if [ -z "$downloadClientTimeOut" ]; then
downloadClientTimeOut="10m" # if not set, set to 10 minutes
fi
if [ -z "$preferSpecialEditions" ]; then
preferSpecialEditions="true"
fi
audioPath="$downloadPath/audio"
tidalDlNgConfigDir="/config/extended/tidal_dl_ng"
tidalDlNgConfigFile="${tidalDlNgConfigDir}/config.json"
tidalDlNgConfigTemplate="/config/extended/tidal-dl.json"
}
Configuration () {
sleepTimer=0.5
tidaldlFail=0
deemixFail=0
log "-----------------------------------------------------------------------------"
log " |~) _ ._ _| _ ._ _ |\ |o._ o _ |~|_|_|"
log " |~\(_|| |(_|(_)| | || \||| |_|(_||~| | |<"
log " Presents: $scriptName ($scriptVersion)"
log " May the beats be with you!"
log "-----------------------------------------------------------------------------"
log "Donate: https://github.com/sponsors/RandomNinjaAtk"
log "Project: https://github.com/RandomNinjaAtk/arr-scripts"
log "Support: https://github.com/RandomNinjaAtk/arr-scripts/discussions"
log "-----------------------------------------------------------------------------"
sleep 5
log ""
log "Lift off in..."; sleep 0.5
log "5"; sleep 1
log "4"; sleep 1
log "3"; sleep 1
log "2"; sleep 1
log "1"; sleep 1
if [ ! -d /config/extended ]; then
mkdir -p /config/extended
fi
if [ ! -d "$tidalDlNgConfigDir" ]; then
mkdir -p "$tidalDlNgConfigDir"
fi
if [ -z $topLimit ]; then
topLimit=10
fi
verifyApiAccess
AddDownloadClient
if [ "$addDeezerTopArtists" == "true" ]; then
log "Add Deezer Top $topLimit Artists is enabled"
else
log "Add Deezer Top Artists is disabled (enable by setting addDeezerTopArtists=true)"
fi
if [ "$addDeezerTopAlbumArtists" == "true" ]; then
log "Add Deezer Top $topLimit Album Artists is enabled"
else
log "Add Deezer Top Album Artists is disabled (enable by setting addDeezerTopAlbumArtists=true)"
fi
if [ "$addDeezerTopTrackArtists" == "true" ]; then
log "Add Deezer Top $topLimit Track Artists is enabled"
else
log "Add Deezer Top Track Artists is disabled (enable by setting addDeezerTopTrackArtists=true)"
fi
if [ "$addRelatedArtists" == "true" ]; then
log "Add Deezer Related Artists is enabled"
log "Add $numberOfRelatedArtistsToAddPerArtist Deezer related Artist for each Lidarr Artist"
else
log "Add Deezer Related Artists is disabled (enable by setting addRelatedArtists=true)"
fi
log "Download Location: $audioPath"
log "Output format: $audioFormat"
if [ "$audioFormat" != "native" ]; then
if [ "$audioFormat" == "alac" ]; then
audioBitrateText="LOSSLESS"
else
audioBitrateText="${audioBitrate}k"
fi
else
audioBitrateText="$audioBitrate"
fi
log "Output bitrate: $audioBitrateText"
if [ "$requireQuality" == "true" ]; then
log "Download Quality Check Enabled"
else
log "Download Quality Check Disabled (enable by setting: requireQuality=true"
fi
if [ "$audioLyricType" == "both" ] || [ "$audioLyricType" == "explicit" ] || [ "$audioLyricType" == "explicit" ]; then
log "Preferred audio lyric type: $audioLyricType"
fi
log "Tidal Country Code set to: $tidalCountryCode"
if [ "$enableReplaygainTags" == "true" ]; then
log "Replaygain Tagging Enabled"
else
log "Replaygain Tagging Disabled"
fi
log "Match Distance: $matchDistance"
if [ $enableBeetsTagging = true ]; then
log "Beets Tagging Enabled"
log "Beets Matching Threshold ${beetsMatchPercentage}%"
beetsMatchPercentage=$(expr 100 - $beetsMatchPercentage )
if cat /config/extended/beets-config.yaml | grep "strong_rec_thresh: 0.04" | read; then
log "Configuring Beets Matching Threshold"
sed -i "s/strong_rec_thresh: 0.04/strong_rec_thresh: 0.${beetsMatchPercentage}/g" /config/extended/beets-config.yaml
fi
else
log "Beets Tagging Disabled"
fi
if [ "$preferSpecialEditions" == "true" ]; then
log "Prefer Special Editions Enabled"
else
log "Prefer Special Editions Disabled"
fi
log "Failed Download Attempt Threshold: $failedDownloadAttemptThreshold"
}
DownloadClientFreyr () {
timeout $downloadClientTimeOut freyr --no-bar --no-net-check -d $audioPath/incomplete deezer:album:$1 2>&1 | tee -a "/config/logs/$logFileName"
# Resolve issue 94
if [ -d /root/.cache/FreyrCLI ]; then
rm -rf /root/.cache/FreyrCLI/*
fi
}
DownloadFormat () {
if [ "$audioFormat" == "native" ]; then
if [ "$audioBitrate" == "master" ]; then
tidalQuality=HI_RES_LOSSLESS
deemixQuality=flac
elif [ "$audioBitrate" == "lossless" ]; then
tidalQuality=LOSSLESS
deemixQuality=flac
elif [ "$audioBitrate" == "high" ]; then
tidalQuality=HIGH
deemixQuality=320
elif [ "$audioBitrate" == "low" ]; then
tidalQuality=LOW
deemixQuality=128
else
log "ERROR :: Invalid audioFormat and audioBitrate options set..."
log "ERROR :: Change audioBitrate to a low, high, or lossless..."
log "ERROR :: Exiting..."
NotifyWebhook "FatalError" "Invalid audioFormat and audioBitrate options set"
log "Script sleeping for $audioScriptInterval..."
sleep $audioScriptInterval
exit
fi
else
bitrateError="false"
audioFormatError="false"
tidalQuality=LOSSLESS
deemixQuality=flac
case "$audioBitrate" in
lossless | high | low)
bitrateError="true"
;;
*)
bitrateError="false"
;;
esac
if [ "$bitrateError" == "true" ]; then
log "ERROR :: Invalid audioBitrate options set..."
log "ERROR :: Change audioBitrate to a desired bitrate number, example: 192..."
log "ERROR :: Exiting..."
NotifyWebhook "FatalError" "audioBitrate options set"
log "Script sleeping for $audioScriptInterval..."
sleep $audioScriptInterval
exit
fi
case "$audioFormat" in
mp3 | alac | opus | aac)
audioFormatError="false"
;;
*)
audioFormatError="true"
;;
esac
if [ "$audioFormatError" == "true" ]; then
log "ERROR :: Invalid audioFormat options set..."
log "ERROR :: Change audioFormat to a desired format (opus or mp3 or aac or alac)"
NotifyWebhook "FatalError" "audioFormat options set"
log "Script sleeping for $audioScriptInterval..."
sleep $audioScriptInterval
exit
fi
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg quality_audio LOSSLESS 2>&1 | tee -a "/config/logs/$logFileName"
deemixQuality=flac
bitrateError=""
audioFormatError=""
fi
}
DownloadFolderCleaner () {
# check for completed download folder
if [ -d "$audioPath/complete" ]; then
log "Removing prevously completed downloads that failed to import..."
# check for completed downloads older than 1 day
if find "$audioPath"/complete -mindepth 1 -type d -mtime +1 | read; then
# delete completed downloads older than 1 day, these most likely failed to import due to Lidarr failing to match
find "$audioPath"/complete -mindepth 1 -type d -mtime +1 -exec rm -rf "{}" \; &>/dev/null
fi
fi
}
NotFoundFolderCleaner () {
# check for completed download folder
if [ -d /config/extended/logs/notfound ]; then
# check for notfound entries older than X days
if find /config/extended/logs/notfound -mindepth 1 -type f -mtime +$retryNotFound | read; then
log "Removing prevously notfound lidarr album ids older than $retryNotFound days to give them a retry..."
# delete ntofound entries older than X days
find /config/extended/logs/notfound -mindepth 1 -type f -mtime +$retryNotFound -delete
fi
fi
}
TidalClientSetup () {
log "TIDAL :: Verifying tidal-dl-ng configuration"
touch "${tidalDlNgConfigDir}/tidal-dl-ng.log"
if [ -f "$tidalDlNgConfigFile" ]; then
rm "$tidalDlNgConfigFile"
fi
if [ ! -f "$tidalDlNgConfigFile" ]; then
log "TIDAL :: No default config found, importing default config \"tidal-dl.json\""
if [ -f "$tidalDlNgConfigTemplate" ]; then
cp "$tidalDlNgConfigTemplate" "$tidalDlNgConfigFile"
chmod 777 -R "$tidalDlNgConfigDir"
fi
fi
TidaldlStatusCheck
DownloadFormat
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg download_base_path "$audioPath/incomplete" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg quality_audio "$tidalQuality" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg path_binary_ffmpeg "/usr/bin/ffmpeg" 2>&1 | tee -a "/config/logs/$logFileName"
if ! ls "${tidalDlNgConfigDir}"/*auth*.json "${tidalDlNgConfigDir}"/*token*.json 1>/dev/null 2>&1; then
TidaldlStatusCheck
log "TIDAL :: ERROR :: Loading client for required authentication, please authenticate, then exit the client..."
NotifyWebhook "FatalError" "TIDAL requires authentication, please authenticate now (check logs)"
TidaldlStatusCheck
if command -v script >/dev/null 2>&1; then
script -q -c "PYTHONUNBUFFERED=1 XDG_CONFIG_HOME=/config/extended tidal-dl-ng login" /dev/null
else
PYTHONUNBUFFERED=1 XDG_CONFIG_HOME=/config/extended tidal-dl-ng login
fi
fi
if [ ! -d /config/extended/cache/tidal ]; then
mkdir -p /config/extended/cache/tidal
chmod 777 /config/extended/cache/tidal
fi
if [ -d /config/extended/cache/tidal ]; then
log "TIDAL :: Purging album list cache..."
rm /config/extended/cache/tidal/*-albums.json &>/dev/null
fi
if [ ! -d "$audioPath/incomplete" ]; then
mkdir -p "$audioPath"/incomplete
chmod 777 "$audioPath"/incomplete
else
rm -rf "$audioPath"/incomplete/*
fi
TidaldlStatusCheck
}
TidaldlStatusCheck () {
until false
do
running=no
if ps aux | grep "tidal-dl-ng" | grep -v "grep" | read; then
running=yes
log "STATUS :: TIDAL-DL-NG :: BUSY :: Pausing/waiting for all active tidal-dl-ng tasks to end..."
sleep 2
continue
fi
break
done
}
TidalClientTest () {
log "TIDAL :: tidal-dl-ng client setup verification..."
i=0
while [ $i -lt 3 ]; do
i=$(( $i + 1 ))
TidaldlStatusCheck
XDG_CONFIG_HOME=/config/extended tidal-dl-ng dl "https://tidal.com/browse/album/$tidalClientTestDownloadId" 2>&1 | tee -a "/config/logs/$logFileName"
downloadCount=$(find "$audioPath"/incomplete -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)
if [ $downloadCount -le 0 ]; then
continue
else
break
fi
done
tidalClientTest="unknown"
if [ $downloadCount -le 0 ]; then
rm -f "${tidalDlNgConfigDir}"/*auth*.json "${tidalDlNgConfigDir}"/*token*.json
log "TIDAL :: ERROR :: Download failed"
log "TIDAL :: ERROR :: You will need to re-authenticate on next script run..."
log "TIDAL :: ERROR :: Exiting..."
rm -rf "$audioPath"/incomplete/*
NotifyWebhook "Error" "TIDAL not authenticated but configured"
tidalClientTest="failed"
log "Script sleeping for $audioScriptInterval..."
sleep $audioScriptInterval
exit
else
rm -rf "$audioPath"/incomplete/*
log "TIDAL :: Successfully Verified"
tidalClientTest="success"
fi
}
DownloadProcess () {
# Required Input Data
# $1 = Album ID to download from online Service
# $2 = Download Client Type (DEEZER or TIDAL)
# $3 = Album Year that matches Album ID Metadata
# $4 = Album Title that matches Album ID Metadata
# $5 = Expected Track Count
# Create Required Directories
if [ ! -d "$audioPath/incomplete" ]; then
mkdir -p "$audioPath"/incomplete
chmod 777 "$audioPath"/incomplete
else
rm -rf "$audioPath"/incomplete/*
fi
if [ ! -d "$audioPath/complete" ]; then
mkdir -p "$audioPath"/complete
chmod 777 "$audioPath"/complete
else
rm -rf "$audioPath"/complete/*
fi
if [ ! -d "/config/extended/logs" ]; then
mkdir -p /config/extended/logs
chmod 777 /config/extended/logs
fi
if [ ! -d "/config/extended/logs/downloaded" ]; then
mkdir -p /config/extended/logs/downloaded
chmod 777 /config/extended/logs/downloaded
fi
if [ ! -d "/config/extended/logs/downloaded/deezer" ]; then
mkdir -p /config/extended/logs/downloaded/deezer
chmod 777 /config/extended/logs/downloaded/deezer
fi
if [ ! -d "/config/extended/logs/downloaded/tidal" ]; then
mkdir -p /config/extended/logs/downloaded/tidal
chmod 777 /config/extended/logs/downloaded/tidal
fi
if [ ! -d /config/extended/logs/downloaded/failed/deezer ]; then
mkdir -p /config/extended/logs/downloaded/failed/deezer
chmod 777 /config/extended/logs/downloaded/failed/deezer
fi
if [ ! -d /config/extended/logs/downloaded/failed/tidal ]; then
mkdir -p /config/extended/logs/downloaded/failed/tidal
chmod 777 /config/extended/logs/downloaded/failed/tidal
fi
if [ ! -d "$importPath" ]; then
mkdir -p "$importPath"
chmod 777 "$importPath"
fi
AddDownloadClient
downloadedAlbumTitleClean="$(echo "$4" | sed -e "s%[^[:alpha:][:digit:]._' ]% %g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')"
if find "$audioPath"/complete -type d -iname "$lidarrArtistNameSanitized-$downloadedAlbumTitleClean ($3)-*-$1-$2" | read; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: Previously Downloaded..."
return
fi
# check for log file
if [ "$2" == "DEEZER" ]; then
if [ -f /config/extended/logs/downloaded/deezer/$1 ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: Previously Downloaded ($1)..."
return
fi
if [ -f /config/extended/logs/downloaded/failed/deezer/$1 ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: Previously Attempted Download ($1)..."
return
fi
fi
# check for log file
if [ "$2" == "TIDAL" ]; then
if [ -f /config/extended/logs/downloaded/tidal/$1 ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: Previously Downloaded ($1)..."
return
fi
if [ -f /config/extended/logs/downloaded/failed/tidal/$1 ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: Previously Attempted Download ($1)..."
return
fi
fi
downloadTry=0
until false
do
downloadTry=$(( $downloadTry + 1 ))
if [ -f /temp-download ]; then
rm /temp-download
sleep 0.1
fi
touch /temp-download
sleep 0.1
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Download Attempt number $downloadTry"
if [ "$2" == "DEEZER" ]; then
if [ -z $arlToken ]; then
DownloadClientFreyr $1
else
deemix -b $deemixQuality -p "$audioPath"/incomplete "https://www.deezer.com/album/$1" 2>&1 | tee -a "/config/logs/$logFileName"
fi
if [ -d "/tmp/deemix-imgs" ]; then
rm -rf /tmp/deemix-imgs
fi
# Verify Client Works...
clientTestDlCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)
if [ $clientTestDlCount -le 0 ]; then
# Add +1 to failed attempts
deemixFail=$(( $deemixFail + 1))
else
# Reset for successful download
deemixFail=0
fi
# If download failes X times, exit with error...
if [ $deemixFail -eq $failedDownloadAttemptThreshold ]; then
if [ -z $arlToken ]; then
rm -rf "$audioPath"/incomplete/*
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: All $failedDownloadAttemptThreshold Download Attempts failed, skipping..."
else
DeezerClientTest
if [ "$deezerClientTest" == "success" ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: All $failedDownloadAttemptThreshold Download Attempts failed, skipping..."
deemixFail=0
fi
fi
fi
fi
if [ "$2" == "DEEZER" ]; then
if [ $deemixFail -eq $failedDownloadAttemptThreshold ]; then
if [ -z $arlToken ]; then
DownloadClientFreyr $1
else
deemix -b $deemixQuality -p "$audioPath"/incomplete "https://www.deezer.com/album/$1" 2>&1 | tee -a "/config/logs/$logFileName"
fi
fi
fi
if [ "$2" == "TIDAL" ]; then
TidaldlStatusCheck
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg download_base_path "$audioPath/incomplete" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg quality_audio "$tidalQuality" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng dl "https://tidal.com/browse/album/$1" 2>&1 | tee -a "/config/logs/$logFileName"
# Verify Client Works...
clientTestDlCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)
if [ $clientTestDlCount -le 0 ]; then
# Add +1 to failed attempts
tidaldlFail=$(( $tidaldlFail + 1))
else
# Reset for successful download
tidaldlFail=0
fi
# If download failes X times, exit with error...
if [ $tidaldlFail -eq $failedDownloadAttemptThreshold ]; then
TidalClientTest
if [ "$tidalClientTest" == "success" ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: All $failedDownloadAttemptThreshold Download Attempts failed, skipping..."
fi
fi
fi
find "$audioPath/incomplete" -type f -iname "*.flac" -newer "/temp-download" -print0 | while IFS= read -r -d '' file; do
audioFlacVerification "$file"
if [ "$verifiedFlacFile" == "0" ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Flac Verification :: $file :: Verified"
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Flac Verification :: $file :: ERROR :: Failed Verification"
rm "$file"
fi
done
downloadCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|m4a\|mp3\)" | wc -l)
if [ "$downloadCount" -ne "$5" ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: download failed, missing tracks..."
completedVerification="false"
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Success"
completedVerification="true"
fi
if [ "$completedVerification" == "true" ]; then
break
elif [ "$downloadTry" == "2" ]; then
if [ -d "$audioPath"/incomplete ]; then
rm -rf "$audioPath"/incomplete/*
fi
break
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Retry Download in 1 second fix errors..."
sleep 1
fi
done
# Consolidate files to a single folder
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Consolidating files to single folder"
find "$audioPath/incomplete" -type f -exec mv "{}" "$audioPath"/incomplete/ \; 2>/dev/null
find $audioPath/incomplete/ -type d -mindepth 1 -maxdepth 1 -exec rm -rf {} \; 2>/dev/null
downloadCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|m4a\|mp3\)" | wc -l)
if [ "$downloadCount" -gt "0" ]; then
# Check download for required quality (checks based on file extension)
DownloadQualityCheck "$audioPath/incomplete" "$2"
fi
downloadCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|m4a\|mp3\)" | wc -l)
if [ "$downloadCount" -ne "$5" ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: All download Attempts failed..."
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Logging $1 as failed download..."
if [ "$2" == "DEEZER" ]; then
touch /config/extended/logs/downloaded/failed/deezer/$1
fi
if [ "$2" == "TIDAL" ]; then
touch /config/extended/logs/downloaded/failed/tidal/$1
fi
return
fi
# Log Completed Download
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Logging $1 as successfully downloaded..."
if [ "$2" == "DEEZER" ]; then
touch /config/extended/logs/downloaded/deezer/$1
fi
if [ "$2" == "TIDAL" ]; then
touch /config/extended/logs/downloaded/tidal/$1
fi
# Tag with beets
if [ "$enableBeetsTagging" == "true" ]; then
if [ -f /config/extended/beets-error ]; then
rm /config/extended/beets-error
fi
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Processing files with beets..."
ProcessWithBeets "$audioPath/incomplete"
fi
# Embed Lyrics into Flac files
find "$audioPath/incomplete" -type f -iname "*.flac" -print0 | while IFS= read -r -d '' file; do
lrcFile="${file%.*}.lrc"
if [ -f "$lrcFile" ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Embedding lyrics (lrc) into $file"
metaflac --remove-tag=Lyrics "$file"
metaflac --set-tag-from-file="Lyrics=$lrcFile" "$file"
fi
done
if [ "$audioFormat" != "native" ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Converting Flac Audio to ${audioFormat^^} ($audioBitrateText)"
if [ "$audioFormat" == "opus" ]; then
options="-c:a libopus -b:a ${audioBitrate}k -application audio -vbr off"
extension="opus"
fi
if [ "$audioFormat" == "mp3" ]; then
options="-c:a libmp3lame -b:a ${audioBitrate}k"
extension="mp3"
fi
if [ "$audioFormat" == "aac" ]; then
options="-c:a aac -b:a ${audioBitrate}k -movflags faststart"
extension="m4a"
fi
if [ "$audioFormat" == "alac" ]; then
options="-c:a alac -movflags faststart"
extension="m4a"
fi
find "$audioPath/incomplete" -type f -iname "*.flac" -print0 | while IFS= read -r -d '' audio; do
file="${audio}"
filename="$(basename "$audio")"
foldername="$(dirname "$audio")"
filenamenoext="${filename%.*}"
if [ "$audioFormat" == "opus" ]; then
if opusenc --bitrate ${audioBitrate} --vbr --music "$file" "$foldername/${filenamenoext}.$extension"; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: $filename :: Conversion to $audioFormat ($audioBitrateText) successful"
rm "$file"
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: $filename :: ERROR :: Conversion Failed"
rm "$foldername/${filenamenoext}.$extension"
fi
continue
fi
if ffmpeg -loglevel warning -hide_banner -nostats -i "$file" -n -vn $options "$foldername/${filenamenoext}.$extension" < /dev/null; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: $filename :: Conversion to $audioFormat ($audioBitrateText) successful"
rm "$file"
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: $filename :: ERROR :: Conversion Failed"
rm "$foldername/${filenamenoext}.$extension"
fi
done
fi
if [ "$enableReplaygainTags" == "true" ]; then
AddReplaygainTags "$audioPath/incomplete"
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Replaygain Tagging Disabled (set enableReplaygainTags=true to enable...)"
fi
albumquality="$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | head -n 1 | egrep -i -E -o "\.{1}\w*$" | sed 's/\.//g')"
downloadedAlbumFolder="${lidarrArtistNameSanitized}-${downloadedAlbumTitleClean:0:100} (${3})"
find "$audioPath/incomplete" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" -print0 | while IFS= read -r -d '' audio; do
file="${audio}"
filenoext="${file%.*}"
filename="$(basename "$audio")"
extension="${filename##*.}"
filenamenoext="${filename%.*}"
if [ ! -d "$audioPath/complete" ]; then
mkdir -p "$audioPath"/complete
chmod 777 "$audioPath"/complete
fi
mkdir -p "$audioPath/complete/$downloadedAlbumFolder"
mv "$file" "$audioPath/complete/$downloadedAlbumFolder"/
done
chmod -R 777 "$audioPath"/complete
mv "$audioPath/complete/$downloadedAlbumFolder" "$importPath"
if [ -d "$importPath/$downloadedAlbumFolder" ]; then
NotifyLidarrForImport "$importPath/$downloadedAlbumFolder"
lidarrDownloadImportNotfication="true"
LidarrTaskStatusCheck
fi
if [ -d "$audioPath/complete/$downloadedAlbumFolder" ]; then
rm -rf "$audioPath"/incomplete/*
fi
}
ProcessWithBeets () {
# Input
# $1 Download Folder to process
if [ -f /config/extended/beets-library.blb ]; then
rm /config/extended/beets-library.blb
sleep 0.5
fi
if [ -f /config/extended/beets.log ]; then
rm /config/extended/beets.log
sleep 0.5
fi
if [ -f "/config/beets-match" ]; then
rm "/config/beets-match"
sleep 0.5
fi
touch "/config/beets-match"
sleep 0.5
beet -c /config/extended/beets-config.yaml -l /config/extended/beets-library.blb -d "$1" import -qC "$1"
if [ $(find "$1" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" -newer "/config/beets-match" | wc -l) -gt 0 ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: SUCCESS: Matched with beets!"
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: fixing track tags"
find "$audioPath/incomplete" -type f -iname "*.flac" -print0 | while IFS= read -r -d '' file; do
getArtistCredit="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$file" | jq -r ".format.tags.ARTIST_CREDIT" | sed "s/null//g" | sed "/^$/d")"
# album artist
metaflac --remove-tag=ALBUMARTIST "$file"
metaflac --remove-tag=ALBUMARTIST_CREDIT "$file"
metaflac --remove-tag=ALBUM_ARTIST "$file"
metaflac --remove-tag="ALBUM ARTIST" "$file"
# artist
metaflac --remove-tag=ARTIST "$file"
metaflac --remove-tag=ARTIST_CREDIT "$file"
if [ ! -z "$getArtistCredit" ]; then
metaflac --set-tag=ARTIST="$getArtistCredit" "$file"
else
metaflac --set-tag=ARTIST="$lidarrArtistName" "$file"
fi
# sorts
metaflac --remove-tag=ARTISTSORT "$file"
metaflac --remove-tag=COMPOSERSORT "$file"
metaflac --remove-tag=ALBUMARTISTSORT "$file"
# lidarr
metaflac --set-tag=ALBUMARTIST="$lidarrArtistName" "$file"
# mbrainz
metaflac --remove-tag=MUSICBRAINZ_ARTISTID "$file"
metaflac --remove-tag=MUSICBRAINZ_ALBUMARTISTID "$file"
metaflac --set-tag=MUSICBRAINZ_ARTISTID="$lidarrArtistForeignArtistId" "$file"
metaflac --set-tag=MUSICBRAINZ_ALBUMARTISTID="$lidarrArtistForeignArtistId" "$file"
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: FIXED : $file"
done
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: Unable to match using beets to a musicbrainz release..."
return
fi
if [ -f "/config/beets-match" ]; then
rm "/config/beets-match"
sleep 0.1
fi
# Get file metadata
GetFile=$(find "$audioPath/incomplete" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | head -n1)
extension="${GetFile##*.}"
if [ "$extension" == "opus" ]; then
matchedTags=$(ffprobe -hide_banner -loglevel fatal -show_error -show_format -show_streams -show_programs -show_chapters -show_private_data -print_format json "$GetFile" | jq -r ".streams[].tags")
else
matchedTags=$(ffprobe -hide_banner -loglevel fatal -show_error -show_format -show_streams -show_programs -show_chapters -show_private_data -print_format json "$GetFile" | jq -r ".format.tags")
fi
# Get Musicbrainz Release Group ID and Album Artist ID from tagged file
if [ "$extension" == "flac" ] || [ "$extension" == "opus" ]; then
matchedTagsAlbumReleaseGroupId="$(echo $matchedTags | jq -r ".MUSICBRAINZ_RELEASEGROUPID")"
matchedTagsAlbumArtistId="$(echo $matchedTags | jq -r ".MUSICBRAINZ_ALBUMARTISTID")"
elif [ "$extension" == "mp3" ] || [ "$extension" == "m4a" ]; then
matchedTagsAlbumReleaseGroupId="$(echo $matchedTags | jq -r '."MusicBrainz Release Group Id"')"
matchedLidarrAlbumArtistId="$(echo $matchedTags | jq -r '."MusicBrainz Ablum Artist Id"')"
fi
if [ ! -d "/config/extended/logs/downloaded/musicbrainz_matched" ]; then
mkdir -p "/config/extended/logs/downloaded/musicbrainz_matched"
chmod 777 "/config/extended/logs/downloaded/musicbrainz_matched"
fi
if [ ! -f "/config/extended/logs/downloaded/musicbrainz_matched/$matchedTagsAlbumReleaseGroupId" ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Marking MusicBrainz Release Group ($matchedTagsAlbumReleaseGroupId) as successfully downloaded..."
touch "/config/extended/logs/downloaded/musicbrainz_matched/$matchedTagsAlbumReleaseGroupId"
fi
}
DownloadQualityCheck () {
if [ "$requireQuality" == "true" ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Checking for unwanted files"
if [ "$audioFormat" != "native" ]; then
if find "$1" -type f -regex ".*/.*\.\(opus\|m4a\|mp3\)"| read; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Unwanted files found!"
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Performing cleanup..."
rm "$1"/*
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: No unwanted files found!"
fi
fi
if [ "$audioFormat" == "native" ]; then
if [ "$audioBitrate" == "master" ]; then
if find "$1" -type f -regex ".*/.*\.\(opus\|m4a\|mp3\)"| read; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Unwanted files found!"
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Performing cleanup..."
rm "$1"/*
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: No unwanted files found!"
fi
elif [ "$audioBitrate" == "lossless" ]; then
if find "$1" -type f -regex ".*/.*\.\(opus\|m4a\|mp3\)"| read; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Unwanted files found!"
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Performing cleanup..."
rm "$1"/*
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: No unwanted files found!"
fi
elif [ "$2" == "DEEZER" ]; then
if find "$1" -type f -regex ".*/.*\.\(opus\|m4a\|flac\)"| read; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Unwanted files found!"
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Performing cleanup..."
rm "$1"/*
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: No unwanted files found!"
fi
elif [ "$2" == "TIDAL" ]; then
if find "$1" -type f -regex ".*/.*\.\(opus\|flac\|mp3\)"| read; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Unwanted files found!"
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Performing cleanup..."
rm "$1"/*
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: No unwanted files found!"
fi
fi
fi
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Skipping download quality check... (enable by setting: requireQuality=true)"
fi
}
AddReplaygainTags () {
# Input Data
# $1 Folder path to scan and add tags
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Adding Replaygain Tags using r128gain"
r128gain -r -c 1 -a "$1" &>/dev/null
}
NotifyLidarrForImport () {
LidarrProcessIt=$(curl -s "$arrUrl/api/v1/command" --header "X-Api-Key:"${arrApiKey} -H "Content-Type: application/json" --data "{\"name\":\"DownloadedAlbumsScan\", \"path\":\"$1\"}")
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: LIDARR IMPORT NOTIFICATION SENT! :: $1"
}
DeemixClientSetup () {
log "DEEZER :: Verifying deemix configuration"
if [ ! -z "$arlToken" ]; then
arlToken="$(echo $arlToken | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')"
# Create directories
mkdir -p /config/xdg/deemix
if [ -f "/config/xdg/deemix/.arl" ]; then
rm "/config/xdg/deemix/.arl"
fi
if [ ! -f "/config/xdg/deemix/.arl" ]; then
echo -n "$arlToken" > "/config/xdg/deemix/.arl"
fi
log "DEEZER :: ARL Token: Configured"
else
log "DEEZER :: ERROR :: arlToken setting invalid, currently set to: $arlToken"
fi
if [ -f "/config/xdg/deemix/config.json" ]; then
rm /config/xdg/deemix/config.json
fi
if [ -f "/config/extended/deemix_config.json" ]; then
log "DEEZER :: Configuring deemix client"
cp /config/extended/deemix_config.json /config/xdg/deemix/config.json
chmod 777 /config/xdg/deemix/config.json
fi
if [ -d /config/extended/cache/deezer ]; then
log "DEEZER :: Purging album list cache..."
rm /config/extended/cache/deezer/*-albums.json &>/dev/null
fi
if [ ! -d "$audioPath/incomplete" ]; then
mkdir -p "$audioPath"/incomplete
chmod 777 "$audioPath"/incomplete
else
rm -rf "$audioPath"/incomplete/*
fi
#log "DEEZER :: Upgrade deemix to the latest..."
#pip install deemix --upgrade &>/dev/null
}
DeezerClientTest () {
log "DEEZER :: deemix client setup verification..."
deemix -b 128 -p $audioPath/incomplete "https://www.deezer.com/album/$deezerClientTestDownloadId" 2>&1 | tee -a "/config/logs/$logFileName"
if [ -d "/tmp/deemix-imgs" ]; then
rm -rf /tmp/deemix-imgs
fi
deezerClientTest="unknown"
downloadCount=$(find $audioPath/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)
if [ $downloadCount -le 0 ]; then
log "DEEZER :: ERROR :: Download failed"
log "DEEZER :: ERROR :: Please review log for errors in client"
log "DEEZER :: ERROR :: Try updating your ARL Token to possibly resolve the issue..."
log "DEEZER :: ERROR :: Exiting..."
rm -rf $audioPath/incomplete/*
NotifyWebhook "Error" "DEEZER not authenticated but configured"
deezerClientTest="fail"
log "Script sleeping for $audioScriptInterval..."
sleep $audioScriptInterval
exit
else
rm -rf $audioPath/incomplete/*
log "DEEZER :: Successfully Verified"
deezerClientTest="success"
fi
}
LidarrRootFolderCheck () {
if curl -s "$arrUrl/api/v1/rootFolder" -H "X-Api-Key: ${arrApiKey}" | sed '1q' | grep "\[\]" | read; then
log "ERROR :: No root folder found"
log "ERROR :: Configure root folder in Lidarr to continue..."
log "ERROR :: Exiting..."
NotifyWebhook "FatalError" "No root folder found"
log "Script sleeping for $audioScriptInterval..."
sleep $audioScriptInterval
exit