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
+44
View File
@@ -0,0 +1,44 @@
class TrackFormatter:
"""Class to format track information into display strings"""
@staticmethod
def format_video_track(track: dict) -> str:
"""Format a video track dict into a display string"""
codec = track.get('codec', 'unknown')
width = track.get('width', '?')
height = track.get('height', '?')
bitrate = track.get('bitrate')
fps = track.get('fps')
profile = track.get('profile')
video_str = f"{codec} {width}x{height}"
if bitrate:
video_str += f" {bitrate}bps"
if fps:
video_str += f" {fps}fps"
if profile:
video_str += f" ({profile})"
return video_str
@staticmethod
def format_audio_track(track: dict) -> str:
"""Format an audio track dict into a display string"""
codec = track.get('codec', 'unknown')
channels = track.get('channels', '?')
lang = track.get('language', 'und')
bitrate = track.get('bitrate')
audio_str = f"{codec} {channels}ch {lang}"
if bitrate:
audio_str += f" {bitrate}bps"
return audio_str
@staticmethod
def format_subtitle_track(track: dict) -> str:
"""Format a subtitle track dict into a display string"""
lang = track.get('language', 'und')
format = track.get('format', 'unknown')
return f"{lang} ({format})"