summaryrefslogtreecommitdiff
path: root/src/tag
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-08-12 13:39:29 +0200
committerMax Kellermann <max@musicpd.org>2019-08-12 20:31:43 +0200
commit575ba5193137ead33ba8bd4627d46283c423c644 (patch)
tree8bf5ee047fc33d3d48302f8b4a7e23d4cb91cd96 /src/tag
parent96a1c69c292db2a75aa7c27a3b9872a2252452b1 (diff)
tag/Id3Scan: support embedded pictures (the "APIC" tag)
Diffstat (limited to 'src/tag')
-rw-r--r--src/tag/Id3Scan.cxx42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/tag/Id3Scan.cxx b/src/tag/Id3Scan.cxx
index ca862c86e..092b66f5a 100644
--- a/src/tag/Id3Scan.cxx
+++ b/src/tag/Id3Scan.cxx
@@ -286,6 +286,47 @@ tag_id3_import_ufid(const struct id3_tag *id3_tag,
}
}
+/**
+ * Handle "APIC" ("attached picture") tags.
+ */
+static void
+tag_id3_handle_apic(const struct id3_tag *id3_tag,
+ TagHandler &handler) noexcept
+{
+ if (!handler.WantPicture())
+ return;
+
+ for (unsigned i = 0;; ++i) {
+ const id3_frame *frame = id3_tag_findframe(id3_tag, "APIC", i);
+ if (frame == nullptr)
+ break;
+
+ id3_field *mime_type_field = id3_frame_field(frame, 1);
+ if (mime_type_field == nullptr)
+ continue;
+
+ const char *mime_type = (const char *)
+ id3_field_getlatin1(mime_type_field);
+ if (mime_type != nullptr &&
+ StringIsEqual(mime_type, "-->"))
+ /* this is a URL, not image data */
+ continue;
+
+ id3_field *data_field = id3_frame_field(frame, 4);
+ if (data_field == nullptr ||
+ data_field->type != ID3_FIELD_TYPE_BINARYDATA)
+ continue;
+
+ id3_length_t size;
+ const id3_byte_t *data =
+ id3_field_getbinarydata(data_field, &size);
+ if (data == nullptr || size == 0)
+ continue;
+
+ handler.OnPicture(mime_type, {data, size});
+ }
+}
+
void
scan_id3_tag(const struct id3_tag *tag, TagHandler &handler) noexcept
{
@@ -327,6 +368,7 @@ scan_id3_tag(const struct id3_tag *tag, TagHandler &handler) noexcept
tag_id3_import_musicbrainz(tag, handler);
tag_id3_import_ufid(tag, handler);
+ tag_id3_handle_apic(tag, handler);
}
Tag