now i fixed arrs ckean, maybe?

This commit is contained in:
2026-04-24 17:44:11 -04:00
parent b3f72417a4
commit 5f940a7181
4 changed files with 46 additions and 28 deletions
+20 -3
View File
@@ -90,7 +90,19 @@ fi
LIDARR_URL="$HOST1_LIDARR_URL"
LIDARR_API_KEY="$HOST1_LIDARR_API_KEY"
LIDARR_MUSIC_ROOT="$HOST1_LIDARR_MUSIC_ROOT"
LIDARR_CONTAINER="Lidarr" # Docker container name for health check
LIDARR_CONTAINER="Lidarr"
# Load path map — translates container paths from API to host paths on disk
declare -A ARR_PATH_MAP
if [[ "$LOCAL_SERVER_NAME" == "$HOST1" ]]; then
for key in "${!HOST1_LIDARR_PATH_MAP[@]}"; do
ARR_PATH_MAP["$key"]="${HOST1_LIDARR_PATH_MAP[$key]}"
done
else
for key in "${!HOST2_LIDARR_PATH_MAP[@]}"; do
ARR_PATH_MAP["$key"]="${HOST2_LIDARR_PATH_MAP[$key]}"
done
fi
info "Lidarr instance: $LOCAL_SERVER_NAME$LIDARR_URL"
info "Music root: $LIDARR_MUSIC_ROOT"
@@ -253,7 +265,12 @@ while IFS= read -r artist_id; do
[[ -z "$artist_id" ]] && continue
ARTIST_TRACKS=$(lidarr_api "trackFile?artistId=${artist_id}" 2>/dev/null)
if [[ -n "$ARTIST_TRACKS" ]]; then
echo "$ARTIST_TRACKS" | jq -r '.[].path' 2>/dev/null >> "$TRACKED_FILE"
if [[ -n "$ARTIST_TRACKS" ]]; then
while IFS= read -r api_path; do
[[ -z "$api_path" ]] && continue
translate_path "$api_path" >> "$TRACKED_FILE"
done < <(echo "$ARTIST_TRACKS" | jq -r '.[].path' 2>/dev/null)
fi
fi
done <<< "$ARTIST_IDS"
@@ -321,7 +338,7 @@ while IFS= read -r filepath; do
fi
if is_protected_file "$filepath"; then
log "PROTECTED: $filepath"
log "$ICON_PROTECTED PROTECTED: $filepath"
((PROTECTED_COUNT++))
continue
fi
+8 -8
View File
@@ -70,14 +70,14 @@ else
fi
# Load path map for this host
declare -A PATH_MAP
declare -A ARR_PATH_MAP
if [[ "$LOCAL_SERVER_NAME" == "$HOST1" ]]; then
for key in "${!HOST1_RADARR_PATH_MAP[@]}"; do
PATH_MAP["$key"]="${HOST1_RADARR_PATH_MAP[$key]}"
ARR_PATH_MAP["$key"]="${HOST1_RADARR_PATH_MAP[$key]}"
done
else
for key in "${!HOST2_RADARR_PATH_MAP[@]}"; do
PATH_MAP["$key"]="${HOST2_RADARR_PATH_MAP[$key]}"
ARR_PATH_MAP["$key"]="${HOST2_RADARR_PATH_MAP[$key]}"
done
fi
@@ -188,7 +188,7 @@ trap "rm -rf $TMP_DIR" EXIT
TRACKED_FILE="$TMP_DIR/tracked_paths.txt"
while IFS= read -r api_path; do
[[ -z "$api_path" ]] && continue
translate_path "$api_path" PATH_MAP >> "$TRACKED_FILE"
translate_path "$api_path" >> "$TRACKED_FILE"
done < <(echo "$MOVIEFILE_RESPONSE" | jq -r '.[].path' 2>/dev/null)
sort -u "$TRACKED_FILE" -o "$TRACKED_FILE"
@@ -232,7 +232,7 @@ while IFS= read -r filepath; do
fi
if is_protected_file "$filepath"; then
log "PROTECTED: $filepath"
log "$ICON_PROTECTED PROTECTED: $filepath"
((PROTECTED_COUNT++))
continue
fi
@@ -273,8 +273,8 @@ while IFS= read -r filepath; do
fi
done < <(
# Scan all host paths defined in PATH_MAP — covers all root folders managed by Radarr
for host_path in "${PATH_MAP[@]}" "$RADARR_MOVIES_ROOT"; do
# Scan all host paths defined in ARR_PATH_MAP — covers all root folders managed by Radarr
for host_path in "${ARR_PATH_MAP[@]}" "$RADARR_MOVIES_ROOT"; do
[[ -d "$host_path" ]] && find "$host_path" -type f 2>/dev/null
done | sort -u
)
@@ -282,7 +282,7 @@ done < <(
if [[ "$DRY_RUN" == false ]]; then
echo ""
info "Cleaning up empty folders..."
for host_path in "${PATH_MAP[@]}" "$RADARR_MOVIES_ROOT"; do
for host_path in "${ARR_PATH_MAP[@]}" "$RADARR_MOVIES_ROOT"; do
[[ -d "$host_path" ]] && \
find "$host_path" -mindepth 1 -type d -empty -delete 2>/dev/null
done
+8 -8
View File
@@ -70,14 +70,14 @@ else
fi
# Load path map for this host
declare -A PATH_MAP
declare -A ARR_PATH_MAP
if [[ "$LOCAL_SERVER_NAME" == "$HOST1" ]]; then
for key in "${!HOST1_SONARR_PATH_MAP[@]}"; do
PATH_MAP["$key"]="${HOST1_SONARR_PATH_MAP[$key]}"
ARR_PATH_MAP["$key"]="${HOST1_SONARR_PATH_MAP[$key]}"
done
else
for key in "${!HOST2_SONARR_PATH_MAP[@]}"; do
PATH_MAP["$key"]="${HOST2_SONARR_PATH_MAP[$key]}"
ARR_PATH_MAP["$key"]="${HOST2_SONARR_PATH_MAP[$key]}"
done
fi
@@ -188,7 +188,7 @@ trap "rm -rf $TMP_DIR" EXIT
TRACKED_FILE="$TMP_DIR/tracked_paths.txt"
while IFS= read -r api_path; do
[[ -z "$api_path" ]] && continue
translate_path "$api_path" PATH_MAP >> "$TRACKED_FILE"
translate_path "$api_path" >> "$TRACKED_FILE"
done < <(echo "$EPISODEFILE_RESPONSE" | jq -r '.[].path' 2>/dev/null)
sort -u "$TRACKED_FILE" -o "$TRACKED_FILE"
@@ -232,7 +232,7 @@ while IFS= read -r filepath; do
fi
if is_protected_file "$filepath"; then
log "PROTECTED: $filepath"
log "$ICON_PROTECTED PROTECTED: $filepath"
((PROTECTED_COUNT++))
continue
fi
@@ -273,8 +273,8 @@ while IFS= read -r filepath; do
fi
done < <(
# Scan all host paths defined in PATH_MAP — covers all root folders managed by Sonarr
for host_path in "${PATH_MAP[@]}" "$SONARR_TV_ROOT"; do
# Scan all host paths defined in ARR_PATH_MAP — covers all root folders managed by Sonarr
for host_path in "${ARR_PATH_MAP[@]}" "$SONARR_TV_ROOT"; do
[[ -d "$host_path" ]] && find "$host_path" -type f 2>/dev/null
done | sort -u
)
@@ -282,7 +282,7 @@ done < <(
if [[ "$DRY_RUN" == false ]]; then
echo ""
info "Cleaning up empty folders..."
for host_path in "${PATH_MAP[@]}" "$SONARR_TV_ROOT"; do
for host_path in "${ARR_PATH_MAP[@]}" "$SONARR_TV_ROOT"; do
[[ -d "$host_path" ]] && \
find "$host_path" -mindepth 1 -type d -empty -delete 2>/dev/null
done
+10 -9
View File
@@ -93,6 +93,7 @@ ICON_START="▶️" # start command being issued
ICON_STARTED="💚" # container confirmed started
ICON_RUNNING="🟢" # container already running when checked
ICON_SKIP="⏭️" # skipping — already running healthy instance
ICON_PROTECTED="🔰" # file/item is protected — never delete
ICON_NOT_RUNNING="⭕" # container already stopped when checked
# Transfer
@@ -851,25 +852,25 @@ _release_rsync_on_exit() {
# Usage: check_api "http://localhost:8989" "Sonarr" || exit 1
# -----------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------
# translate_path — translate container path to host path using a PATH_MAP array
# Used by arr cleanup scripts — arrs store paths using container mounts, not host paths
# translate_path — translate container path to host path
# Uses ARR_PATH_MAP associative array — must be declared in calling script before use
#
# Usage:
# translate_path "/ext-music/Artist/Album/track.flac" HOST1_LIDARR_PATH_MAP
# declare -A ARR_PATH_MAP=(["/ext-music"]="/mnt/user/Music-New")
# translate_path "/ext-music/Artist/Album/track.flac"
# Returns: /mnt/user/Music-New/Artist/Album/track.flac
#
# If no match found in PATH_MAP — returns path unchanged
# If no match found — returns path unchanged
# Handles longest-match first to avoid partial path collisions
# ARR_PATH_MAP must be exported or declared global before calling
# -----------------------------------------------------------------------------------------------
translate_path() {
local api_path="$1"
local -n _path_map="$2" # nameref to the associative array
local best_match=""
local best_len=0
# Find longest matching prefix (handles overlapping container paths)
for container_path in "${!_path_map[@]}"; do
# Find longest matching container path prefix
for container_path in "${!ARR_PATH_MAP[@]}"; do
if [[ "$api_path" == "$container_path"* ]]; then
if [[ "${#container_path}" -gt "$best_len" ]]; then
best_match="$container_path"
@@ -879,7 +880,7 @@ translate_path() {
done
if [[ -n "$best_match" ]]; then
echo "${_path_map[$best_match]}${api_path#$best_match}"
echo "${ARR_PATH_MAP[$best_match]}${api_path#$best_match}"
else
echo "$api_path" # no match — return unchanged
fi