mirror of
https://github.com/Dictionarry-Hub/profilarr.git
synced 2026-01-22 10:51:02 +01:00
fix(compiler): advanced langauge processing
- use database langauge import score, not default - fix except language field
This commit is contained in:
@@ -4,6 +4,7 @@ from typing import Dict, List, Any, Optional
|
||||
from .mappings import TargetApp, ValueResolver
|
||||
from .utils import load_regex_patterns
|
||||
from ..db.queries.format_renames import is_format_in_renames
|
||||
from ..db.queries.settings import get_language_import_score
|
||||
from .logger import get_import_logger
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -119,7 +120,17 @@ def _compile_condition(
|
||||
language_name = condition.get('language', '').lower()
|
||||
try:
|
||||
language_data = ValueResolver.get_language(language_name, target_app, for_profile=False)
|
||||
spec['fields'] = [{'name': 'value', 'value': language_data['id']}]
|
||||
fields = [{'name': 'value', 'value': language_data['id']}]
|
||||
|
||||
# Handle exceptLanguage field if present
|
||||
if 'exceptLanguage' in condition:
|
||||
except_value = condition['exceptLanguage']
|
||||
fields.append({
|
||||
'name': 'exceptLanguage',
|
||||
'value': except_value
|
||||
})
|
||||
|
||||
spec['fields'] = fields
|
||||
except Exception:
|
||||
import_logger = get_import_logger()
|
||||
import_logger.warning(f"Language not found: {language_name}")
|
||||
@@ -281,25 +292,31 @@ def compile_profile_to_api_structure(
|
||||
if language != 'any' and '_' in language:
|
||||
behavior, language_code = language.split('_', 1)
|
||||
|
||||
# Add "Not [Language]" format with appropriate score
|
||||
# Get the score from database instead of hardcoding
|
||||
language_score = get_language_import_score()
|
||||
|
||||
# Use proper capitalization for the language name
|
||||
lang_display = language_code.capitalize()
|
||||
not_language_name = f"Not {lang_display}"
|
||||
format_items.append({
|
||||
'name': not_language_name,
|
||||
'score': -9999 # Standard score for language exclusion
|
||||
})
|
||||
|
||||
# For 'only' behavior, add additional formats
|
||||
if behavior == 'only':
|
||||
# Handle behaviors: 'must' and 'only' (matching old working logic)
|
||||
if behavior in ['must', 'only']:
|
||||
# Add "Not [Language]" format with score from database
|
||||
not_language_name = f"Not {lang_display}"
|
||||
format_items.append({
|
||||
'name': f"Not Only {lang_display}",
|
||||
'score': -9999
|
||||
})
|
||||
format_items.append({
|
||||
'name': f"Not Only {lang_display} (Missing)",
|
||||
'score': -9999
|
||||
'name': not_language_name,
|
||||
'score': language_score
|
||||
})
|
||||
|
||||
# For 'only' behavior, add additional formats
|
||||
if behavior == 'only':
|
||||
format_items.append({
|
||||
'name': f"Not Only {lang_display}",
|
||||
'score': language_score
|
||||
})
|
||||
format_items.append({
|
||||
'name': f"Not Only {lang_display} (Missing)",
|
||||
'score': language_score
|
||||
})
|
||||
|
||||
# Main custom formats
|
||||
for cf in profile_yaml.get('custom_formats', []):
|
||||
|
||||
@@ -77,7 +77,7 @@ def generate_language_formats(language: str, arr_type: str) -> List[Dict[str, An
|
||||
Generate language-specific format configurations.
|
||||
|
||||
Args:
|
||||
language: Language string (e.g., 'must_english', 'prefer_french')
|
||||
language: Language string (e.g., 'must_english', 'only_french')
|
||||
arr_type: 'radarr' or 'sonarr'
|
||||
|
||||
Returns:
|
||||
@@ -89,50 +89,54 @@ def generate_language_formats(language: str, arr_type: str) -> List[Dict[str, An
|
||||
behavior, language_code = language.split('_', 1)
|
||||
formats = []
|
||||
|
||||
# Load base "Not English" format as template
|
||||
try:
|
||||
base_format = load_yaml('custom_format/Not English.yml')
|
||||
|
||||
# Create "Not [Language]" format
|
||||
not_format = base_format.copy()
|
||||
lang_display = language_code.capitalize()
|
||||
not_format['name'] = f"Not {lang_display}"
|
||||
|
||||
# Update conditions for the specific language
|
||||
for condition in not_format.get('conditions', []):
|
||||
if condition.get('type') == 'language':
|
||||
condition['language'] = language_code
|
||||
if 'name' in condition:
|
||||
condition['name'] = condition['name'].replace('English', lang_display)
|
||||
|
||||
formats.append(not_format)
|
||||
|
||||
# For 'only' behavior, add additional formats
|
||||
if behavior == 'only':
|
||||
additional_format_names = [
|
||||
"Not Only English",
|
||||
"Not Only English (Missing)"
|
||||
]
|
||||
# Handle behaviors: 'must' and 'only' (matching old working logic)
|
||||
if behavior in ['must', 'only']:
|
||||
# Load base "Not English" format as template
|
||||
try:
|
||||
base_format = load_yaml('custom_format/Not English.yml')
|
||||
|
||||
for format_name in additional_format_names:
|
||||
try:
|
||||
additional = load_yaml(f'custom_format/{format_name}.yml')
|
||||
additional['name'] = additional['name'].replace('English', lang_display)
|
||||
|
||||
for condition in additional.get('conditions', []):
|
||||
if condition.get('type') == 'language':
|
||||
condition['language'] = language_code
|
||||
if 'name' in condition:
|
||||
condition['name'] = condition['name'].replace('English', lang_display)
|
||||
|
||||
formats.append(additional)
|
||||
except Exception as e:
|
||||
# Silent fail - format doesn't exist
|
||||
pass
|
||||
# Create "Not [Language]" format
|
||||
not_format = base_format.copy()
|
||||
lang_display = language_code.capitalize()
|
||||
not_format['name'] = f"Not {lang_display}"
|
||||
|
||||
# Update conditions for the specific language
|
||||
for condition in not_format.get('conditions', []):
|
||||
if condition.get('type') == 'language':
|
||||
condition['language'] = language_code
|
||||
if 'name' in condition:
|
||||
condition['name'] = condition['name'].replace('English', lang_display)
|
||||
# Note: exceptLanguage field is preserved from the base format
|
||||
|
||||
formats.append(not_format)
|
||||
|
||||
# For 'only' behavior, add additional formats
|
||||
if behavior == 'only':
|
||||
additional_format_names = [
|
||||
"Not Only English",
|
||||
"Not Only English (Missing)"
|
||||
]
|
||||
|
||||
for format_name in additional_format_names:
|
||||
try:
|
||||
additional = load_yaml(f'custom_format/{format_name}.yml')
|
||||
additional['name'] = additional['name'].replace('English', lang_display)
|
||||
|
||||
for condition in additional.get('conditions', []):
|
||||
if condition.get('type') == 'language':
|
||||
condition['language'] = language_code
|
||||
if 'name' in condition:
|
||||
condition['name'] = condition['name'].replace('English', lang_display)
|
||||
# Note: exceptLanguage field is preserved from the base format
|
||||
|
||||
formats.append(additional)
|
||||
except Exception as e:
|
||||
# Silent fail - format doesn't exist
|
||||
pass
|
||||
|
||||
except Exception as e:
|
||||
# Silent fail - will be caught at higher level
|
||||
pass
|
||||
except Exception as e:
|
||||
# Silent fail - will be caught at higher level
|
||||
pass
|
||||
|
||||
return formats
|
||||
|
||||
|
||||
Reference in New Issue
Block a user