88 lines
2.9 KiB
Python
88 lines
2.9 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
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.attachment_format import AttachmentFormat # noqa: E402
|
|
from ffx.media_descriptor import MediaDescriptor # noqa: E402
|
|
from ffx.track_codec import TrackCodec # noqa: E402
|
|
from ffx.track_descriptor import TrackDescriptor # noqa: E402
|
|
from ffx.track_type import TrackType # noqa: E402
|
|
|
|
|
|
ASSETS_ROOT = Path(__file__).resolve().parents[1] / "assets"
|
|
|
|
|
|
class TrackDescriptorProbeTests(unittest.TestCase):
|
|
def test_attachment_without_codec_name_uses_font_metadata_to_identify_ttf(self):
|
|
descriptor = TrackDescriptor.fromFfprobe(
|
|
{
|
|
"index": 4,
|
|
"codec_type": "attachment",
|
|
"disposition": {"default": 0},
|
|
"tags": {
|
|
"filename": "AmazonEmberTanuki-Italic.ttf",
|
|
"mimetype": "font/ttf",
|
|
},
|
|
},
|
|
subIndex=0,
|
|
)
|
|
|
|
self.assertIsNotNone(descriptor)
|
|
self.assertEqual(TrackType.ATTACHMENT, descriptor.getType())
|
|
self.assertEqual(AttachmentFormat.TTF, descriptor.getAttachmentFormat())
|
|
self.assertEqual(AttachmentFormat.TTF, descriptor.getFormatDescriptor())
|
|
self.assertEqual(TrackCodec.UNKNOWN, descriptor.getCodec())
|
|
|
|
def test_attachment_without_codec_name_still_probes_as_unknown_when_not_font(self):
|
|
descriptor = TrackDescriptor.fromFfprobe(
|
|
{
|
|
"index": 9,
|
|
"codec_type": "attachment",
|
|
"disposition": {"default": 0},
|
|
"tags": {
|
|
"filename": "cover.bin",
|
|
"mimetype": "application/octet-stream",
|
|
},
|
|
},
|
|
subIndex=0,
|
|
)
|
|
|
|
self.assertIsNotNone(descriptor)
|
|
self.assertEqual(TrackType.ATTACHMENT, descriptor.getType())
|
|
self.assertEqual(AttachmentFormat.UNKNOWN, descriptor.getAttachmentFormat())
|
|
self.assertEqual(TrackCodec.UNKNOWN, descriptor.getCodec())
|
|
|
|
def test_media_descriptor_from_boruto_probe_json_handles_attachment_streams_without_codec_name(self):
|
|
probe_payload = json.loads(
|
|
(ASSETS_ROOT / "ffprobe.out.json").read_text(encoding="utf-8")
|
|
)
|
|
|
|
descriptor = MediaDescriptor.fromFfprobe(
|
|
{"logger": None},
|
|
probe_payload["format"],
|
|
probe_payload["streams"],
|
|
)
|
|
|
|
track_descriptors = descriptor.getTrackDescriptors()
|
|
attachment_tracks = descriptor.getAttachmentTracks()
|
|
|
|
self.assertEqual(14, len(track_descriptors))
|
|
self.assertEqual(10, len(attachment_tracks))
|
|
self.assertTrue(
|
|
all(track.getAttachmentFormat() == AttachmentFormat.TTF for track in attachment_tracks)
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|