fix: optimize audio track sorting by grouping descriptive tracks and sorting by bitrate, fixes bug that does not identify ATMOS or DD+ as the highest quality available in filenaming.

This commit is contained in:
Andy
2025-09-25 23:21:35 +00:00
parent bc26bf3046
commit a2c6798fe6

View File

@@ -202,17 +202,16 @@ class Tracks:
"""Sort audio tracks by bitrate, descriptive, and optionally language.""" """Sort audio tracks by bitrate, descriptive, and optionally language."""
if not self.audio: if not self.audio:
return return
# bitrate
self.audio.sort(key=lambda x: float(x.bitrate or 0.0), reverse=True)
# descriptive # descriptive
self.audio.sort(key=lambda x: str(x.language) if x.descriptive else "") self.audio.sort(key=lambda x: x.descriptive)
# bitrate (within each descriptive group)
self.audio.sort(key=lambda x: float(x.bitrate or 0.0), reverse=True)
# language # language
for language in reversed(by_language or []): for language in reversed(by_language or []):
if str(language) in ("all", "best"): if str(language) in ("all", "best"):
language = next((x.language for x in self.audio if x.is_original_lang), "") language = next((x.language for x in self.audio if x.is_original_lang), "")
if not language: if not language:
continue continue
self.audio.sort(key=lambda x: str(x.language))
self.audio.sort(key=lambda x: not is_close_match(language, [x.language])) self.audio.sort(key=lambda x: not is_close_match(language, [x.language]))
def sort_subtitles(self, by_language: Optional[Sequence[Union[str, Language]]] = None) -> None: def sort_subtitles(self, by_language: Optional[Sequence[Union[str, Language]]] = None) -> None: