-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideo.bash
More file actions
612 lines (575 loc) · 23.3 KB
/
video.bash
File metadata and controls
612 lines (575 loc) · 23.3 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
#!/bin/bash
scriptVersion="8.4"
scriptName="Video-Processor"
dockerPath="/config/logs"
keepUnknownAudioIfDefaultLangMatch="true"
forceRemuxToMkv="false"
requireSubsForMovies="false"
requireSubsForTv="false"
# Import Script Settings/Configuration
source /config/scripts/settings.conf
set -e
logfileSetup () {
logFileName="$scriptName-$(date +"%Y_%m_%d_%I_%M_%p").txt"
if find "$dockerPath" -type f -iname "$scriptName-*.txt" | read; then
# Keep only the last 2 log files for 3 active log files at any given time...
rm -f $(ls -1t $dockerPath/$scriptName-* | tail -n +5)
# delete log files older than 5 days
find "$dockerPath" -type f -iname "$scriptName-*.txt" -mtime +5 -delete
fi
if [ ! -f "$dockerPath/$logFileName" ]; then
echo "" > "$dockerPath/$logFileName"
chmod 666 "$dockerPath/$logFileName"
fi
}
log () {
m_time=`date "+%F %T"`
echo $m_time" :: "$1
}
VideoFileCheck () {
log "Step - Video Check"
# check for video files
if find "$filePath" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | read; then
log "Video Files Found, continuing..."
sleep 0.1
else
Cleaner
echo "SCRIPT ERROR :: No video files found for processing"
arrRefreshMonitoredDownloads
arrRefreshMonitoredDownloads
exit 1
fi
}
VideoLanguageCheck () {
log "Step - Language Check"
if [ -f "/config/scripts/skip" ]; then
rm "/config/scripts/skip"
fi
noremux="true"
noremuxOverride="false"
count=0
fileCount=$(find "$filePath" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | wc -l)
log "Processing ${fileCount} video files..."
find "$filePath" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" -print0 | while IFS= read -r -d '' file; do
count=$(($count+1))
baseFileName="${file%.*}"
fileName="$(basename "$file")"
extension="${fileName##*.}"
log "$count of $fileCount :: Processing $fileName"
videoData=$(mkvmerge -J "$file")
videoAudioTracksCount=$(echo "${videoData}" | jq -r '.tracks[] | select(.type=="audio") | .id' | wc -l)
videoUnknownAudioTracksNull=$(echo "${videoData}" | jq -r '.tracks[] | select(.type=="audio") | .properties.language')
videoUnknownAudioTracksCount=$(echo "${videoData}" | jq -r '.tracks[] | select(.type=="audio") | select(.properties.language=="und") | .id' | wc -l)
videoSubtitleTracksCount=$(echo "${videoData}" | jq -r '.tracks[] | select(.type=="subtitles") | .id' | wc -l)
log "$count of $fileCount :: $videoAudioTracksCount Audio Tracks Found!"
log "$count of $fileCount :: $videoSubtitleTracksCount Subtitle Tracks Found!"
videoAudioLanguages=$(echo "${videoData}" | jq -r '.tracks[] | select(.type=="audio") | .properties.language')
videoSubtitleLanguages=$(echo "${videoData}" | jq -r '.tracks[] | select(.type=="subtitles") | .properties.language')
# Language Check
log "$count of $fileCount :: Checking for preferred languages \"$videoLanguages\""
preferredLanguage=false
IFS=',' read -r -a filters <<< "$videoLanguages"
for filter in "${filters[@]}"
do
videoAudioTracksLanguageCount=$(echo "${videoData}" | jq -r --arg lang "$filter" '.tracks[] | select(.type=="audio") | select(.properties.language==$lang) | .id' | wc -l)
videoSubtitleTracksLanguageCount=$(echo "${videoData}" | jq -r --arg lang "$filter" '.tracks[] | select(.type=="subtitles") | select(.properties.language==$lang) | .id' | wc -l)
log "$count of $fileCount :: $videoAudioTracksLanguageCount \"$filter\" Audio Tracks Found!"
log "$count of $fileCount :: $videoSubtitleTracksLanguageCount \"$filter\" Subtitle Tracks Found!"
if [ "$preferredLanguage" == "false" ]; then
if echo "$videoAudioLanguages" | grep -i "$filter" | read; then
preferredLanguage=true
elif echo "$videoSubtitleLanguages" | grep -i "$filter" | read; then
preferredLanguage=true
fi
fi
done
if echo "$filePath" | grep "sonarr" | read; then
if [ "$requireSubsForTv" == "true" ]; then
requireSubs="true"
else
requireSubs="false"
fi
fi
if echo "$filePath" | grep "radarr" | read; then
if [ "$requireSubsForMovies" == "true" ]; then
requireSubs="true"
else
requireSubs="false"
fi
fi
if [ "$requireSubs" == "true" ]; then
if [ "${requireLanguageMatch}" = "true" ]; then
if [ $videoSubtitleTracksLanguageCount -eq 0 ]; then
log "$count of $fileCount :: ERROR :: No subtitles found, requireSubs is enabled..."
rm "$file"
if [ $count -eq $fileCount ]; then
exit 1
fi
fi
elif [ $videoSubtitleTracksCount -eq 0 ]; then
log "$count of $fileCount :: ERROR :: No subtitles found, requireSubs is enabled..."
rm "$file"
if [ $count -eq $fileCount ]; then
exit 1
fi
fi
fi
if [ ! -f "$file" ]; then
continue
fi
if [ "$failVideosWithUnknownAudioTracks" == "true" ]; then
if [ "$videoUnknownAudioTracksNull" == "null" ] || [ $videoUnknownAudioTracksCount -ne 0 ]; then
if [ "$keepUnknownAudioIfDefaultLangMatch" == "true" ]; then
if [ ! -f "/config/scripts/arr-info" ]; then
ArrDownloadInfo
fi
if [ "$arrItemLanguage" = "$defaultLanguage" ]; then
if [ $videoAudioTracksCount -eq 1 ]; then
preferredLanguage=true
log "$count of $fileCount :: Only 1 Audio Track Detected, it is unknown but the download matches the defaultLanguage, so we're gonna assume it's just improperly tagged and skip failing the file..."
if [ $videoSubtitleTracksCount -eq $videoSubtitleTracksLanguageCount ]; then
noremuxOverride="true"
else
log "$count of $fileCount :: ERROR :: Subtitle track count missmatch, cannot remux due to unknown audio, failing download and performing cleanup..."
rm "$file"
if [ $count -eq $fileCount ]; then
exit 1
fi
fi
fi
fi
else
log "$count of $fileCount :: ERROR :: $videoAudioTracksCount Unknown (null) Audio Language Tracks found, failing download and performing cleanup..."
rm "$file"
if [ $count -eq $fileCount ]; then
exit 1
fi
fi
fi
fi
if [ ! -f "$file" ]; then
continue
fi
if [ "$preferredLanguage" == "false" ]; then
if [ "$requireLanguageMatch" == "true" ]; then
log "$count of $fileCount :: ERROR :: No matching languages found in $(($videoAudioTracksCount + $videoSubtitleTracksCount)) Audio/Subtitle tracks"
rm "$file"
if [ $count -eq $fileCount ]; then
exit 1
fi
fi
fi
if [ ! -f "$file" ]; then
continue
fi
# Skip further processing when Number of Audio and Subtitle tracks match the preferred language
if [ $videoAudioTracksCount -ne $videoAudioTracksLanguageCount ]; then
if [ "$noremuxOverride" == "false" ] ; then
log "$count of $fileCount :: Audio Track Count Missmatch (Total $videoAudioTracksCount vs Preferred $videoAudioTracksLanguageCount), forcing remux..."
noremux="false"
fi
else
log "$count of $fileCount :: Skipping ARR download information step because Audio Track count matches Preferred Track Count (Total $videoAudioTracksCount vs Preferred $videoAudioTracksLanguageCount)"
touch "/config/scripts/arr-info"
fi
if [ $videoSubtitleTracksCount -ne $videoSubtitleTracksLanguageCount ]; then
if [ "$noremuxOverride" == "false" ] ; then
log "$count of $fileCount :: Subtitle Track Count Missmatch (Total $videoSubtitleTracksCount vs Preferred $videoSubtitleTracksLanguageCount), forcing remux..."
noremux="false"
fi
fi
if [ "$noremux" == "true" ] || [ "$noremuxOverride" == "true" ] ; then
touch "/config/scripts/skip"
elif [ -f "$filePath/$tempFile" ]; then
log "$count of $fileCount :: Removing Source Temp File"
rm "$filePath/$tempFile"
fi
done
}
MkvPropEdit () {
log "Step - MkvPropEdit"
count=0
tempFile=""
fileCount=$(find "$filePath" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | wc -l)
log "Processing ${fileCount} video files with mkvmerge..."
find "$filePath" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" -print0 | while IFS= read -r -d '' file; do
count=$(($count+1))
baseFileName="${file%.*}"
fileName="$(basename "$file")"
fileNameNoExt="${fileName%.*}"
extension="${fileName##*.}"
tempFile="temp.$extension"
newFile="$fileNameNoExt.mkv"
log "$count of $fileCount :: Processing $fileName"
if [ "$1" = "false" ]; then
log "$count of $fileCount :: Removing Title and adding/updating track statistics"
mkvpropedit "$file" --delete title --add-track-statistics-tags
else
log "$count of $fileCount :: Removing Title"
mkvpropedit "$file" --delete title
fi
done
}
MkvMerge () {
log "Step - MKV Merge"
count=0
tempFile=""
fileCount=$(find "$filePath" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | wc -l)
log "Processing ${fileCount} video files with mkvmerge..."
find "$filePath" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" -print0 | while IFS= read -r -d '' file; do
count=$(($count+1))
baseFileName="${file%.*}"
fileName="$(basename "$file")"
fileNameNoExt="${fileName%.*}"
extension="${fileName##*.}"
tempFile="temp.$extension"
newFile="$fileNameNoExt.mkv"
log "$count of $fileCount :: Processing $fileName"
if [ -f "$file" ]; then
log "$count of $fileCount :: Renaming $fileName to $tempFile"
mv "$file" "$filePath/$tempFile"
fi
if [ -f "$filePath/$tempFile" ]; then
if [ "$1" = "true" ]; then
log "$count of $fileCount :: Dropping unwanted subtitles and converting to MKV ($tempFile ==> $newFile)"
log "$count of $fileCount :: Keeping only \"${audioLang}${videoLanguages},mul,zxx\" audio and \"$videoLanguages\" subtitle languages, droping all other audio/subtitle tracks..."
mkvmerge -o "$filePath/$newFile" --audio-tracks ${audioLang}${videoLanguages},mul,zxx --subtitle-tracks $videoLanguages --normalize-language-ietf canonical --no-global-tags --no-attachments "$filePath/$tempFile"
else
mkvmerge -o "$filePath/$newFile" --normalize-language-ietf canonical --no-global-tags --no-attachments "$filePath/$tempFile"
fi
if [ -f "$filePath/$newFile" ]; then
log "$count of $fileCount :: Conversion Complete"
else
log "$count of $fileCount :: ERROR :: File conversion failed..."
fi
fi
if [ -f "$filePath/$newFile" ]; then
if [ -f "$filePath/$tempFile" ]; then
log "$count of $fileCount :: Removing Source Temp File"
rm "$filePath/$tempFile"
fi
fi
log "$count of $fileCount :: Validating remuxed file by checking for audio tracks"
newFileVideoData=$(mkvmerge -J "$filePath/$newFile")
newFilevideoAudioTracksCount=$(echo "${newFileVideoData}" | jq -r '.tracks[] | select(.type=="audio") | .id' | wc -l)
if [ $newFilevideoAudioTracksCount -eq 0 ]; then
rm "$filePath/$newFile"
log "$count of $fileCount :: ERROR :: No audio tracks found afer remuxing, performing cleanup..."
exit 1
else
log "$count of $fileCount :: $newFilevideoAudioTracksCount Audio Tracks found!"
fi
log "$count of $fileCount :: Remux process complete!"
done
}
ArrWaitForTaskCompletion () {
arrRefreshMonitoredDownloads
log "Step - Checking $arrApp App Status"
alerted="no"
until false
do
taskCount=$(curl -s "$arrUrl/api/v3/command?apikey=${arrApiKey}" | jq -r '.[] | select(.status=="started") | .name' | wc -l)
arrRefreshMonitoredDownloadTaskCount=$(curl -s "$arrUrl/api/v3/command?apikey=${arrApiKey}" | jq -r '.[] | select(.status=="started") | .name' | grep "RefreshMonitoredDownloads" | wc -l)
if [ "$taskCount" -ge 3 ] || [ "$arrRefreshMonitoredDownloadTaskCount" -ge 1 ]; then
if [ "$alerted" == "no" ]; then
alerted="yes"
log "STATUS :: ARR APP BUSY :: Pausing/waiting for all active Arr app tasks to end..."
log "STATUS :: ARR APP BUSY :: Waiting..."
fi
else
break
fi
done
log "STATUS :: Done"
}
arrRefreshMonitoredDownloads () {
refreshQueue=$(curl -s "$arrUrl/api/v3/command" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" --data-raw '{"name":"RefreshMonitoredDownloads"}')
}
arrLanguage () {
if [ "$arrItemLanguage" == "English" ]; then
arrItemLang="en,"
elif [ "$arrItemLanguage" == "French" ]; then
arrItemLang="fr,"
elif [ "$arrItemLanguage" == "Japanese" ]; then
arrItemLang="ja,"
elif [ "$arrItemLanguage" == "German" ]; then
arrItemLang="de,"
elif [ "$arrItemLanguage" == "Spanish" ]; then
arrItemLang="es,"
elif [ "$arrItemLanguage" == "Chinese" ]; then
arrItemLang="zh,"
elif [ "$arrItemLanguage" == "Telugu" ]; then
arrItemLang="te,"
elif [ "$arrItemLanguage" == "Turkish" ]; then
arrItemLang="tr,"
elif [ "$arrItemLanguage" == "Arabic" ]; then
arrItemLang="ar,"
elif [ "$arrItemLanguage" == "Bengali" ]; then
arrItemLang="bn,"
elif [ "$arrItemLanguage" == "Catalan" ]; then
arrItemLang="ca,"
elif [ "$arrItemLanguage" == "Croatian" ]; then
arrItemLang="hr,"
elif [ "$arrItemLanguage" == "Czech" ]; then
arrItemLang="cs,"
elif [ "$arrItemLanguage" == "Danish" ]; then
arrItemLang="da,"
elif [ "$arrItemLanguage" == "Dutch" ]; then
arrItemLang="nl,"
elif [ "$arrItemLanguage" == "Hindi" ]; then
arrItemLang="hi,"
elif [ "$arrItemLanguage" == "Hungarian" ]; then
arrItemLang="hu,"
elif [ "$arrItemLanguage" == "Icelandic" ]; then
arrItemLang="is,"
elif [ "$arrItemLanguage" == "Indonesian" ]; then
arrItemLang="id,"
elif [ "$arrItemLanguage" == "Italian" ]; then
arrItemLang="it,"
elif [ "$arrItemLanguage" == "Kannada" ]; then
arrItemLang="kn,"
elif [ "$arrItemLanguage" == "Korean" ]; then
arrItemLang="ko,"
elif [ "$arrItemLanguage" == "Latvian" ]; then
arrItemLang="lv,"
elif [ "$arrItemLanguage" == "Malayalam" ]; then
arrItemLang="ml,"
elif [ "$arrItemLanguage" == "Marathi" ]; then
arrItemLang="mr,"
elif [ "$arrItemLanguage" == "Norwegian" ]; then
arrItemLang="no,"
elif [ "$arrItemLanguage" == "Persian" ]; then
arrItemLang="fa,"
elif [ "$arrItemLanguage" == "Polish" ]; then
arrItemLang="pl,"
elif [ "$arrItemLanguage" == "Portuguese" ]; then
arrItemLang="pt,"
elif [ "$arrItemLanguage" == "Romanian" ]; then
arrItemLang="ro,"
elif [ "$arrItemLanguage" == "Russian" ]; then
arrItemLang="ru,"
elif [ "$arrItemLanguage" == "Serbian" ]; then
arrItemLang="sr,"
elif [ "$arrItemLanguage" == "Slovenian" ]; then
arrItemLang="sl,"
elif [ "$arrItemLanguage" == "Tagalog" ]; then
arrItemLang="tl,"
elif [ "$arrItemLanguage" == "Tamil" ]; then
arrItemLang="ta,"
elif [ "$arrItemLanguage" == "Thai" ]; then
arrItemLang="th,"
elif [ "$arrItemLanguage" == "Ukrainian" ]; then
arrItemLang="uk,"
elif [ "$arrItemLanguage" == "Vietnamese" ]; then
arrItemLang="vi,"
elif [ "$arrItemLanguage" == "Swedish" ]; then
arrItemLang="sv,"
elif [ "$arrItemLanguage" == "Finnish" ]; then
arrItemLang="fi,"
elif [ "$arrItemLanguage" == "Greek" ]; then
arrItemLang="el,"
elif [ "$arrItemLanguage" == "Hebrew" ]; then
arrItemLang="he,"
else
log "ERROR :: Unconfigured Language ($arrItemLanguage), using default ($videoLanguages) only..."
arrItemLang=""
fi
}
arrApiKeySelect () {
if echo "$filePath" | grep "sonarr" | read; then
arrApp="Sonarr"
arrUrl="$sonarrUrl" # Set category in SABnzbd to: sonarr
arrApiKey="$sonarrApiKey" # Set category in SABnzbd to: sonarr
fi
if echo "$filePath" | grep "sonarr-anime" | read; then
arrApp="Sonarr Anime"
arrUrl="$sonarranimeUrl" # Set category in SABnzbd to: sonarr-anime
arrApiKey="$sonarranimeApiKey" # Set category in SABnzbd to: sonarr-anime
fi
if echo "$filePath" | grep "radarr" | read; then
arrApp="Radarr"
arrUrl="$radarrUrl" # Set category in SABnzbd to: radarr
arrApiKey="$radarrApiKey" # Set category in SABnzbd to: radarr
fi
}
Cleaner () {
if find "$filePath" -mindepth 1 -type f -not -iname "*.mkv" | read; then
log "Cleaner :: Removing all Non MKV Files"
find "$filePath" -mindepth 1 -type f -not -iname "*.mkv" -delete
fi
if find "$filePath" -mindepth 1 -type d -empty | read; then
log "Cleaner :: Removing Empty Folders"
find "$filePath" -mindepth 1 -type d -empty -delete
fi
}
ArrDownloadInfo () {
VerifyApiAccess
#ArrWaitForTaskCompletion
if [ -f "/config/scripts/arr-info" ]; then
return
fi
arrRefreshMonitoredDownloads
log "Step - Getting $arrApp Download Information"
alerted="no"
until false
do
if echo "$filePath" | grep "sonarr" | read; then
arrQueueItemData=$(curl -s "$arrUrl/api/v3/queue?pageSize=500&sortDirection=ascending&sortKey=timeleft&includeUnknownSeriesItems=false&apikey=$arrApiKey" | jq -r --arg id "$downloadId" '.records[] | select(.downloadId==$id)')
arrSeriesId="$(echo $arrQueueItemData | jq -r .seriesId | sort -u)"
if [ -z "$arrSeriesId" ]; then
arrQueueItemData=$(curl -s "$arrUrl/api/v3/history?pageSize=2500&sortDirection=descending&sortKey=date&eventType=1&apikey=$arrApiKey" | jq -r --arg id "$downloadId" '.records[] | select(.downloadId==$id)')
arrSeriesId="$(echo $arrQueueItemData | jq -r .seriesId | sort -u)"
fi
if [ -z "$arrSeriesId" ]; then
onlineData=""
audioLang=""
if [ "$alerted" == "no" ]; then
alerted="yes"
log "STATUS :: ARR APP BUSY :: Pausing/waiting for successful download lookup from ARR app..."
fi
continue
else
arrSeriesCount=$(echo "$arrSeriesId" | wc -l)
arrEpisodeId="$(echo $arrQueueItemData | jq -r .episodeId)"
arrEpisodeCount=$(echo "$arrEpisodeId" | wc -l)
arrSeriesData=$(curl -s "$arrUrl/api/v3/series/$arrSeriesId?apikey=$arrApiKey")
onlineSourceId="$(echo "$arrSeriesData" | jq -r ".tvdbId")"
arrItemLanguage="$(echo "$arrSeriesData" | jq -r ".originalLanguage.name")"
log "Sonarr Show ID = $arrSeriesId :: Lanuage :: $arrItemLanguage"
log "TVDB ID = $onlineSourceId"
if [ "$arrItemLanguage" = "$defaultLanguage" ]; then
audioLang=""
else
arrLanguage
audioLang="$arrItemLang"
fi
fi
fi
if echo "$filePath" | grep "radarr" | read; then
arrItemId=$(curl -s "$arrUrl/api/v3/queue?pageSize=500&sortDirection=ascending&sortKey=timeleft&includeUnknownMovieItems=false&apikey=$arrApiKey" | jq -r --arg id "$downloadId" '.records[] | select(.downloadId==$id) | .movieId')
arrItemData=$(curl -s "$arrUrl/api/v3/movie/$arrItemId?apikey=$arrApiKey")
onlineSourceId="$(echo "$arrItemData" | jq -r ".tmdbId")"
if [ -z "$onlineSourceId" ]; then
arrItemId=$(curl -s "$arrUrl/api/v3/history?pageSize=2500&sortDirection=descending&sortKey=date&eventType=1&apikey=$arrApiKey" | jq -r --arg id "$downloadId" '.records[] | select(.downloadId==$id) | .movieId')
arrItemData=$(curl -s "$arrUrl/api/v3/movie/$arrItemId?apikey=$arrApiKey")
onlineSourceId="$(echo "$arrItemData" | jq -r ".tmdbId")"
fi
if [ -z "$onlineSourceId" ]; then
onlineData=""
audioLang=""
if [ "$alerted" == "no" ]; then
alerted="yes"
log "STATUS :: ARR APP BUSY :: Pausing/waiting for successful download lookup from ARR app..."
fi
continue
else
arrItemLanguage="$(echo "$arrItemData" | jq -r ".originalLanguage.name")"
log "Radarr Movie ID = $arrItemId :: Language: $arrItemLanguage"
log "TMDB ID = $onlineSourceId"
onlineData="-tmdb $onlineSourceId"
if [ "$arrItemLanguage" = "$defaultLanguage" ]; then
audioLang=""
else
arrLanguage
audioLang="$arrItemLang"
fi
fi
fi
touch "/config/scripts/arr-info"
break
done
}
VerifyApiAccess () {
log "Step - Verifying $arrApp API is accessible"
alerted="no"
until false
do
arrApiTest=""
arrApiVersion=""
if [ -z "$arrApiTest" ]; then
arrApiVersion="v3"
arrApiTest="$(curl -s "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" | jq -r .instanceName)"
fi
if [ -z "$arrApiTest" ]; then
arrApiVersion="v1"
arrApiTest="$(curl -s "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" | jq -r .instanceName)"
fi
if [ ! -z "$arrApiTest" ]; then
break
else
if [ "$alerted" == "no" ]; then
alerted="yes"
log "STATUS :: $arrApp is not ready, sleeping until valid response..."
fi
sleep 1
fi
done
log "STATUS :: Done"
}
MAIN () {
SECONDS=0
logfileSetup
touch "$dockerPath/$logFileName"
exec &> >(tee -a "$dockerPath/$logFileName")
filePath="$1"
downloadId="$SAB_NZO_ID"
skipRemux="false"
skipStatistics="false"
log "Script: Name :: $scriptName"
log "Script: Version :: $scriptVersion"
log "Script: Settings :: videoLanguages = $videoLanguages"
log "Script: Settings :: defaultLanguage = $defaultLanguage"
log "Script: Settings :: requireLanguageMatch = $requireLanguageMatch"
log "Script: Settings :: failVideosWithUnknownAudioTracks = $failVideosWithUnknownAudioTracks"
log "Script: Settings :: keepUnknownAudioIfDefaultLangMatch = $keepUnknownAudioIfDefaultLangMatch"
log "Script: Settings :: forceRemuxToMkv = $forceRemuxToMkv"
log "Script: Settings :: requireSubsForMovies = $requireSubsForMovies"
log "Script: Settings :: requireSubsForTv = $requireSubsForTv"
log "Script: Settings :: onlyLanguageCheck = $onlyLanguageCheck"
arrApiKeySelect
# log "$filePath :: $downloadId :: Processing"
if [ -f "/config/scripts/arr-info" ]; then
rm "/config/scripts/arr-info"
fi
VideoFileCheck
if [ "$onlyLanguageCheck" != "true" ]; then
if find "$filePath" -type f -regex ".*/.*\.\(m4v\|wmv\|mp4\|avi\)" | read; then
MkvMerge "false"
VideoFileCheck
skipStatistics="true"
fi
fi
VideoLanguageCheck
VideoFileCheck
if [ "$onlyLanguageCheck" != "true" ]; then
if [ -f "/config/scripts/skip" ]; then
skipRemux="true"
rm "/config/scripts/skip"
if [ "$forceRemuxToMkv" == "true" ]; then
skipRemux="false"
fi
fi
if [ "$skipRemux" == "false" ]; then
if [ ! -f "/config/scripts/arr-info" ]; then
ArrDownloadInfo
fi
MkvMerge "true"
VideoFileCheck
skipStatistics="true"
fi
if [ -f "/config/scripts/arr-info" ]; then
rm "/config/scripts/arr-info"
fi
MkvPropEdit "$skipStatistics"
Cleaner
fi
log "Refreshing $arrApp download queue to notify and import completed downloads"
duration=$SECONDS
durationOutput="$(printf '%dd:%dh:%dm:%ds\n' $((duration/86400)) $((duration%86400/3600)) $((duration%3600/60)) $((duration%60)))"
echo "Completed in $durationOutput!"
# Actually perform the Arr App Download Queue refresh here as the very last step....
arrRefreshMonitoredDownloads
arrRefreshMonitoredDownloads
}
MAIN "$1"
exit