feat: Enhance frame class extraction logic to include width matching and update test assertions

This commit is contained in:
sHa
2025-12-27 05:49:56 +00:00
parent 8ceea5bce3
commit 229478ce64
5 changed files with 40 additions and 25 deletions

BIN
dist/renamer-0.2.12-py3-none-any.whl vendored Normal file

Binary file not shown.

View File

@@ -1,6 +1,6 @@
[project] [project]
name = "renamer" name = "renamer"
version = "0.2.11" version = "0.2.12"
description = "Terminal-based media file renamer and metadata viewer" description = "Terminal-based media file renamer and metadata viewer"
readme = "README.md" readme = "README.md"
requires-python = ">=3.11" requires-python = ">=3.11"

View File

@@ -58,28 +58,43 @@ class MediaInfoExtractor:
if not self.video_tracks: if not self.video_tracks:
return None return None
height = getattr(self.video_tracks[0], 'height', None) height = getattr(self.video_tracks[0], 'height', None)
if height: width = getattr(self.video_tracks[0], 'width', None)
# Check if interlaced if not height or not width:
interlaced = getattr(self.video_tracks[0], 'interlaced', None) return None
scan_type = 'i' if interlaced == 'Yes' else 'p'
# Check if interlaced
# First try exact match interlaced = getattr(self.video_tracks[0], 'interlaced', None)
frame_class = f"{height}{scan_type}" scan_type = 'i' if interlaced == 'Yes' else 'p'
if frame_class in FRAME_CLASSES:
return frame_class # First, try to match width to typical widths
matching_classes = []
# Find closest height with same scan type for frame_class, info in FRAME_CLASSES.items():
closest_height = None if width in info['typical_widths'] and frame_class.endswith(scan_type):
min_diff = float('inf') matching_classes.append((frame_class, info))
for fc, info in FRAME_CLASSES.items():
if fc.endswith(scan_type): if matching_classes:
diff = abs(height - info['nominal_height']) # If multiple matches, choose the one with closest height
if diff < min_diff: closest = min(matching_classes, key=lambda x: abs(height - x[1]['nominal_height']))
min_diff = diff return closest[0]
closest_height = info['nominal_height']
# If no width match, fall back to height-based matching
if closest_height and min_diff <= 100: # First try exact match
return f"{closest_height}{scan_type}" frame_class = f"{height}{scan_type}"
if frame_class in FRAME_CLASSES:
return frame_class
# Find closest height with same scan type
closest_height = None
min_diff = float('inf')
for fc, info in FRAME_CLASSES.items():
if fc.endswith(scan_type):
diff = abs(height - info['nominal_height'])
if diff < min_diff:
min_diff = diff
closest_height = info['nominal_height']
if closest_height and min_diff <= 100:
return f"{closest_height}{scan_type}"
return None return None
def extract_resolution(self) -> tuple[int, int] | None: def extract_resolution(self) -> tuple[int, int] | None:

View File

@@ -29,4 +29,4 @@ class TestMediaInfoExtractor:
"""Test extracting audio languages""" """Test extracting audio languages"""
langs = extractor.extract_audio_langs() langs = extractor.extract_audio_langs()
# Text files don't have audio tracks # Text files don't have audio tracks
assert langs == '' assert langs is None

2
uv.lock generated
View File

@@ -164,7 +164,7 @@ wheels = [
[[package]] [[package]]
name = "renamer" name = "renamer"
version = "0.2.11" version = "0.2.12"
source = { editable = "." } source = { editable = "." }
dependencies = [ dependencies = [
{ name = "langcodes" }, { name = "langcodes" },