fix hardcoded paths
This commit is contained in:
+35
-9
@@ -3,30 +3,56 @@
|
||||
Path mapping utilities for NFOGuard
|
||||
Handles conversion between external service paths and container paths
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class PathMapper:
|
||||
"""Handles path mapping between different environments"""
|
||||
|
||||
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:
|
||||
"""Convert Sonarr path to container path"""
|
||||
# Replace /mnt/unionfs/Media with /media
|
||||
"""Convert Sonarr path to container path using environment mappings"""
|
||||
# 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"):
|
||||
return sonarr_path.replace("/mnt/unionfs/Media", "/media")
|
||||
return sonarr_path
|
||||
|
||||
def radarr_path_to_container_path(self, radarr_path: str) -> str:
|
||||
"""Convert Radarr path to container path"""
|
||||
# Replace /mnt/unionfs/Media with /media
|
||||
"""Convert Radarr path to container path using environment mappings"""
|
||||
# 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"):
|
||||
container_path = radarr_path.replace("/mnt/unionfs/Media", "/media")
|
||||
# Keep movies6 as movies6, don't convert to movies/6
|
||||
return container_path
|
||||
return radarr_path.replace("/mnt/unionfs/Media", "/media")
|
||||
return radarr_path
|
||||
|
||||
def container_path_to_host_path(self, container_path: str) -> str:
|
||||
|
||||
Reference in New Issue
Block a user