mirror of
https://github.com/shadoll/moma.git
synced 2026-08-28 03:27:34 +00:00
Refactor extractors and formatters for improved structure and functionality
- Converted static methods to instance methods in FileInfoExtractor and FilenameExtractor for better encapsulation. - Enhanced MediaInfoExtractor to initialize with file path and extract media information upon instantiation. - Updated MetadataExtractor to handle metadata extraction with improved error handling and added methods for meta type detection. - Introduced ColorFormatter for consistent text formatting across the application. - Refactored MediaFormatter to utilize the new extractor structure and improve output formatting. - Removed redundant utility functions and replaced them with direct calls in extractors. - Added ProposedNameFormatter for better handling of proposed filename formatting. - Updated extension handling to use MEDIA_TYPES for descriptions instead of VIDEO_EXT_DESCRIPTIONS.
This commit is contained in:
@@ -6,40 +6,37 @@ from ..constants import SOURCE_DICT, FRAME_CLASSES
|
||||
class FilenameExtractor:
|
||||
"""Class to extract information from filename"""
|
||||
|
||||
@staticmethod
|
||||
def _get_frame_class_from_height(height: int) -> str:
|
||||
def __init__(self, file_path: Path):
|
||||
self.file_path = file_path
|
||||
self.file_name = file_path.name
|
||||
|
||||
def _get_frame_class_from_height(self, height: int) -> str:
|
||||
"""Get frame class from video height using FRAME_CLASSES constant"""
|
||||
for frame_class, info in FRAME_CLASSES.items():
|
||||
if height == info['nominal_height']:
|
||||
return frame_class
|
||||
return 'Unclassified'
|
||||
|
||||
@staticmethod
|
||||
def extract_title(file_path: Path) -> str | None:
|
||||
def extract_title(self) -> str | None:
|
||||
"""Extract movie title from filename"""
|
||||
file_name = file_path.name
|
||||
temp_name = re.sub(r'\s*\(\d{4}\)\s*|\s*\d{4}\s*|\.\d{4}\.', '', file_name)
|
||||
temp_name = re.sub(r'\s*\(\d{4}\)\s*|\s*\d{4}\s*|\.\d{4}\.', '', self.file_name)
|
||||
|
||||
# Find and remove source
|
||||
source = FilenameExtractor.extract_source(file_path)
|
||||
source = self.extract_source()
|
||||
if source:
|
||||
for alias in SOURCE_DICT[source]:
|
||||
temp_name = re.sub(r'\b' + re.escape(alias) + r'\b', '', temp_name, flags=re.IGNORECASE)
|
||||
|
||||
return temp_name.rsplit('.', 1)[0].strip()
|
||||
|
||||
@staticmethod
|
||||
def extract_year(file_path: Path) -> str | None:
|
||||
def extract_year(self) -> str | None:
|
||||
"""Extract year from filename"""
|
||||
file_name = file_path.name
|
||||
year_match = re.search(r'\((\d{4})\)|(\d{4})', file_name)
|
||||
year_match = re.search(r'\((\d{4})\)|(\d{4})', self.file_name)
|
||||
return (year_match.group(1) or year_match.group(2)) if year_match else None
|
||||
|
||||
@staticmethod
|
||||
def extract_source(file_path: Path) -> str | None:
|
||||
def extract_source(self) -> str | None:
|
||||
"""Extract video source from filename"""
|
||||
file_name = file_path.name
|
||||
temp_name = re.sub(r'\s*\(\d{4}\)\s*|\s*\d{4}\s*|\.\d{4}\.', '', file_name)
|
||||
temp_name = re.sub(r'\s*\(\d{4}\)\s*|\s*\d{4}\s*|\.\d{4}\.', '', self.file_name)
|
||||
|
||||
for src, aliases in SOURCE_DICT.items():
|
||||
for alias in aliases:
|
||||
@@ -47,12 +44,10 @@ class FilenameExtractor:
|
||||
return src
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def extract_frame_class(file_path: Path) -> str | None:
|
||||
def extract_frame_class(self) -> str | None:
|
||||
"""Extract frame class from filename (480p, 720p, 1080p, 2160p, etc.)"""
|
||||
file_name = file_path.name
|
||||
match = re.search(r'(\d{3,4})[pi]', file_name, re.IGNORECASE)
|
||||
match = re.search(r'(\d{3,4})[pi]', self.file_name, re.IGNORECASE)
|
||||
if match:
|
||||
height = int(match.group(1))
|
||||
return FilenameExtractor._get_frame_class_from_height(height)
|
||||
return self._get_frame_class_from_height(height)
|
||||
return 'Unclassified'
|
||||
Reference in New Issue
Block a user