mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-19 07:25:11 +00:00
fix(tracks): match resolutions per range and codec
An exact height match in one range denied the 16:9 canvas fallback to the others, so a cropped HDR10 or SDR track was dropped whenever an uncropped DV track matched the requested height. Also sweep the hybrid L5 temp files so a killed run cannot leave a stale RPU behind.
This commit is contained in:
@@ -3473,7 +3473,16 @@ class dl:
|
||||
temp_path.unlink(missing_ok=True)
|
||||
except PermissionError:
|
||||
self.log.warning(f"Failed to delete temp file (in use?): {temp_path}")
|
||||
for leftover in ("HDR10-DV.hevc", "DV.hevc", "RPU.bin", "RPU_UNT.bin", "RPU_L6.bin"):
|
||||
for leftover in (
|
||||
"HDR10-DV.hevc",
|
||||
"HDR10.hevc",
|
||||
"DV.hevc",
|
||||
"RPU.bin",
|
||||
"RPU_UNT.bin",
|
||||
"RPU_L5.bin",
|
||||
"RPU_L6.bin",
|
||||
"L5.json",
|
||||
):
|
||||
leftover_path = config.directories.temp / leftover
|
||||
try:
|
||||
leftover_path.unlink(missing_ok=True)
|
||||
|
||||
@@ -455,19 +455,18 @@ class Tracks:
|
||||
return select
|
||||
|
||||
def by_resolutions(self, resolutions: list[int], per_resolution: int = 0) -> None:
|
||||
# Note: Do not merge these list comprehensions. They must be done separately so the results
|
||||
# from the 16:9 canvas check is only used if there's no exact height resolution match.
|
||||
selected = []
|
||||
groups: dict[tuple, list[Video]] = {}
|
||||
for video in self.videos:
|
||||
groups.setdefault((video.range, video.codec), []).append(video)
|
||||
|
||||
keep: set[int] = set()
|
||||
for resolution in resolutions:
|
||||
matches = [ # exact matches
|
||||
x for x in self.videos if x.height == resolution
|
||||
]
|
||||
if not matches:
|
||||
matches = [ # 16:9 canvas matches
|
||||
x for x in self.videos if x.width and int(x.width * (9 / 16)) == resolution
|
||||
]
|
||||
selected.extend(matches[: per_resolution or None])
|
||||
self.videos = selected
|
||||
for group in groups.values():
|
||||
matches = [x for x in group if x.height == resolution]
|
||||
if not matches:
|
||||
matches = [x for x in group if x.width and int(x.width * (9 / 16)) == resolution]
|
||||
keep.update(id(x) for x in matches[: per_resolution or None])
|
||||
self.videos = [x for x in self.videos if id(x) in keep]
|
||||
|
||||
@staticmethod
|
||||
def by_language(
|
||||
|
||||
Reference in New Issue
Block a user