FEATURE: all versions use single source of truth for codec/container/file_extension info
This commit is contained in:
+11
-33
@@ -1,16 +1,17 @@
|
||||
# audio_splitter/formats.py
|
||||
"""Container format decision and validation."""
|
||||
|
||||
from typing import Dict, Optional
|
||||
|
||||
from .constants import FORMAT_INFO
|
||||
from .constants import FORMAT_INFO, CODEC_TO_CONTAINER_MAP, CONTAINER_INFO
|
||||
|
||||
|
||||
def determine_default_format(container: Optional[str], codec: Optional[str]) -> Optional[str]:
|
||||
"""
|
||||
Given the container format and audio codec, determine the recommended output format.
|
||||
|
||||
This is used when the user has not explicitly specified a format.
|
||||
It prioritizes the codec to choose the most appropriate container/extension.
|
||||
This uses the CODEC_TO_CONTAINER_MAP to map codec → container.
|
||||
If the codec is not found, it falls back to the container.
|
||||
|
||||
Args:
|
||||
container: Container name (e.g., 'ogg', 'mp4', 'matroska') as returned by get_container_format().
|
||||
@@ -22,37 +23,14 @@ def determine_default_format(container: Optional[str], codec: Optional[str]) ->
|
||||
if not container:
|
||||
return None
|
||||
|
||||
# Codec-based decisions (highest priority)
|
||||
if codec == 'opus':
|
||||
return 'opus'
|
||||
if codec in ('aac', 'alac', 'he-aac'):
|
||||
return 'm4a'
|
||||
if codec == 'mp3':
|
||||
return 'mp3'
|
||||
if codec == 'vorbis':
|
||||
return 'ogg'
|
||||
if codec == 'flac':
|
||||
return 'flac'
|
||||
# Codec-based decision (highest priority)
|
||||
if codec and codec in CODEC_TO_CONTAINER_MAP:
|
||||
return CODEC_TO_CONTAINER_MAP[codec]
|
||||
|
||||
# Container-based fallback (lower priority)
|
||||
if container in ('mp4', 'm4a', 'mov', '3gp'):
|
||||
return 'mp4'
|
||||
if container in ('matroska', 'webm'):
|
||||
return 'matroska'
|
||||
if container in ('ogg',):
|
||||
return 'ogg'
|
||||
if container in ('mp3', 'mpeg'):
|
||||
return 'mp3'
|
||||
if container == 'flac':
|
||||
return 'flac'
|
||||
if container == 'wav':
|
||||
return 'wav'
|
||||
if container == 'aac':
|
||||
return 'aac'
|
||||
if container == 'opus':
|
||||
return 'opus'
|
||||
if container == 'amr':
|
||||
return 'amr'
|
||||
# Container-based fallback (lowest priority)
|
||||
# Ensure the container is in FORMAT_INFO
|
||||
if container in FORMAT_INFO:
|
||||
return container
|
||||
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user