diff --git a/src/ffx/track_codec.py b/src/ffx/track_codec.py index f560715..d6ec091 100644 --- a/src/ffx/track_codec.py +++ b/src/ffx/track_codec.py @@ -3,17 +3,20 @@ from enum import Enum class TrackCodec(Enum): + VP9 = {'identifier': 'vp9', 'format': 'ivf', 'extension': 'ivf' , 'label': 'VP9'} H265 = {'identifier': 'hevc', 'format': 'h265', 'extension': 'h265' ,'label': 'H.265'} H264 = {'identifier': 'h264', 'format': 'h264', 'extension': 'h264' ,'label': 'H.264'} MPEG4 = {'identifier': 'mpeg4', 'format': 'm4v', 'extension': 'm4v' ,'label': 'MPEG-4'} MPEG2 = {'identifier': 'mpeg2video', 'format': 'mpeg2video', 'extension': 'mpg' ,'label': 'MPEG-2'} + OPUS = {'identifier': 'opus', 'format': 'opus', 'extension': 'opus' , 'label': 'Opus'} AAC = {'identifier': 'aac', 'format': None, 'extension': 'aac' , 'label': 'AAC'} AC3 = {'identifier': 'ac3', 'format': 'ac3', 'extension': 'ac3' , 'label': 'AC3'} EAC3 = {'identifier': 'eac3', 'format': 'eac3', 'extension': 'eac3' , 'label': 'EAC3'} DTS = {'identifier': 'dts', 'format': 'dts', 'extension': 'dts' , 'label': 'DTS'} MP3 = {'identifier': 'mp3', 'format': 'mp3', 'extension': 'mp3' , 'label': 'MP3'} + WEBVTT = {'identifier': 'webvtt', 'format': 'webvtt', 'extension': 'vtt' , 'label': 'WebVTT'} SRT = {'identifier': 'subrip', 'format': 'srt', 'extension': 'srt' , 'label': 'SRT'} ASS = {'identifier': 'ass', 'format': 'ass', 'extension': 'ass' , 'label': 'ASS'} TTF = {'identifier': 'ttf', 'format': None, 'extension': 'ttf' , 'label': 'TTF'} diff --git a/tests/unit/test_file_properties_asset_probe.py b/tests/unit/test_file_properties_asset_probe.py new file mode 100644 index 0000000..367d26d --- /dev/null +++ b/tests/unit/test_file_properties_asset_probe.py @@ -0,0 +1,64 @@ +from __future__ import annotations + +from pathlib import Path +import sys +import unittest + + +SRC_ROOT = Path(__file__).resolve().parents[2] / "src" + +if str(SRC_ROOT) not in sys.path: + sys.path.insert(0, str(SRC_ROOT)) + + +from ffx.file_properties import FileProperties # noqa: E402 +from ffx.i18n import set_current_language # noqa: E402 +from ffx.logging_utils import get_ffx_logger # noqa: E402 +from ffx.track_codec import TrackCodec # noqa: E402 +from ffx.track_type import TrackType # noqa: E402 + + +class StaticConfig: + def __init__(self, data: dict): + self._data = data + + def getData(self): + return self._data + + +class FilePropertiesAssetProbeTests(unittest.TestCase): + def tearDown(self): + set_current_language("de") + + def test_boruto_webm_probe_recognizes_webm_stream_codecs(self): + context = { + "logger": get_ffx_logger(), + "config": StaticConfig({}), + "language": "de", + "use_pattern": False, + } + set_current_language("de") + + media_path = ( + Path(__file__).resolve().parents[1] + / "assets" + / "Boruto; Naruto Next Generations (2017) - 0069 Super-Chochos Liebestaumel - S01E0069.webm" + ) + + file_properties = FileProperties(context, str(media_path)) + tracks = file_properties.getMediaDescriptor().getTrackDescriptors() + + subtitle_codecs = [ + track.getCodec() + for track in tracks + if track.getType() == TrackType.SUBTITLE + ] + + self.assertIn(TrackCodec.VP9, [track.getCodec() for track in tracks]) + self.assertIn(TrackCodec.OPUS, [track.getCodec() for track in tracks]) + self.assertTrue(subtitle_codecs) + self.assertTrue(all(codec == TrackCodec.WEBVTT for codec in subtitle_codecs)) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/unit/test_track_codec_identification.py b/tests/unit/test_track_codec_identification.py new file mode 100644 index 0000000..509172e --- /dev/null +++ b/tests/unit/test_track_codec_identification.py @@ -0,0 +1,25 @@ +from __future__ import annotations + +from pathlib import Path +import sys +import unittest + + +SRC_ROOT = Path(__file__).resolve().parents[2] / "src" + +if str(SRC_ROOT) not in sys.path: + sys.path.insert(0, str(SRC_ROOT)) + + +from ffx.track_codec import TrackCodec # noqa: E402 + + +class TrackCodecIdentificationTests(unittest.TestCase): + def test_identify_modern_webm_codecs(self): + self.assertEqual(TrackCodec.VP9, TrackCodec.identify("vp9")) + self.assertEqual(TrackCodec.OPUS, TrackCodec.identify("opus")) + self.assertEqual(TrackCodec.WEBVTT, TrackCodec.identify("webvtt")) + + +if __name__ == "__main__": + unittest.main()