feat: restructure renamer package and implement media extraction features

- 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.
This commit is contained in:
sha
2025-12-25 03:10:40 +00:00
parent 9e331e58ce
commit 305dd5f43e
21 changed files with 792 additions and 329 deletions
+48
View File
@@ -0,0 +1,48 @@
import mutagen
from pathlib import Path
class MetadataExtractor:
"""Class to extract information from file metadata"""
@staticmethod
def extract_title(file_path: Path) -> str | None:
"""Extract title from metadata"""
try:
info = mutagen.File(file_path)
if info:
return getattr(info, 'title', None) or getattr(info, 'get', lambda x, default=None: default)('title', [None])[0]
except:
pass
return None
@staticmethod
def extract_duration(file_path: Path) -> float | None:
"""Extract duration from metadata"""
try:
info = mutagen.File(file_path)
if info:
return getattr(info, 'length', None)
except:
pass
return None
@staticmethod
def extract_artist(file_path: Path) -> str | None:
"""Extract artist from metadata"""
try:
info = mutagen.File(file_path)
if info:
return getattr(info, 'artist', None) or getattr(info, 'get', lambda x, default=None: default)('artist', [None])[0]
except:
pass
return None
@staticmethod
def extract_all_metadata(file_path: Path) -> dict:
"""Extract all metadata"""
return {
'title': MetadataExtractor.extract_title(file_path),
'duration': MetadataExtractor.extract_duration(file_path),
'artist': MetadataExtractor.extract_artist(file_path)
}