fix path mapping wrong with smartstring
This commit is contained in:
+32
-15
@@ -25,15 +25,28 @@ class PathMapper:
|
|||||||
|
|
||||||
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 using environment mappings"""
|
"""Convert Sonarr path to container path using environment mappings"""
|
||||||
# Try to match against configured Sonarr root folders
|
print(f"DEBUG: sonarr_path_to_container_path input: {sonarr_path}")
|
||||||
for i, sonarr_root in enumerate(self.sonarr_roots):
|
print(f"DEBUG: sonarr_roots: {self.sonarr_roots}")
|
||||||
if sonarr_path.startswith(sonarr_root):
|
print(f"DEBUG: tv_paths: {self.tv_paths}")
|
||||||
# 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
|
|
||||||
|
|
||||||
|
# Sort roots by length (longest first) to avoid substring matching issues
|
||||||
|
indexed_roots = [(i, root) for i, root in enumerate(self.sonarr_roots)]
|
||||||
|
indexed_roots.sort(key=lambda x: len(x[1]), reverse=True)
|
||||||
|
|
||||||
|
# Try to match against configured Sonarr root folders (longest first)
|
||||||
|
for original_index, sonarr_root in indexed_roots:
|
||||||
|
print(f"DEBUG: Checking sonarr_root[{original_index}]: {sonarr_root}")
|
||||||
|
if sonarr_path.startswith(sonarr_root + '/') or sonarr_path == sonarr_root:
|
||||||
|
print(f"DEBUG: Match found! Index {original_index}")
|
||||||
|
# Map to corresponding TV path
|
||||||
|
if original_index < len(self.tv_paths):
|
||||||
|
container_root = self.tv_paths[original_index]
|
||||||
|
relative_path = sonarr_path[len(sonarr_root):].lstrip('/')
|
||||||
|
result = str(Path(container_root) / relative_path) if relative_path else container_root
|
||||||
|
print(f"DEBUG: Mapped to: {result}")
|
||||||
|
return result
|
||||||
|
|
||||||
|
print(f"DEBUG: No match found, returning original: {sonarr_path}")
|
||||||
# No fallback - if path mapping fails, return original and let validation catch it
|
# No fallback - if path mapping fails, return original and let validation catch it
|
||||||
return sonarr_path
|
return sonarr_path
|
||||||
|
|
||||||
@@ -43,14 +56,18 @@ class PathMapper:
|
|||||||
print(f"DEBUG: radarr_roots: {self.radarr_roots}")
|
print(f"DEBUG: radarr_roots: {self.radarr_roots}")
|
||||||
print(f"DEBUG: movie_paths: {self.movie_paths}")
|
print(f"DEBUG: movie_paths: {self.movie_paths}")
|
||||||
|
|
||||||
# Try to match against configured Radarr root folders
|
# Sort roots by length (longest first) to avoid substring matching issues
|
||||||
for i, radarr_root in enumerate(self.radarr_roots):
|
indexed_roots = [(i, root) for i, root in enumerate(self.radarr_roots)]
|
||||||
print(f"DEBUG: Checking radarr_root[{i}]: {radarr_root}")
|
indexed_roots.sort(key=lambda x: len(x[1]), reverse=True)
|
||||||
if radarr_path.startswith(radarr_root):
|
|
||||||
print(f"DEBUG: Match found! Index {i}")
|
# Try to match against configured Radarr root folders (longest first)
|
||||||
|
for original_index, radarr_root in indexed_roots:
|
||||||
|
print(f"DEBUG: Checking radarr_root[{original_index}]: {radarr_root}")
|
||||||
|
if radarr_path.startswith(radarr_root + '/') or radarr_path == radarr_root:
|
||||||
|
print(f"DEBUG: Match found! Index {original_index}")
|
||||||
# Map to corresponding movie path
|
# Map to corresponding movie path
|
||||||
if i < len(self.movie_paths):
|
if original_index < len(self.movie_paths):
|
||||||
container_root = self.movie_paths[i]
|
container_root = self.movie_paths[original_index]
|
||||||
relative_path = radarr_path[len(radarr_root):].lstrip('/')
|
relative_path = radarr_path[len(radarr_root):].lstrip('/')
|
||||||
result = str(Path(container_root) / relative_path) if relative_path else container_root
|
result = str(Path(container_root) / relative_path) if relative_path else container_root
|
||||||
print(f"DEBUG: Mapped to: {result}")
|
print(f"DEBUG: Mapped to: {result}")
|
||||||
|
|||||||
Reference in New Issue
Block a user