diff --git a/dist/renamer-0.2.12-py3-none-any.whl b/dist/renamer-0.2.12-py3-none-any.whl new file mode 100644 index 0000000..9345427 Binary files /dev/null and b/dist/renamer-0.2.12-py3-none-any.whl differ diff --git a/pyproject.toml b/pyproject.toml index 5536cda..2265cd1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "renamer" -version = "0.2.11" +version = "0.2.12" description = "Terminal-based media file renamer and metadata viewer" readme = "README.md" requires-python = ">=3.11" diff --git a/renamer/extractors/mediainfo_extractor.py b/renamer/extractors/mediainfo_extractor.py index fdd062b..0266d6f 100644 --- a/renamer/extractors/mediainfo_extractor.py +++ b/renamer/extractors/mediainfo_extractor.py @@ -58,28 +58,43 @@ class MediaInfoExtractor: if not self.video_tracks: return None height = getattr(self.video_tracks[0], 'height', None) - if height: - # Check if interlaced - interlaced = getattr(self.video_tracks[0], 'interlaced', None) - scan_type = 'i' if interlaced == 'Yes' else 'p' - - # First try exact match - 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}" + width = getattr(self.video_tracks[0], 'width', None) + if not height or not width: + return None + + # Check if interlaced + interlaced = getattr(self.video_tracks[0], 'interlaced', None) + scan_type = 'i' if interlaced == 'Yes' else 'p' + + # First, try to match width to typical widths + matching_classes = [] + for frame_class, info in FRAME_CLASSES.items(): + if width in info['typical_widths'] and frame_class.endswith(scan_type): + matching_classes.append((frame_class, info)) + + if matching_classes: + # If multiple matches, choose the one with closest height + closest = min(matching_classes, key=lambda x: abs(height - x[1]['nominal_height'])) + return closest[0] + + # If no width match, fall back to height-based matching + # First try exact match + 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 def extract_resolution(self) -> tuple[int, int] | None: diff --git a/renamer/test/test_mediainfo_extractor.py b/renamer/test/test_mediainfo_extractor.py index 57aa6e3..a1de9d1 100644 --- a/renamer/test/test_mediainfo_extractor.py +++ b/renamer/test/test_mediainfo_extractor.py @@ -29,4 +29,4 @@ class TestMediaInfoExtractor: """Test extracting audio languages""" langs = extractor.extract_audio_langs() # Text files don't have audio tracks - assert langs == '' \ No newline at end of file + assert langs is None \ No newline at end of file diff --git a/uv.lock b/uv.lock index e2a09d0..a0c92fa 100644 --- a/uv.lock +++ b/uv.lock @@ -164,7 +164,7 @@ wheels = [ [[package]] name = "renamer" -version = "0.2.11" +version = "0.2.12" source = { editable = "." } dependencies = [ { name = "langcodes" },