mirror of
https://github.com/shadoll/moma.git
synced 2026-08-28 11:33:25 +00:00
feat: Introduce DefaultExtractor for fallback values and refactor extraction logic in MediaExtractor
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
class DefaultExtractor:
|
||||
"""Extractor that provides default fallback values"""
|
||||
|
||||
def extract_title(self):
|
||||
return "Unknown Title"
|
||||
|
||||
def extract_year(self):
|
||||
return None
|
||||
|
||||
def extract_source(self):
|
||||
return None
|
||||
|
||||
def extract_resolution(self):
|
||||
return None
|
||||
|
||||
def extract_hdr(self):
|
||||
return None
|
||||
|
||||
def extract_movie_db(self):
|
||||
return None
|
||||
|
||||
def extract_audio_langs(self):
|
||||
return None
|
||||
|
||||
def extract_meta_type(self):
|
||||
return None
|
||||
|
||||
def extract_size(self):
|
||||
return None
|
||||
|
||||
def extract_modification_time(self):
|
||||
return None
|
||||
|
||||
def extract_file_name(self):
|
||||
return None
|
||||
|
||||
def extract_file_path(self):
|
||||
return None
|
||||
|
||||
def extract_frame_class(self):
|
||||
return None
|
||||
|
||||
def extract_video_tracks(self):
|
||||
return []
|
||||
|
||||
def extract_audio_tracks(self):
|
||||
return []
|
||||
|
||||
def extract_subtitle_tracks(self):
|
||||
return []
|
||||
@@ -12,12 +12,12 @@ class FilenameExtractor:
|
||||
self.file_path = file_path
|
||||
self.file_name = file_path.name
|
||||
|
||||
def _get_frame_class_from_height(self, height: int) -> str:
|
||||
def _get_frame_class_from_height(self, height: int) -> str | None:
|
||||
"""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'
|
||||
return None
|
||||
|
||||
def extract_title(self) -> str | None:
|
||||
"""Extract movie title from filename"""
|
||||
@@ -126,9 +126,9 @@ class FilenameExtractor:
|
||||
unclassified_indicators = ['SD', 'LQ', 'HD', 'QHD']
|
||||
for indicator in unclassified_indicators:
|
||||
if re.search(r'\b' + re.escape(indicator) + r'\b', self.file_name, re.IGNORECASE):
|
||||
return 'Unclassified'
|
||||
return None
|
||||
|
||||
return 'Unclassified'
|
||||
return None
|
||||
|
||||
def extract_hdr(self) -> str | None:
|
||||
"""Extract HDR information from filename"""
|
||||
|
||||
@@ -26,7 +26,7 @@ class MediaInfoExtractor:
|
||||
for frame_class, info in FRAME_CLASSES.items():
|
||||
if height == info['nominal_height']:
|
||||
return frame_class
|
||||
return 'Unclassified'
|
||||
return None
|
||||
|
||||
def extract_duration(self) -> float | None:
|
||||
"""Extract duration from media info in seconds"""
|
||||
@@ -39,11 +39,11 @@ class MediaInfoExtractor:
|
||||
def extract_frame_class(self) -> str | None:
|
||||
"""Extract frame class from media info (480p, 720p, 1080p, etc.)"""
|
||||
if not self.video_tracks:
|
||||
return 'Unclassified'
|
||||
return None
|
||||
height = getattr(self.video_tracks[0], 'height', None)
|
||||
if height:
|
||||
return self._get_frame_class_from_height(height)
|
||||
return 'Unclassified'
|
||||
return None
|
||||
|
||||
def extract_resolution(self) -> tuple[int, int] | None:
|
||||
"""Extract actual video resolution as (width, height) tuple from media info"""
|
||||
|
||||
Reference in New Issue
Block a user