Merge pull request #66 from CodeName393/Config-Filenames

Add option to include episode titles and fix video resolution bug
This commit is contained in:
Sp5rky
2026-02-26 10:30:07 -07:00
committed by GitHub
4 changed files with 20 additions and 17 deletions

View File

@@ -97,6 +97,7 @@ class Config:
self.dash_naming: bool = kwargs.get("dash_naming", False) self.dash_naming: bool = kwargs.get("dash_naming", False)
self.series_year: bool = kwargs.get("series_year", True) self.series_year: bool = kwargs.get("series_year", True)
self.unicode_filenames: bool = kwargs.get("unicode_filenames", False) self.unicode_filenames: bool = kwargs.get("unicode_filenames", False)
self.insert_episodename_into_filenames: bool = kwargs.get("insert_episodename_into_filenames", True)
self.title_cache_time: int = kwargs.get("title_cache_time", 1800) # 30 minutes default self.title_cache_time: int = kwargs.get("title_cache_time", 1800) # 30 minutes default
self.title_cache_max_retention: int = kwargs.get("title_cache_max_retention", 86400) # 24 hours default self.title_cache_max_retention: int = kwargs.get("title_cache_max_retention", 86400) # 24 hours default

View File

@@ -105,22 +105,21 @@ class Episode(Title):
def _get_resolution_token(track: Any) -> str: def _get_resolution_token(track: Any) -> str:
if not track or not getattr(track, "height", None): if not track or not getattr(track, "height", None):
return "" return ""
resolution = track.height width = getattr(track, "width", track.height)
resolution = min(width, track.height)
try: try:
dar = getattr(track, "other_display_aspect_ratio", None) or [] dar = getattr(track, "other_display_aspect_ratio", None) or []
if dar and dar[0]: if dar and dar[0]:
aspect_ratio = [int(float(plane)) for plane in str(dar[0]).split(":")] aspect_ratio = [int(float(plane)) for plane in str(dar[0]).split(":")]
if len(aspect_ratio) == 1: if len(aspect_ratio) == 1:
aspect_ratio.append(1) aspect_ratio.append(1)
if aspect_ratio[0] / aspect_ratio[1] not in (16 / 9, 4 / 3): ratio = aspect_ratio[0] / aspect_ratio[1]
resolution = int(track.width * (9 / 16)) if ratio not in (16 / 9, 4 / 3, 9 / 16, 3 / 4):
resolution = int(max(width, track.height) * (9 / 16))
except Exception: except Exception:
pass pass
scan_suffix = "p" scan_suffix = "i" if str(getattr(track, "scan_type", "")).lower() == "interlaced" else "p"
scan_type = getattr(track, "scan_type", None)
if scan_type and str(scan_type).lower() == "interlaced":
scan_suffix = "i"
return f"{resolution}{scan_suffix}" 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)
@@ -142,7 +141,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()
@@ -153,7 +152,7 @@ class Episode(Title):
year=f" {self.year}" if self.year and config.series_year else "", year=f" {self.year}" if self.year and config.series_year else "",
season=self.season, season=self.season,
number=self.number, number=self.number,
name=self.name or "", name=self.name if self.name and config.insert_episodename_into_filenames else "",
).strip() ).strip()
if getattr(config, "repack", False): if getattr(config, "repack", False):
@@ -287,4 +286,4 @@ class Series(SortedKeyList, ABC):
return tree return tree
__all__ = ("Episode", "Series") __all__ = ("Episode", "Series")

View File

@@ -70,22 +70,21 @@ class Movie(Title):
def _get_resolution_token(track: Any) -> str: def _get_resolution_token(track: Any) -> str:
if not track or not getattr(track, "height", None): if not track or not getattr(track, "height", None):
return "" return ""
resolution = track.height width = getattr(track, "width", track.height)
resolution = min(width, track.height)
try: try:
dar = getattr(track, "other_display_aspect_ratio", None) or [] dar = getattr(track, "other_display_aspect_ratio", None) or []
if dar and dar[0]: if dar and dar[0]:
aspect_ratio = [int(float(plane)) for plane in str(dar[0]).split(":")] aspect_ratio = [int(float(plane)) for plane in str(dar[0]).split(":")]
if len(aspect_ratio) == 1: if len(aspect_ratio) == 1:
aspect_ratio.append(1) aspect_ratio.append(1)
if aspect_ratio[0] / aspect_ratio[1] not in (16 / 9, 4 / 3): ratio = aspect_ratio[0] / aspect_ratio[1]
resolution = int(track.width * (9 / 16)) if ratio not in (16 / 9, 4 / 3, 9 / 16, 3 / 4):
resolution = int(max(width, track.height) * (9 / 16))
except Exception: except Exception:
pass pass
scan_suffix = "p" scan_suffix = "i" if str(getattr(track, "scan_type", "")).lower() == "interlaced" else "p"
scan_type = getattr(track, "scan_type", None)
if scan_type and str(scan_type).lower() == "interlaced":
scan_suffix = "i"
return f"{resolution}{scan_suffix}" return f"{resolution}{scan_suffix}"
# Name (Year) # Name (Year)

View File

@@ -39,6 +39,10 @@ title_cache_enabled: true # Enable/disable title caching globally (default: true
title_cache_time: 1800 # Cache duration in seconds (default: 1800 = 30 minutes) title_cache_time: 1800 # Cache duration in seconds (default: 1800 = 30 minutes)
title_cache_max_retention: 86400 # Maximum cache retention for fallback when API fails (default: 86400 = 24 hours) title_cache_max_retention: 86400 # Maximum cache retention for fallback when API fails (default: 86400 = 24 hours)
# Filename Configuration
unicode_filenames: false # optionally replace non-ASCII characters with ASCII equivalents
insert_episodename_into_filenames: true # optionally determines whether the specific name of an episode is automatically included within the filename for series content.
# Debug logging configuration # Debug logging configuration
# Comprehensive JSON-based debug logging for troubleshooting and service development # Comprehensive JSON-based debug logging for troubleshooting and service development
debug: debug: