mirror of
https://github.com/shadoll/moma.git
synced 2026-08-28 19:43:28 +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:
@@ -1,6 +1,6 @@
|
||||
from pathlib import Path
|
||||
from ..constants import VIDEO_EXT_DESCRIPTIONS
|
||||
from ..utils import detect_file_type
|
||||
from ..constants import MEDIA_TYPES
|
||||
from .color_formatter import ColorFormatter
|
||||
|
||||
|
||||
class ExtensionFormatter:
|
||||
@@ -9,21 +9,7 @@ class ExtensionFormatter:
|
||||
@staticmethod
|
||||
def check_extension_match(ext_name: str, meta_type: str) -> bool:
|
||||
"""Check if file extension matches detected type"""
|
||||
if ext_name.upper() == meta_type:
|
||||
return True
|
||||
elif ext_name == 'mkv' and meta_type == 'Matroska':
|
||||
return True
|
||||
elif ext_name == 'avi' and meta_type == 'AVI':
|
||||
return True
|
||||
elif ext_name == 'mov' and meta_type == 'QuickTime':
|
||||
return True
|
||||
elif ext_name == 'wmv' and meta_type == 'ASF':
|
||||
return True
|
||||
elif ext_name == 'flv' and meta_type == 'FLV':
|
||||
return True
|
||||
elif ext_name == 'webm' and meta_type == 'WebM':
|
||||
return True
|
||||
elif ext_name == 'ogv' and meta_type == 'Ogg':
|
||||
if ext_name in MEDIA_TYPES and MEDIA_TYPES[ext_name]['meta_type'] == meta_type:
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -31,8 +17,8 @@ class ExtensionFormatter:
|
||||
def format_extension_info(ext_name: str, ext_desc: str, meta_type: str, meta_desc: str, match: bool) -> str:
|
||||
"""Format extension information with match status"""
|
||||
if match:
|
||||
return f"[bold green]Extension:[/bold green] {ext_name} - [grey]{ext_desc}[/grey]"
|
||||
return f"{ColorFormatter.bold_green('Extension:')} {ext_name} - {ColorFormatter.grey(ext_desc)}"
|
||||
else:
|
||||
return (f"[bold yellow]Extension:[/bold yellow] {ext_name} - [grey]{ext_desc}[/grey]\n"
|
||||
f"[bold red]Meta extension:[/bold red] {meta_type} - [grey]{meta_desc}[/grey]\n"
|
||||
"[bold red]Warning: Extensions do not match![/bold red]")
|
||||
return (f"{ColorFormatter.bold_yellow('Extension:')} {ext_name} - {ColorFormatter.grey(ext_desc)}\n"
|
||||
f"{ColorFormatter.bold_red('Meta extension:')} {meta_type} - {ColorFormatter.grey(meta_desc)}\n"
|
||||
f"{ColorFormatter.bold_red('Warning: Extensions do not match!')}")
|
||||
Reference in New Issue
Block a user