fix(importer): pass arr type to format extractor to only compile/import arr specific formats

This commit is contained in:
Sam Chau
2025-08-23 08:23:29 +09:30
parent eb9733807e
commit c30dc33828
2 changed files with 15 additions and 5 deletions

View File

@@ -38,8 +38,8 @@ class ProfileStrategy(ImportStrategy):
# Load profile YAML # Load profile YAML
profile_yaml = load_yaml(f"profile/{filename}.yml") profile_yaml = load_yaml(f"profile/{filename}.yml")
# Extract referenced custom formats # Extract referenced custom formats (only for the target arr type)
format_names = extract_format_names(profile_yaml) format_names = extract_format_names(profile_yaml, self.arr_type)
for format_name in format_names: for format_name in format_names:
# Skip if already processed # Skip if already processed

View File

@@ -46,12 +46,14 @@ def load_yaml(file_path: str) -> Dict[str, Any]:
return yaml.safe_load(f) return yaml.safe_load(f)
def extract_format_names(profile_data: Dict[str, Any]) -> Set[str]: def extract_format_names(profile_data: Dict[str, Any], arr_type: str = None) -> Set[str]:
""" """
Extract all custom format names referenced in a profile. Extract all custom format names referenced in a profile.
Args: Args:
profile_data: Profile YAML data profile_data: Profile YAML data
arr_type: Target arr type ('radarr' or 'sonarr'). If provided, only extracts
formats for that specific arr type.
Returns: Returns:
Set of unique format names Set of unique format names
@@ -64,10 +66,18 @@ def extract_format_names(profile_data: Dict[str, Any]) -> Set[str]:
format_names.add(cf['name']) format_names.add(cf['name'])
# Extract from app-specific custom_formats # Extract from app-specific custom_formats
for key in ['custom_formats_radarr', 'custom_formats_sonarr']: if arr_type:
for cf in profile_data.get(key, []): # Only extract formats for the specific arr type
app_key = f'custom_formats_{arr_type.lower()}'
for cf in profile_data.get(app_key, []):
if isinstance(cf, dict) and 'name' in cf: if isinstance(cf, dict) and 'name' in cf:
format_names.add(cf['name']) format_names.add(cf['name'])
else:
# Extract from all app-specific sections (backwards compatibility)
for key in ['custom_formats_radarr', 'custom_formats_sonarr']:
for cf in profile_data.get(key, []):
if isinstance(cf, dict) and 'name' in cf:
format_names.add(cf['name'])
return format_names return format_names