mirror of
https://github.com/shadoll/moma.git
synced 2026-08-28 19:43:28 +00:00
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:
@@ -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})"
|
||||
Reference in New Issue
Block a user