fix: Remove unused resolution frame class method from formatter order

This commit is contained in:
sHa
2025-12-29 20:10:34 +00:00
parent 50de7e1d4a
commit e0637e9981
6 changed files with 11 additions and 64 deletions

BIN
dist/renamer-0.5.2-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.5.1" version = "0.5.2"
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

@@ -71,43 +71,26 @@ 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)
width = getattr(self.video_tracks[0], 'width', None) if not height:
if not height or not width:
return None return None
# Check if interlaced # Check if interlaced
interlaced = getattr(self.video_tracks[0], 'interlaced', None) interlaced = getattr(self.video_tracks[0], 'interlaced', None)
scan_type = 'i' if interlaced == 'Yes' else 'p' scan_type = 'i' if interlaced == 'Yes' else 'p'
# First, try to match width to typical widths # Find the closest frame class based on height
matching_classes = [] closest_class = None
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') min_diff = float('inf')
for fc, info in FRAME_CLASSES.items(): for frame_class, info in FRAME_CLASSES.items():
if fc.endswith(scan_type): if frame_class.endswith(scan_type):
diff = abs(height - info['nominal_height']) diff = abs(height - info['nominal_height'])
if diff < min_diff: if diff < min_diff:
min_diff = diff min_diff = diff
closest_height = info['nominal_height'] closest_class = frame_class
if closest_height and min_diff <= 100: # Return the closest match if within reasonable distance
return f"{closest_height}{scan_type}" if closest_class and min_diff <= 100:
return closest_class
return None return None
@cached_method() @cached_method()

View File

@@ -34,7 +34,6 @@ class FormatterApplier:
DateFormatter.format_modification_date, DateFormatter.format_modification_date,
DateFormatter.format_year, DateFormatter.format_year,
ExtensionFormatter.format_extension_info, ExtensionFormatter.format_extension_info,
ResolutionFormatter.get_frame_class_from_resolution,
ResolutionFormatter.format_resolution_dimensions, ResolutionFormatter.format_resolution_dimensions,
TrackFormatter.format_video_track, TrackFormatter.format_video_track,
TrackFormatter.format_audio_track, TrackFormatter.format_audio_track,

View File

@@ -1,41 +1,6 @@
from renamer.constants import FRAME_CLASSES
class ResolutionFormatter: class ResolutionFormatter:
"""Class for formatting video resolutions and frame classes""" """Class for formatting video resolutions and frame classes"""
@staticmethod
def get_frame_class_from_resolution(resolution: str) -> str:
"""Convert resolution string (WIDTHxHEIGHT) to frame class (480p, 720p, etc.)"""
if not resolution:
return 'Unclassified'
try:
# Extract height from WIDTHxHEIGHT format
if 'x' in resolution:
height = int(resolution.split('x')[1])
else:
# Try to extract number directly
import re
match = re.search(r'(\d{3,4})', resolution)
if match:
height = int(match.group(1))
else:
return 'Unclassified'
# Find the closest frame class based on nominal height
closest_class = 'Unclassified'
min_diff = float('inf')
for frame_class, info in FRAME_CLASSES.items():
nominal_height = info['nominal_height']
diff = abs(height - nominal_height)
if diff < min_diff:
min_diff = diff
closest_class = frame_class
return closest_class
except (ValueError, IndexError):
return 'Unclassified'
@staticmethod @staticmethod
def format_resolution_dimensions(resolution: tuple[int, int]) -> str: def format_resolution_dimensions(resolution: tuple[int, int]) -> str:
"""Format resolution as WIDTHxHEIGHT""" """Format resolution as WIDTHxHEIGHT"""

2
uv.lock generated
View File

@@ -342,7 +342,7 @@ wheels = [
[[package]] [[package]]
name = "renamer" name = "renamer"
version = "0.5.1" version = "0.5.2"
source = { editable = "." } source = { editable = "." }
dependencies = [ dependencies = [
{ name = "langcodes" }, { name = "langcodes" },