Repository: mopidy/mopidy-local

Issue:
Not extracting images from m4a files when scanning
Whenever I execute `mopidy local scan --force` in my terminal, I get an error extracting the image from any m4a file.

Example: `WARNING  2021-02-20 22:42:52,743 [111960:MainThread] mopidy_local.storage
  Error extracting images for 'local:track:MDMA/Genie%20%28Deluxe%29/01%20Xccelerate.m4a': ValueError('Unknown image type')`

I can play these files completely fine with ncmpcpp's file browser and they are tagged properly too but I can't scan them into my library.

Discussion:

Patch:
diff --git a/mopidy_local/storage.py b/mopidy_local/storage.py
index a8679c3..9f9947c 100644
--- a/mopidy_local/storage.py
+++ b/mopidy_local/storage.py
@@ -58,6 +58,15 @@ def get_image_size_jpeg(data):
     return width, height
 
 
+def test_jpeg(data, file_handle):
+    # Additional JPEG detection looking for JPEG SOI marker
+    if data[:2] == b"\xff\xd8":
+        return "jpeg"
+
+
+imghdr.tests.append(test_jpeg)
+
+
 class LocalStorageProvider:
     def __init__(self, config):
         self._config = ext_config = config[Extension.ext_name]


Test patch:
diff --git a/tests/test_storage.py b/tests/test_storage.py
new file mode 100644
index 0000000..6caed2c
--- /dev/null
+++ b/tests/test_storage.py
@@ -0,0 +1,16 @@
+import pytest
+
+from mopidy_local import storage
+
+
+@pytest.mark.parametrize(
+    "data",
+    [
+        pytest.param("ffd8ffe000104a46494600", id="JFIF"),
+        pytest.param("ffd8ffe100184578696600", id="Exif"),
+        pytest.param("ffd8ffe1095068747470", id="XMP"),
+    ],
+)
+def test_jpeg_detection(data):
+    data_bytes = bytes.fromhex(data)
+    assert storage.imghdr.what(None, data_bytes) is not None