mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-26 19:05:13 +00:00
merge: subtitle.group_by track option
This commit is contained in:
@@ -2397,7 +2397,11 @@ class dl:
|
||||
by_language=processed_audio_sort_lang,
|
||||
codec_priority=config.audio.get("codec_priority"),
|
||||
)
|
||||
title.tracks.sort_subtitles(by_language=s_lang, type_priority=config.subtitle.get("type_priority"))
|
||||
title.tracks.sort_subtitles(
|
||||
by_language=s_lang,
|
||||
type_priority=config.subtitle.get("type_priority"),
|
||||
group_by=config.subtitle.get("group_by"),
|
||||
)
|
||||
|
||||
if list_:
|
||||
available_tracks, _ = title.tracks.tree()
|
||||
|
||||
@@ -289,6 +289,7 @@ class Tracks:
|
||||
self,
|
||||
by_language: Optional[Sequence[Union[str, Language]]] = None,
|
||||
type_priority: Optional[Sequence[str]] = None,
|
||||
group_by: Optional[str] = None,
|
||||
) -> None:
|
||||
"""
|
||||
Sort subtitle tracks by various track attributes to a common P2P standard.
|
||||
@@ -299,30 +300,46 @@ class Tracks:
|
||||
- then rest ascending alphabetically after the prioritized groups
|
||||
(Each section ascending alphabetically, but separated)
|
||||
|
||||
Language Group Order:
|
||||
Type Order:
|
||||
- Forced
|
||||
- Normal
|
||||
- Hard of Hearing (SDH/CC)
|
||||
(Least to most captions expected in the subtitle)
|
||||
|
||||
type_priority overrides the Language Group Order with an explicit ranking of
|
||||
"forced", "normal", and "sdh" (cc counts as sdh); unlisted types fall to the end.
|
||||
The first track after sorting receives the default flag at mux time, so this also
|
||||
controls which subtitle type becomes default.
|
||||
type_priority overrides the Type Order with an explicit ranking of "forced",
|
||||
"normal", and "sdh" (cc counts as sdh); unlisted types fall to the end.
|
||||
|
||||
group_by sets the major key. "type" (default) keeps every forced track together,
|
||||
then every normal, then every SDH, each block ascending by language. "language"
|
||||
groups by language instead, so Finnish sits next to Finnish SDH, with the Type
|
||||
Order applied inside each language.
|
||||
"""
|
||||
if not self.subtitles:
|
||||
return
|
||||
# language groups
|
||||
self.subtitles.sort(key=lambda x: str(x.language))
|
||||
if type_priority:
|
||||
rank = {str(t).lower(): i for i, t in enumerate(type_priority)}
|
||||
default_rank = len(rank)
|
||||
self.subtitles.sort(
|
||||
key=lambda x: rank.get("forced" if x.forced else "sdh" if (x.sdh or x.cc) else "normal", default_rank)
|
||||
)
|
||||
|
||||
def by_type() -> None:
|
||||
if type_priority:
|
||||
rank = {str(t).lower(): i for i, t in enumerate(type_priority)}
|
||||
default_rank = len(rank)
|
||||
self.subtitles.sort(
|
||||
key=lambda x: rank.get(
|
||||
"forced" if x.forced else "sdh" if (x.sdh or x.cc) else "normal", default_rank
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.subtitles.sort(key=lambda x: x.sdh or x.cc)
|
||||
self.subtitles.sort(key=lambda x: x.forced, reverse=True)
|
||||
|
||||
def by_lang() -> None:
|
||||
self.subtitles.sort(key=lambda x: str(x.language))
|
||||
|
||||
# stable sorts, so the last pass is the major key
|
||||
if str(group_by or "type").lower() == "language":
|
||||
by_type()
|
||||
by_lang()
|
||||
else:
|
||||
self.subtitles.sort(key=lambda x: x.sdh or x.cc)
|
||||
self.subtitles.sort(key=lambda x: x.forced, reverse=True)
|
||||
by_lang()
|
||||
by_type()
|
||||
# sections
|
||||
for language in reversed(by_language or []):
|
||||
if str(language) == "all":
|
||||
|
||||
Reference in New Issue
Block a user