mirror of
https://github.com/shadoll/moma.git
synced 2026-08-28 03:27:34 +00:00
feat: Enhance metadata extraction and formatting, improve extractor architecture, and update documentation
This commit is contained in:
@@ -31,23 +31,49 @@ class FilenameExtractor:
|
||||
|
||||
def extract_year(self) -> str | None:
|
||||
"""Extract year from filename"""
|
||||
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
|
||||
# First try to find year in parentheses (most common and reliable)
|
||||
paren_match = re.search(r'\((\d{4})\)', self.file_name)
|
||||
if paren_match:
|
||||
return paren_match.group(1)
|
||||
|
||||
# Fallback: look for year in dots (like .1971.)
|
||||
dot_match = re.search(r'\.(\d{4})\.', self.file_name)
|
||||
if dot_match:
|
||||
return dot_match.group(1)
|
||||
|
||||
# Last resort: any 4-digit number (but this is less reliable)
|
||||
any_match = re.search(r'\b(\d{4})\b', self.file_name)
|
||||
if any_match:
|
||||
year = any_match.group(1)
|
||||
# Basic sanity check: years should be between 1900 and current year + a few years
|
||||
current_year = 2025 # Update this as needed
|
||||
if 1900 <= int(year) <= current_year + 10:
|
||||
return year
|
||||
|
||||
return None
|
||||
|
||||
def extract_source(self) -> str | None:
|
||||
"""Extract video source from filename"""
|
||||
temp_name = re.sub(r'\s*\(\d{4}\)\s*|\s*\d{4}\s*|\.\d{4}\.', '', self.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:
|
||||
if re.search(r'\b' + re.escape(alias) + r'\b', temp_name, re.IGNORECASE):
|
||||
if alias.upper() in temp_name.upper():
|
||||
return src
|
||||
return None
|
||||
|
||||
def extract_frame_class(self) -> str | None:
|
||||
"""Extract frame class from filename (480p, 720p, 1080p, 2160p, etc.)"""
|
||||
# First check for specific numeric resolutions
|
||||
match = re.search(r'(\d{3,4})[pi]', self.file_name, re.IGNORECASE)
|
||||
if match:
|
||||
height = int(match.group(1))
|
||||
return self._get_frame_class_from_height(height)
|
||||
|
||||
# If no specific resolution found, check for quality indicators
|
||||
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 'Unclassified'
|
||||
Reference in New Issue
Block a user