diff --git a/api/funkwhale_api/music/metadata.py b/api/funkwhale_api/music/metadata.py index 801ea6a9badc141c5e06e2eb3f69caa5045076d1..d22f637fd1f29d65cbbeabb97143dfc6bba10077 100644 --- a/api/funkwhale_api/music/metadata.py +++ b/api/funkwhale_api/music/metadata.py @@ -72,7 +72,7 @@ def clean_id3_pictures(apic): def get_mp4_tag(f, k): if k == "pictures": - return f.get("covr") + return f.get("covr", []) raw_value = f.get(k, None) if not raw_value: diff --git a/api/tests/music/test_metadata.py b/api/tests/music/test_metadata.py index 9a3826ce3832050c8ba15188129b4dc5548a480f..6c9b0384685ce114e07444cc192f0b4d32145a3e 100644 --- a/api/tests/music/test_metadata.py +++ b/api/tests/music/test_metadata.py @@ -219,6 +219,11 @@ def test_can_get_metadata_from_m4a_file(field, value): assert data.get(field) == value +def test_get_pictures_m4a_empty(): + pictures = metadata.get_mp4_tag({}, "pictures") + assert metadata.clean_mp4_pictures(pictures) == [] + + def test_can_get_metadata_from_flac_file_not_crash_if_empty(): path = os.path.join(DATA_DIR, "sample.flac") data = metadata.Metadata(path) diff --git a/changes/changelog.d/946.bugfix b/changes/changelog.d/946.bugfix new file mode 100644 index 0000000000000000000000000000000000000000..9f69983065628371c9e895321b824a238f95fa51 --- /dev/null +++ b/changes/changelog.d/946.bugfix @@ -0,0 +1 @@ +Fix import crash when importing M4A file with no embedded cover (#946)