fix hardcoded paths
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
# MEDIA PATHS (REQUIRED) - FIXED
|
# MEDIA PATHS (REQUIRED) - FIXED
|
||||||
# ===========================================
|
# ===========================================
|
||||||
# Container paths (what NFOGuard sees inside container)
|
# Container paths (what NFOGuard sees inside container)
|
||||||
MOVIE_PATHS=/media/movies,/media/movies6
|
MOVIE_PATHS=/media/Movies/movies,/media/Movies/movies6
|
||||||
TV_PATHS=/media/TV/tv,/media/TV/tv6
|
TV_PATHS=/media/TV/tv,/media/TV/tv6
|
||||||
|
|
||||||
# Radarr paths (what Radarr sees on the host system)
|
# Radarr paths (what Radarr sees on the host system)
|
||||||
|
|||||||
+35
-9
@@ -3,30 +3,56 @@
|
|||||||
Path mapping utilities for NFOGuard
|
Path mapping utilities for NFOGuard
|
||||||
Handles conversion between external service paths and container paths
|
Handles conversion between external service paths and container paths
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class PathMapper:
|
class PathMapper:
|
||||||
"""Handles path mapping between different environments"""
|
"""Handles path mapping between different environments"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
# Load path mappings from environment variables
|
||||||
|
self.radarr_roots = self._parse_path_list(os.environ.get("RADARR_ROOT_FOLDERS", ""))
|
||||||
|
self.sonarr_roots = self._parse_path_list(os.environ.get("SONARR_ROOT_FOLDERS", ""))
|
||||||
|
self.movie_paths = self._parse_path_list(os.environ.get("MOVIE_PATHS", ""))
|
||||||
|
self.tv_paths = self._parse_path_list(os.environ.get("TV_PATHS", ""))
|
||||||
|
|
||||||
|
def _parse_path_list(self, path_string: str) -> list:
|
||||||
|
"""Parse comma-separated path string into list"""
|
||||||
|
if not path_string:
|
||||||
|
return []
|
||||||
|
return [p.strip() for p in path_string.split(",") if p.strip()]
|
||||||
|
|
||||||
def sonarr_path_to_container_path(self, sonarr_path: str) -> str:
|
def sonarr_path_to_container_path(self, sonarr_path: str) -> str:
|
||||||
"""Convert Sonarr path to container path"""
|
"""Convert Sonarr path to container path using environment mappings"""
|
||||||
# Replace /mnt/unionfs/Media with /media
|
# Try to match against configured Sonarr root folders
|
||||||
|
for i, sonarr_root in enumerate(self.sonarr_roots):
|
||||||
|
if sonarr_path.startswith(sonarr_root):
|
||||||
|
# Map to corresponding TV path
|
||||||
|
if i < len(self.tv_paths):
|
||||||
|
container_root = self.tv_paths[i]
|
||||||
|
relative_path = sonarr_path[len(sonarr_root):].lstrip('/')
|
||||||
|
return str(Path(container_root) / relative_path) if relative_path else container_root
|
||||||
|
|
||||||
|
# Fallback: simple replacement for backward compatibility
|
||||||
if sonarr_path.startswith("/mnt/unionfs/Media"):
|
if sonarr_path.startswith("/mnt/unionfs/Media"):
|
||||||
return sonarr_path.replace("/mnt/unionfs/Media", "/media")
|
return sonarr_path.replace("/mnt/unionfs/Media", "/media")
|
||||||
return sonarr_path
|
return sonarr_path
|
||||||
|
|
||||||
def radarr_path_to_container_path(self, radarr_path: str) -> str:
|
def radarr_path_to_container_path(self, radarr_path: str) -> str:
|
||||||
"""Convert Radarr path to container path"""
|
"""Convert Radarr path to container path using environment mappings"""
|
||||||
# Replace /mnt/unionfs/Media with /media
|
# Try to match against configured Radarr root folders
|
||||||
|
for i, radarr_root in enumerate(self.radarr_roots):
|
||||||
|
if radarr_path.startswith(radarr_root):
|
||||||
|
# Map to corresponding movie path
|
||||||
|
if i < len(self.movie_paths):
|
||||||
|
container_root = self.movie_paths[i]
|
||||||
|
relative_path = radarr_path[len(radarr_root):].lstrip('/')
|
||||||
|
return str(Path(container_root) / relative_path) if relative_path else container_root
|
||||||
|
|
||||||
|
# Fallback: simple replacement for backward compatibility
|
||||||
if radarr_path.startswith("/mnt/unionfs/Media"):
|
if radarr_path.startswith("/mnt/unionfs/Media"):
|
||||||
container_path = radarr_path.replace("/mnt/unionfs/Media", "/media")
|
return radarr_path.replace("/mnt/unionfs/Media", "/media")
|
||||||
# Keep movies6 as movies6, don't convert to movies/6
|
|
||||||
return container_path
|
|
||||||
return radarr_path
|
return radarr_path
|
||||||
|
|
||||||
def container_path_to_host_path(self, container_path: str) -> str:
|
def container_path_to_host_path(self, container_path: str) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user