feat: Refactor formatting and extraction logic

- Added `langcodes` dependency for improved language handling.
- Replaced `ColorFormatter` with `TextFormatter` for consistent text styling across the application.
- Introduced `TrackFormatter` for better track information formatting.
- Updated `MediaFormatter` to utilize new formatting methods and improved data handling.
- Refactored `MediaExtractor` to enhance data extraction logic and improve readability.
- Removed deprecated `ColorFormatter` methods and replaced them with `TextFormatter` equivalents.
- Added new methods for extracting and formatting audio and subtitle tracks.
- Updated tests to reflect changes in the extraction logic and formatting.
This commit is contained in:
sha
2025-12-26 11:33:24 +00:00
parent d2ec235458
commit 1d6eb9593e
15 changed files with 544 additions and 285 deletions
+7 -15
View File
@@ -1,24 +1,16 @@
from pathlib import Path
from ..constants import MEDIA_TYPES
from .color_formatter import ColorFormatter
from .text_formatter import TextFormatter
class ExtensionFormatter:
"""Class for formatting extension information"""
@staticmethod
def check_extension_match(ext_name: str, meta_type: str) -> bool:
"""Check if file extension matches detected type"""
if ext_name in MEDIA_TYPES and MEDIA_TYPES[ext_name]['meta_type'] == meta_type:
return True
return False
@staticmethod
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"{ColorFormatter.bold_green('Extension:')} {ext_name} - {ColorFormatter.grey(ext_desc)}"
def format_extension_info(ext_name: str) -> str:
"""Format extension information"""
if ext_name in MEDIA_TYPES:
ext_desc = MEDIA_TYPES[ext_name]['description']
return f"{ext_name} - {TextFormatter.grey(ext_desc)}"
else:
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!')}")
return f"{ext_name} - {TextFormatter.grey('Unknown extension')}"