diff --git a/ripper/naming.py b/ripper/naming.py index 4942c70..8c6b118 100644 --- a/ripper/naming.py +++ b/ripper/naming.py @@ -8,6 +8,26 @@ import sys from .config import AUDIO_CODEC_SCENE, CHANNEL_SCENE +# ISO 639-2/B → ISO 639-1 (uppercase) for common languages +_LANG_MAP = { + "eng": "EN", "deu": "DE", "ger": "DE", "fra": "FR", "fre": "FR", + "spa": "ES", "ita": "IT", "por": "PT", "nld": "NL", "dut": "NL", + "rus": "RU", "jpn": "JA", "zho": "ZH", "chi": "ZH", "kor": "KO", + "ara": "AR", "hin": "HI", "pol": "PL", "tur": "TR", "swe": "SV", + "nor": "NO", "dan": "DA", "fin": "FI", "ces": "CS", "cze": "CS", + "hun": "HU", "ron": "RO", "rum": "RO", "bul": "BG", "hrv": "HR", + "slk": "SK", "slo": "SK", "slv": "SL", "ukr": "UK", "ell": "EL", + "gre": "EL", "heb": "HE", "tha": "TH", "vie": "VI", "ind": "ID", + "msa": "MS", "may": "MS", "cat": "CA", "eus": "EU", "baq": "EU", + "glg": "GL", "lat": "LA", "und": "UND", +} + + +def _iso639_to_2letter(code: str) -> str: + """Convert ISO 639-2/B code to uppercase 2-letter ISO 639-1.""" + return _LANG_MAP.get(code.lower(), code.upper()[:2]) + + def get_resolution_tag(title: dict) -> str: """Return a scene-style resolution tag like 1080p, 2160p, 720p.""" height = title.get("Geometry", {}).get("Height", 0) @@ -123,6 +143,8 @@ def build_scene_name( title: dict, audio_tracks: list[dict], source_tag: str, + codec_tag: str = "x265", + is_10bit: bool = True, ) -> str: """ Build a scene-style filename (without extension). @@ -141,8 +163,9 @@ def build_scene_name( parts.append(get_resolution_tag(title)) parts.append(source_tag) - parts.append("10bit") - parts.append("x265") + if is_10bit: + parts.append("10bit") + parts.append(codec_tag) # Primary audio tag (best quality track overall) if audio_tracks: @@ -152,10 +175,15 @@ def build_scene_name( ) parts.append(scene_audio_tag(primary)) - # Multi-language count - langs = {t.get("LanguageCode", "und") for t in audio_tracks} - if len(langs) > 1: + # Language tag: use ISO codes for ≤3 languages, MULTI-N for more + langs = list(dict.fromkeys( + t.get("LanguageCode", "und") for t in audio_tracks + )) # unique, order-preserving + if len(langs) > 3: parts.append(f"MULTI-{len(langs)}.Audio") + elif len(langs) > 1: + parts.append(".".join(_iso639_to_2letter(l) for l in langs)) + # Single language: no tag needed (implied) return ".".join(parts)