|
| 1 | +"""Tests that get_full_metadata raw_metadata includes tags per format. |
| 2 | +
|
| 3 | +ID3v2 and Vorbis expose all frames/comments (including custom/unsupported). |
| 4 | +ID3v1 has no extensible tags. RIFF INFO exposes all INFO chunk FourCCs (known and custom). |
| 5 | +BWF (bext) is exposed under RIFF chunk_structure. |
| 6 | +""" |
| 7 | + |
| 8 | +import pytest |
| 9 | + |
| 10 | +from audiometa import get_full_metadata |
| 11 | +from audiometa.test.helpers.id3v2.id3v2_metadata_setter import ID3v2MetadataSetter |
| 12 | +from audiometa.test.helpers.riff.riff_manual_metadata_creator import ManualRIFFMetadataCreator |
| 13 | +from audiometa.test.helpers.riff.riff_metadata_setter import RIFFMetadataSetter |
| 14 | +from audiometa.test.helpers.temp_file_with_metadata import temp_file_with_metadata |
| 15 | +from audiometa.test.helpers.vorbis.vorbis_metadata_setter import VorbisMetadataSetter |
| 16 | +from audiometa.utils.unified_metadata_key import UnifiedMetadataKey |
| 17 | + |
| 18 | + |
| 19 | +@pytest.mark.integration |
| 20 | +class TestGetFullMetadataRawMetadataIncludesUnsupportedTags: |
| 21 | + def test_id3v2_raw_metadata_includes_custom_txxx_frame(self): |
| 22 | + with temp_file_with_metadata({"title": "Track"}, "mp3") as test_file: |
| 23 | + ID3v2MetadataSetter.set_custom_txxx(test_file, "MYCUSTOMKEY", "custom value") |
| 24 | + result = get_full_metadata(test_file) |
| 25 | + frames = result.get("raw_metadata", {}).get("id3v2", {}).get("frames", {}) |
| 26 | + assert "TXXX:MYCUSTOMKEY" in frames |
| 27 | + frame_data = frames["TXXX:MYCUSTOMKEY"] |
| 28 | + assert "text" in frame_data |
| 29 | + assert "custom value" in frame_data["text"] |
| 30 | + |
| 31 | + def test_vorbis_raw_metadata_includes_custom_comment(self): |
| 32 | + with temp_file_with_metadata({"title": "Track"}, "flac") as test_file: |
| 33 | + VorbisMetadataSetter.set_tag(test_file, "MYCUSTOMKEY", "custom value") |
| 34 | + result = get_full_metadata(test_file) |
| 35 | + comments = result.get("raw_metadata", {}).get("vorbis", {}).get("comments", {}) |
| 36 | + assert "MYCUSTOMKEY" in comments |
| 37 | + assert comments["MYCUSTOMKEY"] == ["custom value"] |
| 38 | + |
| 39 | + def test_id3v1_raw_metadata_includes_parsed_fields(self): |
| 40 | + with temp_file_with_metadata( |
| 41 | + {"title": "ID3v1 Title", "artist": "ID3v1 Artist"}, |
| 42 | + "id3v1", |
| 43 | + ) as test_file: |
| 44 | + result = get_full_metadata(test_file) |
| 45 | + parsed = result.get("raw_metadata", {}).get("id3v1", {}).get("parsed_fields", {}) |
| 46 | + assert UnifiedMetadataKey.TITLE in parsed |
| 47 | + assert parsed[UnifiedMetadataKey.TITLE] == "ID3v1 Title" |
| 48 | + assert UnifiedMetadataKey.ARTISTS in parsed |
| 49 | + assert parsed[UnifiedMetadataKey.ARTISTS] == "ID3v1 Artist" |
| 50 | + |
| 51 | + def test_riff_raw_metadata_includes_known_info_tags(self): |
| 52 | + with temp_file_with_metadata( |
| 53 | + {"title": "RIFF Title", "artist": "RIFF Artist"}, |
| 54 | + "wav", |
| 55 | + ) as test_file: |
| 56 | + result = get_full_metadata(test_file) |
| 57 | + parsed = result.get("raw_metadata", {}).get("riff", {}).get("parsed_fields", {}) |
| 58 | + assert "INAM" in parsed |
| 59 | + assert parsed["INAM"] == "RIFF Title" |
| 60 | + assert "IART" in parsed |
| 61 | + assert parsed["IART"] == "RIFF Artist" |
| 62 | + |
| 63 | + def test_riff_raw_metadata_includes_custom_fourcc(self): |
| 64 | + with temp_file_with_metadata({}, "wav") as test_file: |
| 65 | + ManualRIFFMetadataCreator.add_custom_info_field(test_file, "CUST", "custom value") |
| 66 | + result = get_full_metadata(test_file) |
| 67 | + parsed = result.get("raw_metadata", {}).get("riff", {}).get("parsed_fields", {}) |
| 68 | + assert "CUST" in parsed |
| 69 | + assert parsed["CUST"] == "custom value" |
| 70 | + |
| 71 | + def test_riff_raw_metadata_includes_bext_in_chunk_structure(self): |
| 72 | + with temp_file_with_metadata({}, "wav") as test_file: |
| 73 | + RIFFMetadataSetter.set_bext_description(test_file, "BWF Description") |
| 74 | + RIFFMetadataSetter.set_bext_originator(test_file, "BWF Originator") |
| 75 | + result = get_full_metadata(test_file) |
| 76 | + chunk_structure = result.get("raw_metadata", {}).get("riff", {}).get("chunk_structure", {}) |
| 77 | + assert "bext" in chunk_structure |
| 78 | + bext = chunk_structure["bext"] |
| 79 | + assert bext["Description"] == "BWF Description" |
| 80 | + assert bext["Originator"] == "BWF Originator" |
0 commit comments