-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtagarr_import.sh
More file actions
executable file
·1463 lines (1231 loc) · 59.7 KB
/
tagarr_import.sh
File metadata and controls
executable file
·1463 lines (1231 loc) · 59.7 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/env bash
# -----------------------------------------------------------------------------
# Tagarr Import — Event-Driven Radarr Tagger with Discovery
# Version: 1.5.8
#
# Radarr Connect handler that tags individual movies on import, upgrade, or
# file delete events. Tags are based on release group, quality source
# (MA/Play WEB-DL), and lossless audio codec (TrueHD, TrueHD Atmos, DTS-X,
# DTS-HD MA). Optionally syncs tags to a secondary Radarr instance.
#
# Features:
# TAGGING — Match movies by release group + quality + audio filters
# SYNC — Mirror tags to a secondary Radarr instance (optional)
# DISCOVERY — Auto-detect new release groups that pass all filters but
# aren't in the config yet. Writes them as commented entries
# for manual review and activation. (optional)
# CLEANUP — Remove managed tags when movie file is deleted
# DEBUG — Log every filter decision per event (optional)
# SMART — Only send Discord notifications when something happens
# (tagged or discovered). Silent otherwise.
#
# Setup:
# Radarr > Settings > Connect > Custom Script
# Path: /scripts/tagarr_import.sh
# Events: On Grab, On File Import, On File Upgrade, On Movie File Delete
#
# Based on auto_tag_import.sh v3.4.1. Configuration: tagarr_import.conf
#
# Author: prophetSe7en
#
# WARNING: Runs automatically on every import/upgrade/delete event.
# Test with a single movie before enabling as a Radarr Connect handler.
# -----------------------------------------------------------------------------
SCRIPT_VERSION="1.5.8"
########################################
# CONFIG LOADING
########################################
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
SCRIPT_NAME="$(basename "$0" .sh)"
CONFIG_FILE="${SCRIPT_DIR}/${SCRIPT_NAME}.conf"
if [ -f "$CONFIG_FILE" ]; then
source "$CONFIG_FILE"
else
echo "ERROR: Config not found: $CONFIG_FILE"
exit 1
fi
# Constructed API URLs
PRIMARY_RADARR_API_URL="${PRIMARY_RADARR_URL}/api/v3"
SECONDARY_RADARR_API_URL="${SECONDARY_RADARR_URL}/api/v3"
########################################
# DISCOVERY SETUP
########################################
# Build set of ALL known release groups from config (active + commented)
declare -A known_release_groups
known_release_groups[_]=1; unset "known_release_groups[_]"
while IFS= read -r line; do
if [[ "$line" =~ \"([^:\"]+):[^:\"]+:[^:\"]+:[^:\"]+\" ]]; then
known_release_groups["${BASH_REMATCH[1],,}"]=1
fi
done < "$CONFIG_FILE"
########################################
# EVENT VARIABLES FROM RADARR
########################################
EVENT_TYPE="${radarr_eventtype:-Test}"
MOVIE_ID="${radarr_movie_id:-0}"
MOVIE_FILE_RELATIVE="${radarr_moviefile_relativepath:-}"
MOVIE_FILE_SCENE="${radarr_moviefile_scenename:-}"
RELEASE_GROUP_FROM_FILE="${radarr_moviefile_releasegroup:-}"
DOWNLOAD_ID_FROM_EVENT="${radarr_download_id:-}"
################################################################################
# LOGGING AND LOG ROTATION
################################################################################
log() {
if [ "${ENABLE_LOGGING:-true}" = "true" ] && [ -n "${LOG_FILE:-}" ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') [$1] $2" | tee -a "$LOG_FILE"
else
echo "$(date '+%Y-%m-%d %H:%M:%S') [$1] $2"
fi
}
# Ensure log directory exists
if [ "${ENABLE_LOGGING:-true}" = "true" ] && [ -n "${LOG_FILE:-}" ]; then
mkdir -p "$(dirname "$LOG_FILE")"
fi
if [ "${ENABLE_LOGGING:-true}" = "true" ] && [ -n "${LOG_FILE:-}" ] && [ -f "$LOG_FILE" ]; then
LOG_SIZE=$(stat -c%s "$LOG_FILE" 2>/dev/null || stat -f%z "$LOG_FILE" 2>/dev/null || echo 0)
if [ "$LOG_SIZE" -gt 2097152 ]; then
[ -f "${LOG_FILE}.old" ] && rm "${LOG_FILE}.old"
mv "$LOG_FILE" "${LOG_FILE}.old"
log "INFO" "Log rotated - previous log saved as ${LOG_FILE}.old"
fi
fi
################################################################################
# UPDATE CHECK — non-blocking, fail-safe
################################################################################
UPDATE_AVAILABLE=""
_check_for_update() {
local versions_url="https://raw.githubusercontent.com/ProphetSe7en/tagarr/main/versions.json"
local script_name
script_name="$(basename "$0")"
local remote_json
remote_json=$(curl -fsSL --max-time 5 "$versions_url" 2>/dev/null) || return 0
local latest
latest=$(echo "$remote_json" | jq -r --arg s "$script_name" '.[$s] // ""' 2>/dev/null) || return 0
# Only alert when remote is strictly newer than local (sort -V = version sort).
# Prevents "update available: older-version" if local runs ahead of versions.json.
if [ -n "$latest" ] && [ "$latest" != "$SCRIPT_VERSION" ] && \
[ "$(printf '%s\n%s\n' "$latest" "$SCRIPT_VERSION" | sort -V 2>/dev/null | tail -1)" = "$latest" ]; then
UPDATE_AVAILABLE="$latest"
log "INFO" "Update available: v${latest} (current: v${SCRIPT_VERSION})"
fi
}
_check_for_update
# Discord footer — includes update notice when available
DISCORD_FOOTER="Tagarr Import v${SCRIPT_VERSION} by ProphetSe7en"
[ -n "$UPDATE_AVAILABLE" ] && DISCORD_FOOTER="${DISCORD_FOOTER} • Update available (v${UPDATE_AVAILABLE})"
################################################################################
# HANDLE RADARR GRAB EVENT — qBit torrent rename to match Radarr grab title
#
# Fires when Radarr sends a release to the download client. Renames the qBit
# display name to match radarr_release_title so Radarr's import parser sees
# the full release name (with all CF-relevant tokens) and scores correctly.
# This prevents download loops where stripped torrent names cause score drops.
#
# Discord notification is only sent when meaningful tokens were recovered
# (release group, WEB-DL, IMAX, MA, TrueHD, etc.). Plain cosmetic renames
# (dots vs spaces, DD+ vs DD plus) are silent.
#
# Idempotent — skips when qBit name already equals grab title.
# Never modifies files or folders on disk.
################################################################################
if [ "$EVENT_TYPE" = "Grab" ]; then
log "INFO" "============================================"
log "INFO" "Tagarr Import v${SCRIPT_VERSION}"
log "INFO" "Event: Grab"
log "INFO" "============================================"
# Feature toggle (default off — must be explicitly enabled in config)
if [ "${ENABLE_GRAB_RENAME:-false}" != "true" ]; then
log "INFO" "ENABLE_GRAB_RENAME is not true — skipping"
exit 0
fi
GRAB_RG="${radarr_release_releasegroup:-}"
GRAB_TITLE="${radarr_release_title:-}"
GRAB_HASH="${radarr_download_id:-}"
GRAB_CLIENT="${radarr_download_client:-}"
if [ -z "$GRAB_RG" ] || [ -z "$GRAB_TITLE" ] || [ -z "$GRAB_HASH" ] || [ -z "$GRAB_CLIENT" ]; then
log "WARN" "Missing required env vars (rg='$GRAB_RG' title='$GRAB_TITLE' hash='$GRAB_HASH' client='$GRAB_CLIENT') — skip"
exit 0
fi
log "INFO" "Movie: ${radarr_movie_title:-?} (${radarr_movie_year:-?})"
log "INFO" "Release: $GRAB_TITLE"
log "INFO" "Group: $GRAB_RG"
log "INFO" "Client: $GRAB_CLIENT"
log "INFO" "Hash: $GRAB_HASH"
# Map download client name to qBit URL (case-insensitive match)
# Supports direct qBit URLs or Qui proxy URLs
hash_lower="${GRAB_HASH,,}"
if [ "${#QBIT_CLIENTS[@]}" -eq 0 ]; then
log "WARN" "QBIT_CLIENTS is empty or unset — skip"
exit 0
fi
qbit_url=""
grab_client_lower="${GRAB_CLIENT,,}"
for entry in "${QBIT_CLIENTS[@]}"; do
client_name="${entry%%:*}"
client_url="${entry#*:}"
if [ "${client_name,,}" = "$grab_client_lower" ]; then
qbit_url="$client_url"
break
fi
done
if [ -z "$qbit_url" ]; then
if [ "${#QBIT_CLIENTS[@]}" -eq 1 ]; then
qbit_url="${QBIT_CLIENTS[0]#*:}"
log "INFO" "Client '$GRAB_CLIENT' not in QBIT_CLIENTS but only one entry configured — using ${qbit_url}"
else
log "WARN" "Download client '$GRAB_CLIENT' not in QBIT_CLIENTS map (${#QBIT_CLIENTS[@]} entries) — skip"
exit 0
fi
fi
log "INFO" "qBit URL: $qbit_url"
# Fetch current torrent info from qBit (case-insensitive hash)
qbit_info=$(curl -sS --max-time 10 "${qbit_url}/api/v2/torrents/info?hashes=${hash_lower}" 2>/dev/null)
if [ -z "$qbit_info" ] || [ "$qbit_info" = "[]" ]; then
log "WARN" "Torrent $hash_lower not found in qBit (yet?) — skip"
exit 0
fi
current_name=$(echo "$qbit_info" | jq -r '.[0].name // ""' 2>/dev/null)
if [ -z "$current_name" ]; then
log "WARN" "Could not parse qBit torrent name — skip"
exit 0
fi
log "INFO" "Current torrent name: $current_name"
# Idempotent: if name is already exactly the grab title, skip
if [ "$current_name" = "$GRAB_TITLE" ]; then
log "INFO" "Torrent name already equals grab title — no rename needed"
exit 0
fi
# Scene detection — uses the same logic as TRaSH Scene CF:
# 1) Resolution + WEB (not followed by DL) = scene naming pattern
# 2) Known scene release groups from TRaSH Scene CF
# Source: docs/json/radarr/cf/scene.json in TRaSH-Guides repo
_is_scene() {
local name="$1"
# Pattern 1: has resolution + WEB without DL (scene naming)
if echo "$name" | grep -Eqi '\b[0-9]{3,4}p\b' && \
echo "$name" | grep -Eqi '(^|[_. ])WEB([_. ]|$)' && \
! echo "$name" | grep -Eqi 'WEB[-.]?DL'; then
return 0
fi
# Pattern 2: known scene groups (from TRaSH Scene CF)
# NOTE: `--` is required — the pattern starts with `-` which grep
# otherwise parses as a short option, printing "invalid option -- '('"
# and silently failing the match.
if echo "$name" | grep -Eqi -- '-(CAKES|GGEZ|GGWP|GLHF|GOSSIP|NAISU|KOGI|PECULATE|SLOT|EDITH|ETHEL|ELEANOR|B2B|SPAMnEGGS|FTP|DiRT|SYNCOPY|BAE|SuccessfulCrab|NHTFS|SURCODE|B0MBARDIERS|D3US|BROTHERHOOD|W4K|STRiKES)\b'; then
return 0
fi
return 1
}
is_scene_before=false
is_scene_after=false
_is_scene "$current_name" && is_scene_before=true
_is_scene "$GRAB_TITLE" && is_scene_after=true
if [ "$is_scene_before" = "true" ]; then
log "INFO" "Scene release detected (original torrent name matches Scene CF pattern)"
if [ "${GRAB_RENAME_EXCLUDE_SCENE:-false}" = "true" ]; then
log "INFO" "GRAB_RENAME_EXCLUDE_SCENE is true — skipping rename for scene release"
exit 0
fi
fi
# Track whether rename changes Scene CF matching (scene before but not after)
scene_cf_changed=false
if [ "$is_scene_before" = "true" ] && [ "$is_scene_after" = "false" ]; then
scene_cf_changed=true
log "INFO" "Rename will change Scene CF matching: scene → non-scene"
fi
# Compute diff: which tokens are present in grab title but absent in qBit name.
# Used for both log output and Discord notification.
# Helper: returns true if grab has the pattern but qBit name does not.
_added() {
local regex="$1"
! echo "$current_name" | grep -Eqi "$regex" && \
echo "$GRAB_TITLE" | grep -Eqi "$regex"
}
diff_tokens=()
# Release group suffix — flexible match: -GROUP, - GROUP, -GROUP), etc.
# Escape group name for regex (groups are typically alphanumeric, but be safe)
_grab_rg_esc=$(printf '%s' "$GRAB_RG" | sed 's/[.[\*^$()+?{|\\]/\\&/g')
if ! echo "$current_name" | grep -Eqi "[-][ ]?${_grab_rg_esc}([^a-zA-Z0-9]|$)"; then
diff_tokens+=("-${GRAB_RG} (release group)")
fi
# Token detection — check which CF-relevant tokens are in the grab title
# but missing from the qBit torrent name. These are the tokens that matter
# for Radarr's Custom Format scoring. Only these trigger Discord notification.
#
# Source + audio patterns mirror check_quality_match / check_audio_match
# below (~lines 525-575). Update both together.
ma_or_play_added=false
_added '\bma(\]?\s*\[?|[._-])web([-.]?dl)?' && { diff_tokens+=("MA WEB-DL"); ma_or_play_added=true; }
_added '\bplay(\]?\s*\[?|[._-])web([-.]?dl)?' && { diff_tokens+=("Play WEB-DL"); ma_or_play_added=true; }
# Standalone WEB-DL only when MA/Play didn't already cover it
[ "$ma_or_play_added" = "false" ] && _added '\bweb[-.]?dl\b' && diff_tokens+=("WEB-DL")
[ "${GRAB_RENAME_IMAX:-false}" = "true" ] && \
_added '\bimax\b' && diff_tokens+=("IMAX")
[ "${GRAB_RENAME_OPEN_MATTE:-false}" = "true" ] && \
_added '\bopen[ ._-]?matte\b' && diff_tokens+=("Open Matte")
_added '\btruehd\b' && diff_tokens+=("TrueHD")
_added '\batmos\b' && diff_tokens+=("Atmos")
_added '\bdts[._-]?x\b' && diff_tokens+=("DTS-X")
_added '\bdts[._ -]?hd[._ -]?ma\b' && diff_tokens+=("DTS-HD MA")
# Design principle: only tokens that Radarr CANNOT reconstruct from
# the file itself belong here. MediaInfo-derived CFs (HDR10/HDR10+/
# DV/HLG, audio channels, resolution, codec) are handled by Radarr's
# own file analysis — renaming the torrent to preserve those tokens
# is pointless because the filename already carries them and Radarr
# reads the file directly. Only title-only tokens (release group
# stripped to digits, Movie Version like IMAX/Open Matte) are worth
# chasing via rename.
# User-defined tokens — format per entry: "label:regex". Bash regex,
# no lookaheads. Same semantics as the built-ins above: added to
# diff_tokens when grab title matches but torrent name doesn't.
for _cf_entry in "${GRAB_RENAME_CUSTOM_TOKENS[@]}"; do
_cf_label="${_cf_entry%%:*}"
_cf_regex="${_cf_entry#*:}"
[ -z "$_cf_label" ] || [ -z "$_cf_regex" ] && continue
_added "$_cf_regex" && diff_tokens+=("$_cf_label")
done
# Build comma-space-separated summary string for the "Tokens added" field
if [ "${#diff_tokens[@]}" -gt 0 ]; then
printf -v diff_summary '%s, ' "${diff_tokens[@]}"
diff_summary="${diff_summary%, }"
log "INFO" "Tokens added by rename: $diff_summary"
else
# No meaningful tokens to recover — skip rename entirely.
# Cosmetic differences (dots vs spaces, reordering) don't affect
# Radarr's import scoring and renaming can interfere with queue tracking.
log "INFO" "No meaningful tokens to recover — skipping rename (cosmetic only)"
exit 0
fi
# Build natural-language description for Discord (separate from token list)
group_recovered=false
other_tokens=()
for t in "${diff_tokens[@]}"; do
if [[ "$t" == *"(release group)"* ]]; then
group_recovered=true
else
other_tokens+=("$t")
fi
done
if [ "${#other_tokens[@]}" -gt 0 ]; then
printf -v others_str '**%s**, ' "${other_tokens[@]}"
others_str="${others_str%, }"
else
others_str=""
fi
if [ "$group_recovered" = "true" ] && [ -n "$others_str" ]; then
summary_text="Recovered release group **${GRAB_RG}** and added ${others_str}"
elif [ "$group_recovered" = "true" ]; then
summary_text="Recovered release group **${GRAB_RG}**"
elif [ -n "$others_str" ]; then
summary_text="Added ${others_str}"
else
summary_text="Cosmetic rename — no scoring impact tracked"
fi
# Execute rename
log "INFO" "Renaming qBit torrent to: $GRAB_TITLE"
rename_response=$(curl -sS --max-time 10 -w "\nHTTP_CODE:%{http_code}" \
-X POST "${qbit_url}/api/v2/torrents/rename" \
--data-urlencode "hash=${hash_lower}" \
--data-urlencode "name=${GRAB_TITLE}" 2>/dev/null)
rename_http=$(echo "$rename_response" | grep "HTTP_CODE:" | tail -1 | cut -d: -f2)
if [ "$rename_http" = "200" ]; then
log "INFO" "Rename successful (HTTP 200)"
else
log "WARN" "Rename failed (HTTP $rename_http)"
exit 0
fi
# Discord notification — only when meaningful tokens were recovered or
# Scene CF matching was changed by the rename. Plain cosmetic renames are silent.
if [ "${DISCORD_ENABLED:-false}" = "true" ] && [ -n "${DISCORD_WEBHOOK_URL:-}" ] && \
{ [ "${#diff_tokens[@]}" -gt 0 ] || [ "$scene_cf_changed" = "true" ]; }; then
# Fetch movie details for poster (Grab handler exits before main flow runs)
grab_poster_url=""
grab_movie_id="${radarr_movie_id:-}"
if [ -n "$grab_movie_id" ] && [ -n "${PRIMARY_RADARR_API_URL:-}" ] && [ -n "${PRIMARY_RADARR_API_KEY:-}" ]; then
grab_movie_json=$(curl -sS --max-time 5 "${PRIMARY_RADARR_API_URL}/movie/${grab_movie_id}?apikey=${PRIMARY_RADARR_API_KEY}" 2>/dev/null)
if [ -n "$grab_movie_json" ] && [ "$grab_movie_json" != "null" ]; then
grab_poster_url=$(echo "$grab_movie_json" | jq -r '.remotePoster // ""' 2>/dev/null)
if [ -z "$grab_poster_url" ] || [ "$grab_poster_url" = "null" ]; then
grab_poster_url=$(echo "$grab_movie_json" | jq -r '.images[]? | select(.coverType == "poster") | .remoteUrl // .url // empty' 2>/dev/null | head -1)
fi
fi
fi
[ "$grab_poster_url" = "null" ] && grab_poster_url=""
# Categorize tokens into quality/audio for separate fields
quality_fixed=""
audio_parts=()
for t in "${other_tokens[@]}"; do
case "$t" in
"MA WEB-DL"|"Play WEB-DL"|"WEB-DL"|"IMAX"|"Open Matte")
quality_fixed="${quality_fixed:+$quality_fixed, }$t"
;;
"TrueHD"|"Atmos"|"DTS-X"|"DTS-HD MA")
audio_parts+=("$t")
;;
esac
done
# Combine TrueHD + Atmos into the natural "TrueHD Atmos" string
audio_fixed=""
if [ "${#audio_parts[@]}" -gt 0 ]; then
has_truehd=false
has_atmos=false
other_audio=()
for a in "${audio_parts[@]}"; do
case "$a" in
TrueHD) has_truehd=true ;;
Atmos) has_atmos=true ;;
*) other_audio+=("$a") ;;
esac
done
if [ "$has_truehd" = "true" ] && [ "$has_atmos" = "true" ]; then
audio_fixed="TrueHD Atmos"
elif [ "$has_truehd" = "true" ]; then
audio_fixed="TrueHD"
elif [ "$has_atmos" = "true" ]; then
audio_fixed="Atmos"
fi
if [ "${#other_audio[@]}" -gt 0 ]; then
for a in "${other_audio[@]}"; do
if [ -z "$audio_fixed" ]; then
audio_fixed="$a"
else
audio_fixed="${audio_fixed}, $a"
fi
done
fi
fi
notif_title="Renamed - ${radarr_movie_title:-Unknown} (${radarr_movie_year:-?})"
# Always orange — matches Radarr's existing Tagged notifications
notif_color=16753920 # Orange (0xFFA500)
# Build fields dynamically — only include what was actually recovered
fields_json='[]'
fields_json=$(echo "$fields_json" | jq \
--arg val "$GRAB_CLIENT" \
'. += [{ name: "Renamed in", value: $val, inline: false }]')
if [ "$group_recovered" = "true" ]; then
fields_json=$(echo "$fields_json" | jq \
--arg val "$GRAB_RG" \
'. += [{ name: "Release Group Recovered", value: $val, inline: true }]')
fi
if [ -n "$quality_fixed" ]; then
fields_json=$(echo "$fields_json" | jq \
--arg val "$quality_fixed" \
'. += [{ name: "Quality Recovered", value: $val, inline: true }]')
fi
if [ -n "$audio_fixed" ]; then
fields_json=$(echo "$fields_json" | jq \
--arg val "$audio_fixed" \
'. += [{ name: "Audio Recovered", value: $val, inline: true }]')
fi
if [ "$scene_cf_changed" = "true" ]; then
fields_json=$(echo "$fields_json" | jq \
'. += [{ name: "⚠️ Scene CF", value: "No longer matches after rename", inline: true }]')
fi
fields_json=$(echo "$fields_json" | jq \
--arg event "Grab" \
--arg old "$current_name" \
--arg new "$GRAB_TITLE" \
'. += [
{ name: "Event", value: $event, inline: true },
{ name: "Torrent Name", value: $old, inline: false },
{ name: "Restored to Release Name", value: $new, inline: false }
]')
payload=$(jq -n \
--arg title "$notif_title" \
--argjson color "$notif_color" \
--arg poster_url "$grab_poster_url" \
--argjson fields "$fields_json" \
--arg footer_text "$DISCORD_FOOTER" \
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" \
'{
embeds: [{
title: $title,
color: $color,
fields: $fields,
footer: { text: $footer_text },
timestamp: $timestamp,
thumbnail: { url: $poster_url }
}]
}')
response=$(curl -sS -w "\nHTTP_CODE:%{http_code}" --max-time 10 \
-X POST "$DISCORD_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "$payload" 2>/dev/null)
http_code=$(echo "$response" | grep "HTTP_CODE:" | tail -1 | cut -d: -f2)
if [ "$http_code" = "204" ] || [ "$http_code" = "200" ]; then
log "INFO" "Discord notification sent successfully"
else
log "WARN" "Discord notification failed (HTTP $http_code)"
fi
fi
log "INFO" "Grab handler complete"
exit 0
fi
################################################################################
# HANDLE RADARR TEST EVENT (early exit — no API calls needed)
################################################################################
if [ "$EVENT_TYPE" = "Test" ]; then
log "INFO" "============================================"
log "INFO" "Tagarr Import v${SCRIPT_VERSION}"
log "INFO" "Event: Test"
log "INFO" "============================================"
if [ "${DISCORD_ENABLED:-false}" = "true" ] && [ -n "${DISCORD_WEBHOOK_URL:-}" ]; then
log "INFO" "Sending Discord test notification..."
payload=$(jq -n \
--argjson color 16753920 \
--arg footer_text "$DISCORD_FOOTER" \
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" \
'{
embeds: [{
title: "Tagarr Import v'"${SCRIPT_VERSION}"' — Test OK",
color: $color,
fields: [
{ name: "Status", value: "Connection successful", inline: true },
{ name: "Discovery", value: "'"${ENABLE_DISCOVERY:-false}"'", inline: true }
],
footer: { text: $footer_text },
timestamp: $timestamp
}]
}')
response=$(curl -sS -w "\nHTTP_CODE:%{http_code}" -X POST "$DISCORD_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "$payload")
http_code=$(echo "$response" | grep "HTTP_CODE:" | cut -d: -f2)
if [ "$http_code" = "204" ] || [ "$http_code" = "200" ]; then
log "INFO" "Discord test notification sent successfully"
else
log "WARN" "Discord test notification failed (HTTP $http_code)"
fi
fi
log "INFO" "Script completed successfully"
exit 0
fi
################################################################################
# HANDLE MOVIE FILE DELETE EVENT
################################################################################
if [ "$EVENT_TYPE" = "MovieFileDelete" ] || [ "$EVENT_TYPE" = "MovieFileDeleteForUpgrade" ]; then
log "INFO" "============================================"
log "INFO" "Tagarr Import v${SCRIPT_VERSION}"
log "INFO" "Event: $EVENT_TYPE"
log "INFO" "============================================"
log "INFO" "Movie file deleted - removing all managed tags"
# Get movie details
movie_json=$(curl -s "${PRIMARY_RADARR_API_URL}/movie/${MOVIE_ID}?apikey=${PRIMARY_RADARR_API_KEY}")
if [ -z "$movie_json" ]; then
log "ERROR" "Failed to fetch movie details from Radarr"
exit 1
fi
MOVIE_TITLE=$(echo "$movie_json" | jq -r '.title')
MOVIE_YEAR=$(echo "$movie_json" | jq -r '.year')
MOVIE_TMDB_ID=$(echo "$movie_json" | jq -r '.tmdbId')
MOVIE_CURRENT_TAGS=$(echo "$movie_json" | jq -r '(.tags // [])')
log "INFO" "Movie: $MOVIE_TITLE ($MOVIE_YEAR)"
# Get all managed tag IDs
declare -a managed_tag_ids=()
for tag_config in "${RELEASE_GROUPS[@]}"; do
TAG_NAME=$(echo "$tag_config" | cut -d: -f2)
# Get tag ID in primary
primary_tag_id=$(curl -s "${PRIMARY_RADARR_API_URL}/tag?apikey=${PRIMARY_RADARR_API_KEY}" | \
jq -r "(.// []) | .[] | select(.label == \"${TAG_NAME}\") | .id")
if [ -n "$primary_tag_id" ]; then
managed_tag_ids+=("$primary_tag_id")
fi
done
# Check if movie has any managed tags
has_managed_tags=false
for tag_id in "${managed_tag_ids[@]}"; do
if echo "$MOVIE_CURRENT_TAGS" | jq -e "(. // []) | contains([${tag_id}])" > /dev/null 2>&1; then
has_managed_tags=true
break
fi
done
if [ "$has_managed_tags" = "false" ]; then
log "INFO" "Movie has no managed tags - nothing to remove"
else
log "INFO" "Removing managed tags from movie..."
# Get fresh movie object
movie_full=$(curl -s "${PRIMARY_RADARR_API_URL}/movie/${MOVIE_ID}?apikey=${PRIMARY_RADARR_API_KEY}")
current_tags=$(echo "$movie_full" | jq -r '(.tags // [])')
# Remove all managed tags
for tag_id in "${managed_tag_ids[@]}"; do
current_tags=$(echo "$current_tags" | jq "(. // []) | del(.[] | select(. == ${tag_id}))")
done
# Update movie
updated_movie=$(echo "$movie_full" | jq ".tags = ${current_tags}")
curl -s -X PUT "${PRIMARY_RADARR_API_URL}/movie/${MOVIE_ID}?apikey=${PRIMARY_RADARR_API_KEY}" \
-H "Content-Type: application/json" \
-d "$updated_movie" > /dev/null
log "INFO" "Tags removed from primary Radarr"
# Sync to secondary if enabled
if [ "$ENABLE_SYNC_TO_SECONDARY" = "true" ]; then
log "INFO" "Syncing tag removal to $SECONDARY_RADARR_NAME..."
# Find movie in secondary
secondary_movie=$(curl -s "${SECONDARY_RADARR_API_URL}/movie?apikey=${SECONDARY_RADARR_API_KEY}" | \
jq -c "(. // []) | .[] | select(.tmdbId == ${MOVIE_TMDB_ID})")
if [ -n "$secondary_movie" ]; then
secondary_movie_id=$(echo "$secondary_movie" | jq -r '.id')
secondary_current_tags=$(echo "$secondary_movie" | jq -r '(.tags // [])')
log "INFO" "Found movie in $SECONDARY_RADARR_NAME (ID: $secondary_movie_id)"
# Get managed tag IDs in secondary
for tag_config in "${RELEASE_GROUPS[@]}"; do
TAG_NAME=$(echo "$tag_config" | cut -d: -f2)
secondary_tag_id=$(curl -s "${SECONDARY_RADARR_API_URL}/tag?apikey=${SECONDARY_RADARR_API_KEY}" | \
jq -r "(. // []) | .[] | select(.label == \"${TAG_NAME}\") | .id")
if [ -n "$secondary_tag_id" ]; then
secondary_current_tags=$(echo "$secondary_current_tags" | jq "del(.[] | select(. == ${secondary_tag_id}))")
fi
done
# Update secondary movie
secondary_movie_full=$(curl -s "${SECONDARY_RADARR_API_URL}/movie/${secondary_movie_id}?apikey=${SECONDARY_RADARR_API_KEY}")
updated_secondary=$(echo "$secondary_movie_full" | jq ".tags = ${secondary_current_tags}")
curl -s -X PUT "${SECONDARY_RADARR_API_URL}/movie/${secondary_movie_id}?apikey=${SECONDARY_RADARR_API_KEY}" \
-H "Content-Type: application/json" \
-d "$updated_secondary" > /dev/null
log "INFO" "Tags removed from $SECONDARY_RADARR_NAME"
else
log "INFO" "Movie not found in $SECONDARY_RADARR_NAME"
fi
fi
fi
log "INFO" "============================================"
log "INFO" "File delete cleanup completed"
log "INFO" "============================================"
exit 0
fi
################################################################################
# QUALITY/AUDIO FILTER FUNCTIONS
################################################################################
# Check if filename matches quality filters
# EXACT COPY FROM tagarr.sh v1.0.0
check_quality_match() {
local f="$1"
[ "$ENABLE_QUALITY_FILTER" != "true" ] && return 0
# Match MA/Play WEB-DL patterns across naming schemes:
# Standard: MA.WEB-DL MA-WEBDL MA_WEB.DL
# Bracket: [MA][WEBDL-2160p] [MA][WEB-DL]
# Separator between source and WEB: . - _ ][ or ]\s*[
# Uses word boundaries (\b) to prevent "AMZN" matching as "MA" or "IMAX" as "MA"
if [ "$ENABLE_MA_WEBDL" = "true" ]; then
if echo "$f" | grep -Eqi '\bma(\]?\s*\[?|[._-])web([-.]?dl)?'; then
return 0
fi
fi
if [ "$ENABLE_PLAY_WEBDL" = "true" ]; then
if echo "$f" | grep -Eqi '\bplay(\]?\s*\[?|[._-])web([-.]?dl)?'; then
return 0
fi
fi
return 1
}
# Check if filename matches audio filters
# EXACT COPY FROM tagarr.sh v1.0.0
check_audio_match() {
local f="$1"
[ "$ENABLE_AUDIO_FILTER" != "true" ] && return 0
# STRICT: Reject transcoded/upmixed/encoded audio first
# Uses word boundaries to avoid false positives
if echo "$f" | grep -Eqi '\b(upmix|encode|transcode|lossy|converted|re-?encode)\b'; then
return 1
fi
# TrueHD checks - RESPECTS CONFIGURATION
# Only matches if explicitly enabled
if [ "$ENABLE_TRUEHD_ATMOS" = "true" ] || [ "$ENABLE_TRUEHD" = "true" ]; then
if echo "$f" | grep -Eqi '\btruehd\b'; then
if echo "$f" | grep -Eqi '\batmos\b'; then
# TrueHD Atmos - only pass if Atmos is enabled
[ "$ENABLE_TRUEHD_ATMOS" = "true" ] && return 0
else
# TrueHD (non-Atmos) - only pass if non-Atmos is enabled
[ "$ENABLE_TRUEHD" = "true" ] && return 0
fi
fi
fi
# DTS:X check with word boundary
if [ "$ENABLE_DTS_X" = "true" ]; then
if echo "$f" | grep -Eqi '\bdts[._-]?x\b'; then
return 0
fi
fi
# DTS-HD MA check - supports various separators
if [ "$ENABLE_DTS_HD_MA" = "true" ]; then
# Match: DTS-HD.MA or DTS-HD MA or DTS.HD.MA or DTS_HD_MA etc
if echo "$f" | grep -Eqi '\bdts[._ -]?hd[._ -]?ma\b'; then
return 0
fi
fi
return 1
}
################################################################################
# RELEASE GROUP RECOVERY VIA DOWNLOAD ID
################################################################################
# Result variable — set by fix_release_group_from_history() on success.
# Using a global avoids the log-via-tee stdout contamination that would
# occur if we returned the value via echo inside a $() capture.
_RECOVER_RESULT=""
fix_release_group_from_history() {
local movie_id="$1"
local movie_title="$2"
local movie_year="$3"
local current_rg="$4"
local moviefile_id="$5"
local download_id="$6"
_RECOVER_RESULT=""
# Only act on empty/Unknown release groups
if [ -n "$current_rg" ] && [ "$current_rg" != "Unknown" ] && [ "$current_rg" != "null" ]; then
return 1
fi
log "INFO" "Release group missing/unknown — attempting recovery via downloadId..."
# Must have a downloadId to match against
if [ -z "$download_id" ]; then
log "INFO" "No downloadId available — cannot recover"
return 1
fi
# Query history for this movie
local history_json
history_json=$(curl -s -f "${PRIMARY_RADARR_API_URL}/history/movie?movieId=${movie_id}&apikey=${PRIMARY_RADARR_API_KEY}") || history_json=""
if [ -z "$history_json" ] || [ "$history_json" = "null" ] || [ "$history_json" = "[]" ] || \
! echo "$history_json" | jq -e 'type == "array"' > /dev/null 2>&1; then
log "INFO" "No history found for movie"
return 1
fi
# Find grab with matching downloadId — exact match, no walking/guessing
local grab_rg
grab_rg=$(echo "$history_json" | jq -r --arg dlid "$download_id" '
[.[] | select(.eventType == "grabbed" and .downloadId == $dlid)] |
.[0].data.releaseGroup // ""
') || grab_rg=""
if [ -z "$grab_rg" ]; then
log "INFO" "No grab found with downloadId $download_id"
return 1
fi
log "INFO" "Found releaseGroup '$grab_rg' from grab with downloadId $download_id"
if [ -z "$moviefile_id" ] || [ "$moviefile_id" = "null" ]; then
log "WARN" "Cannot determine movieFile ID — skipping fix"
return 1
fi
# Fetch full moviefile object for PUT
local moviefile_json
moviefile_json=$(curl -s -f "${PRIMARY_RADARR_API_URL}/moviefile/${moviefile_id}?apikey=${PRIMARY_RADARR_API_KEY}") || moviefile_json=""
if [ -z "$moviefile_json" ] || [ "$moviefile_json" = "null" ]; then
log "WARN" "Failed to fetch moviefile object — skipping fix"
return 1
fi
# Patch releaseGroup and PUT
local updated_moviefile
updated_moviefile=$(echo "$moviefile_json" | jq --arg rg "$grab_rg" '.releaseGroup = $rg')
local put_response put_http_code
put_response=$(curl -s -w "\nHTTP_CODE:%{http_code}" -X PUT \
"${PRIMARY_RADARR_API_URL}/moviefile/${moviefile_id}?apikey=${PRIMARY_RADARR_API_KEY}" \
-H "Content-Type: application/json" \
-d "$updated_moviefile")
put_http_code=$(echo "$put_response" | grep "HTTP_CODE:" | tail -1 | cut -d: -f2)
if [ "$put_http_code" != "200" ] && [ "$put_http_code" != "202" ]; then
log "WARN" "Failed to update moviefile releaseGroup (HTTP $put_http_code)"
return 1
fi
log "INFO" "Fixed releaseGroup: '$grab_rg' applied to moviefile $moviefile_id"
# Trigger rename so the file reflects the corrected releaseGroup
local rename_response rename_http_code
rename_response=$(curl -s -w "\nHTTP_CODE:%{http_code}" -X POST \
"${PRIMARY_RADARR_API_URL}/command?apikey=${PRIMARY_RADARR_API_KEY}" \
-H "Content-Type: application/json" \
-d "{\"name\":\"RenameFiles\",\"movieId\":${movie_id},\"files\":[${moviefile_id}]}")
rename_http_code=$(echo "$rename_response" | grep "HTTP_CODE:" | tail -1 | cut -d: -f2)
if [ "$rename_http_code" = "200" ] || [ "$rename_http_code" = "201" ]; then
log "INFO" "Rename command triggered for movie $movie_id"
else
log "WARN" "Rename command failed (HTTP $rename_http_code) — file may need manual rename"
fi
_RECOVER_RESULT="$grab_rg"
return 0
}
################################################################################
# MAIN SCRIPT
################################################################################
log "INFO" "============================================"
log "INFO" "Tagarr Import v${SCRIPT_VERSION}"
log "INFO" "Event: $EVENT_TYPE"
log "INFO" "============================================"
# Get movie details from primary Radarr
log "INFO" "Fetching movie details (ID: $MOVIE_ID)..."
movie_json=$(curl -s "${PRIMARY_RADARR_API_URL}/movie/${MOVIE_ID}?apikey=${PRIMARY_RADARR_API_KEY}")
if [ -z "$movie_json" ]; then
log "ERROR" "Failed to fetch movie details from Radarr"
exit 1
fi
MOVIE_TITLE=$(echo "$movie_json" | jq -r '.title')
MOVIE_YEAR=$(echo "$movie_json" | jq -r '.year')
MOVIE_TMDB_ID=$(echo "$movie_json" | jq -r '.tmdbId')
MOVIE_CURRENT_TAGS=$(echo "$movie_json" | jq -r '(.tags // [])')
# Get poster URL (try multiple sources)
MOVIE_POSTER_URL=""
# Try remotePoster first
remote_poster=$(echo "$movie_json" | jq -r '.remotePoster // ""')
if [ -n "$remote_poster" ] && [ "$remote_poster" != "null" ] && [ "$remote_poster" != "" ]; then
MOVIE_POSTER_URL="$remote_poster"
log "INFO" "Poster URL from remotePoster: $MOVIE_POSTER_URL"
else
# Try images array for poster
poster_from_images=$(echo "$movie_json" | jq -r '.images[] | select(.coverType == "poster") | .remoteUrl // .url // "" | select(length > 0)' | head -1)
if [ -n "$poster_from_images" ] && [ "$poster_from_images" != "null" ]; then
MOVIE_POSTER_URL="$poster_from_images"
log "INFO" "Poster URL from images array: $MOVIE_POSTER_URL"
fi
fi
# Fallback to TMDb poster if still empty
if [ -z "$MOVIE_POSTER_URL" ] || [ "$MOVIE_POSTER_URL" = "null" ]; then
if [ -n "$MOVIE_TMDB_ID" ] && [ "$MOVIE_TMDB_ID" != "null" ] && [ "$MOVIE_TMDB_ID" != "0" ]; then
MOVIE_POSTER_URL="https://image.tmdb.org/t/p/w500/placeholder.jpg"
log "INFO" "Using TMDb placeholder poster"
else
log "WARN" "No poster URL available"
fi
fi
# Get file details
MOVIE_FILE_QUALITY=$(echo "$movie_json" | jq -r '.movieFile.quality.quality.name // "Unknown"')
MOVIE_FILE_SIZE_BYTES=$(echo "$movie_json" | jq -r '.movieFile.size // 0')
MOVIE_FILE_SIZE_GB=$(awk "BEGIN {printf \"%.2f\", $MOVIE_FILE_SIZE_BYTES/1073741824}")
MOVIE_RELEASE_GROUP=$(echo "$movie_json" | jq -r '.movieFile.releaseGroup // "Unknown"')
log "INFO" "Movie: $MOVIE_TITLE ($MOVIE_YEAR)"
log "INFO" "File: $MOVIE_FILE_RELATIVE"
if [ "${ENABLE_DEBUG:-false}" = "true" ]; then
log "DEBUG" "Release group: $MOVIE_RELEASE_GROUP"
log "DEBUG" "Quality: $MOVIE_FILE_QUALITY"
log "DEBUG" "Size: ${MOVIE_FILE_SIZE_GB} GiB"
log "DEBUG" "Scene: ${MOVIE_FILE_SCENE:-none}"
fi
# Get file info for matching — priority: file env var > API > downloadId recovery
RELEASE_GROUP_FIELD=$(echo "$movie_json" | jq -r '.movieFile.releaseGroup // ""')
# --- Release group from Radarr file env var (most reliable on import/upgrade) ---
if [ -n "$RELEASE_GROUP_FROM_FILE" ] && [ "$RELEASE_GROUP_FROM_FILE" != "null" ]; then
if [ -z "$RELEASE_GROUP_FIELD" ] || [ "$RELEASE_GROUP_FIELD" = "Unknown" ] || [ "$RELEASE_GROUP_FIELD" = "null" ]; then
log "INFO" "Using release group from file env var: '$RELEASE_GROUP_FROM_FILE' (API had: '${RELEASE_GROUP_FIELD:-empty}')"
RELEASE_GROUP_FIELD="$RELEASE_GROUP_FROM_FILE"
MOVIE_RELEASE_GROUP="$RELEASE_GROUP_FROM_FILE"
fi
fi
# --- Release group recovery via downloadId (fallback for empty/Unknown) ---
if [ "${ENABLE_RECOVER:-true}" = "true" ] && \
{ [ -z "$RELEASE_GROUP_FIELD" ] || [ "$RELEASE_GROUP_FIELD" = "Unknown" ] || [ "$RELEASE_GROUP_FIELD" = "null" ]; }; then
_moviefile_id=$(echo "$movie_json" | jq -r '.movieFile.id // ""')
if fix_release_group_from_history "$MOVIE_ID" "$MOVIE_TITLE" "$MOVIE_YEAR" "$RELEASE_GROUP_FIELD" "$_moviefile_id" "$DOWNLOAD_ID_FROM_EVENT"; then
RELEASE_GROUP_FIELD="$_RECOVER_RESULT"
MOVIE_RELEASE_GROUP="$_RECOVER_RESULT"
RECOVER_GROUP="$_RECOVER_RESULT"
log "INFO" "Proceeding with recovered releaseGroup: $_RECOVER_RESULT"
fi
fi
# --- End release group recovery ---
# Combine all sources for searching
COMBINED_NAME="${MOVIE_FILE_RELATIVE} ${MOVIE_FILE_SCENE}"
COMBINED_LOWER=$(echo "$COMBINED_NAME" | tr '[:upper:]' '[:lower:]')
RELEASE_GROUP_LOWER=$(echo "$RELEASE_GROUP_FIELD" | tr '[:upper:]' '[:lower:]')
log "INFO" "Checking release group matches..."
# Arrays to track what should happen
declare -a tags_to_add=()
declare -a tags_to_remove=()
declare -a tags_to_keep=()
# Check each release group
for tag_config in "${RELEASE_GROUPS[@]}"; do
SEARCH_STRING=$(echo "$tag_config" | cut -d: -f1)
TAG_NAME=$(echo "$tag_config" | cut -d: -f2)
DISPLAY_NAME=$(echo "$tag_config" | cut -d: -f3)
TAG_MODE=$(echo "$tag_config" | cut -d: -f4)
# Defaults
[ -z "$DISPLAY_NAME" ] && DISPLAY_NAME="$TAG_NAME"
[ -z "$TAG_MODE" ] && TAG_MODE="simple"
search_lower=$(echo "$SEARCH_STRING" | tr '[:upper:]' '[:lower:]')
# Check if release group matches (3 places)
match_found=false
match_location=""
if echo "$COMBINED_LOWER" | grep -q "$search_lower"; then
match_found=true
match_location="filename/scene"
elif [ -n "$RELEASE_GROUP_LOWER" ] && echo "$RELEASE_GROUP_LOWER" | grep -q "$search_lower"; then