22 lines
731 B
Python
22 lines
731 B
Python
"""Shared Sonarr/Radarr configuration helpers."""
|
|
|
|
from typing import Any
|
|
|
|
|
|
class RootFolderNotFoundError(ValueError):
|
|
pass
|
|
|
|
|
|
async def resolve_root_folder_path(client: Any, root_folder: str, service_name: str) -> str:
|
|
configured = str(root_folder or "").strip()
|
|
if not configured.isdigit():
|
|
return configured
|
|
folders = await client.get_root_folders()
|
|
if isinstance(folders, list):
|
|
for folder in folders:
|
|
if isinstance(folder, dict) and folder.get("id") == int(configured):
|
|
path = str(folder.get("path") or "").strip()
|
|
if path:
|
|
return path
|
|
raise RootFolderNotFoundError(f"{service_name} root folder id {configured} not found")
|