This commit is contained in:
CodeName393
2026-02-26 02:01:45 +09:00
committed by GitHub
parent ad7dd69ecd
commit a4e1c6bb75

View File

@@ -102,6 +102,27 @@ class Episode(Title):
primary_audio_track = sorted_audio[0] primary_audio_track = sorted_audio[0]
unique_audio_languages = len({x.language.split("-")[0] for x in media_info.audio_tracks if x.language}) unique_audio_languages = len({x.language.split("-")[0] for x in media_info.audio_tracks if x.language})
def _get_resolution_token(track: Any) -> str:
if not track or not getattr(track, "height", None):
return ""
width = getattr(track, "width", track.height)
resolution = min(width, track.height)
try:
dar = getattr(track, "other_display_aspect_ratio", None) or []
if dar and dar[0]:
aspect_ratio = [int(float(plane)) for plane in str(dar[0]).split(":")]
if len(aspect_ratio) == 1:
aspect_ratio.append(1)
ratio = aspect_ratio[0] / aspect_ratio[1]
if ratio not in (16 / 9, 4 / 3, 9 / 16, 3 / 4):
resolution = int(max(width, track.height) * (9 / 16))
except Exception:
pass
scan_suffix = "i" if str(getattr(track, "scan_type", "")).lower() == "interlaced" else "p"
return f"{resolution}{scan_suffix}"
# Title [Year] SXXEXX Name (or Title [Year] SXX if folder) # Title [Year] SXXEXX Name (or Title [Year] SXX if folder)
if folder: if folder:
name = f"{self.title}" name = f"{self.title}"
@@ -121,7 +142,7 @@ class Episode(Title):
name += f" - S{self.season:02}E{self.number:02}" name += f" - S{self.season:02}E{self.number:02}"
# Add episode name with dash separator # Add episode name with dash separator
if self.name: if self.name and config.insert_episodename_into_filenames:
name += f" - {self.name}" name += f" - {self.name}"
name = name.strip() name = name.strip()
@@ -135,30 +156,10 @@ class Episode(Title):
name=self.name if self.name and config.insert_episodename_into_filenames else "", name=self.name if self.name and config.insert_episodename_into_filenames else "",
).strip() ).strip()
if config.scene_naming:
# Resolution
if primary_video_track: if primary_video_track:
resolution = primary_video_track.height resolution_token = _get_resolution_token(primary_video_track)
aspect_ratio = [ if resolution_token:
int(float(plane)) for plane in primary_video_track.other_display_aspect_ratio[0].split(":") name += f" {resolution_token}"
]
if len(aspect_ratio) == 1:
# e.g., aspect ratio of 2 (2.00:1) would end up as `(2.0,)`, add 1
aspect_ratio.append(1)
if aspect_ratio[0] / aspect_ratio[1] not in (16 / 9, 4 / 3):
# We want the resolution represented in a 4:3 or 16:9 canvas.
# If it's not 4:3 or 16:9, calculate as if it's inside a 16:9 canvas,
# otherwise the track's height value is fine.
# We are assuming this title is some weird aspect ratio so most
# likely a movie or HD source, so it's most likely widescreen so
# 16:9 canvas makes the most sense.
resolution = int(primary_video_track.width * (9 / 16))
# Determine scan type suffix - default to "p", use "i" only if explicitly interlaced
scan_suffix = "p"
scan_type = getattr(primary_video_track, 'scan_type', None)
if scan_type and str(scan_type).lower() == "interlaced":
scan_suffix = "i"
name += f" {resolution}{scan_suffix}"
# Service (use track source if available) # Service (use track source if available)
if show_service: if show_service:
@@ -209,17 +210,29 @@ class Episode(Title):
) )
frame_rate = float(primary_video_track.frame_rate) frame_rate = float(primary_video_track.frame_rate)
def _append_token(current: str, token: Optional[str]) -> str:
token = (token or "").strip()
current = current.rstrip()
if not token:
return current
if current.endswith(f" {token}"):
return current
return f"{current} {token}"
# Primary HDR format detection # Primary HDR format detection
if hdr_format: if hdr_format:
if hdr_format_full.startswith("Dolby Vision"): if hdr_format_full.startswith("Dolby Vision"):
name += " DV" name = _append_token(name, "DV")
if any( if any(
indicator in (hdr_format_full + " " + hdr_format) indicator in (hdr_format_full + " " + hdr_format)
for indicator in ["HDR10", "SMPTE ST 2086"] for indicator in ["HDR10", "SMPTE ST 2086"]
): ):
name += " HDR" name = _append_token(name, "HDR")
elif "HDR Vivid" in hdr_format:
name = _append_token(name, "HDR")
else: else:
name += f" {DYNAMIC_RANGE_MAP.get(hdr_format)} " dynamic_range = DYNAMIC_RANGE_MAP.get(hdr_format) or hdr_format or ""
name = _append_token(name, dynamic_range)
elif "HLG" in trc or "Hybrid Log-Gamma" in trc or "ARIB STD-B67" in trc or "arib-std-b67" in trc.lower(): elif "HLG" in trc or "Hybrid Log-Gamma" in trc or "ARIB STD-B67" in trc or "arib-std-b67" in trc.lower():
name += " HLG" name += " HLG"
elif any(indicator in trc for indicator in ["PQ", "SMPTE ST 2084", "BT.2100"]) or "smpte2084" in trc.lower() or "bt.2020-10" in trc.lower(): elif any(indicator in trc for indicator in ["PQ", "SMPTE ST 2084", "BT.2100"]) or "smpte2084" in trc.lower() or "bt.2020-10" in trc.lower():
@@ -231,10 +244,7 @@ class Episode(Title):
if config.tag: if config.tag:
name += f"-{config.tag}" name += f"-{config.tag}"
return sanitize_filename(name) return sanitize_filename(name, "." if config.scene_naming else " ")
else:
# Simple naming style without technical details - use spaces instead of dots
return sanitize_filename(name, " ")
class Series(SortedKeyList, ABC): class Series(SortedKeyList, ABC):