From 66ef7a73321dda1318b610a17794c7a5d74176d6 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Wed, 16 Oct 2019 10:21:53 +0200 Subject: [PATCH] Fix #946: Fix import crash when importing M4A file with no embedded cover --- api/funkwhale_api/music/metadata.py | 2 +- api/tests/music/test_metadata.py | 5 +++++ changes/changelog.d/946.bugfix | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changes/changelog.d/946.bugfix diff --git a/api/funkwhale_api/music/metadata.py b/api/funkwhale_api/music/metadata.py index 801ea6a9b..d22f637fd 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 9a3826ce3..6c9b03846 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 000000000..9f6998306 --- /dev/null +++ b/changes/changelog.d/946.bugfix @@ -0,0 +1 @@ +Fix import crash when importing M4A file with no embedded cover (#946)