mirror of
https://github.com/shadoll/moma.git
synced 2026-08-28 11:33:25 +00:00
- Updated `pyproject.toml` to reflect new package structure. - Created `renamer/__init__.py` to initialize the package. - Implemented `RenamerApp` in `renamer/app.py` for the main application interface. - Added constants for video extensions in `renamer/constants.py`. - Developed `MediaExtractor` class in `renamer/extractor.py` for extracting metadata from media files. - Created various extractor classes in `renamer/extractors/` for handling filename, metadata, and media info extraction. - Added formatting classes in `renamer/formatters/` for displaying media information and proposed filenames. - Implemented utility functions in `renamer/utils.py` for detecting file types and extracting media track information. - Introduced `OpenScreen` in `renamer/screens.py` for user input of directory paths. - Enhanced error handling and user feedback throughout the application.
61 lines
2.4 KiB
Python
61 lines
2.4 KiB
Python
from pathlib import Path
|
|
from .extractors.filename_extractor import FilenameExtractor
|
|
from .extractors.metadata_extractor import MetadataExtractor
|
|
from .extractors.mediainfo_extractor import MediaInfoExtractor
|
|
|
|
|
|
class MediaExtractor:
|
|
"""Class to extract various metadata from media files using specialized extractors"""
|
|
|
|
def __init__(self):
|
|
self.mediainfo_extractor = MediaInfoExtractor()
|
|
|
|
def extract_title(self, file_path: Path) -> str | None:
|
|
"""Extract movie title from metadata or filename"""
|
|
# Try metadata first
|
|
title = MetadataExtractor.extract_title(file_path)
|
|
if title:
|
|
return title
|
|
# Fallback to filename
|
|
return FilenameExtractor.extract_title(file_path)
|
|
|
|
def extract_year(self, file_path: Path) -> str | None:
|
|
"""Extract year from filename"""
|
|
return FilenameExtractor.extract_year(file_path)
|
|
|
|
def extract_source(self, file_path: Path) -> str | None:
|
|
"""Extract video source from filename"""
|
|
return FilenameExtractor.extract_source(file_path)
|
|
|
|
def extract_resolution(self, file_path: Path) -> str | None:
|
|
"""Extract resolution from media info or filename"""
|
|
# Try media info first
|
|
resolution = self.mediainfo_extractor.extract_resolution(file_path)
|
|
if resolution:
|
|
return resolution
|
|
# Fallback to filename
|
|
return FilenameExtractor.extract_resolution(file_path)
|
|
|
|
def extract_hdr(self, file_path: Path) -> str | None:
|
|
"""Extract HDR info from media info"""
|
|
return self.mediainfo_extractor.extract_hdr(file_path)
|
|
|
|
def extract_audio_langs(self, file_path: Path) -> str:
|
|
"""Extract audio languages from media info"""
|
|
return self.mediainfo_extractor.extract_audio_langs(file_path)
|
|
|
|
def extract_metadata(self, file_path: Path) -> dict:
|
|
"""Extract general metadata"""
|
|
return MetadataExtractor.extract_all_metadata(file_path)
|
|
|
|
def extract_all(self, file_path: Path) -> dict:
|
|
"""Extract all rename-related data"""
|
|
return {
|
|
'title': self.extract_title(file_path),
|
|
'year': self.extract_year(file_path),
|
|
'source': self.extract_source(file_path),
|
|
'resolution': self.extract_resolution(file_path),
|
|
'hdr': self.extract_hdr(file_path),
|
|
'audio_langs': self.extract_audio_langs(file_path),
|
|
'metadata': self.extract_metadata(file_path)
|
|
} |