Package: xmms2-plugin-vorbis
Version: 0.6DrMattDestruction-7
Severity: wishlist
Tags: patch

Just as mp3 files can contain embedded cover art via the APIC frame,
vorbis files can contain images in a METADATA_BLOCK_PICTURE comment. See
http://wiki.xiph.org/index.php/VorbisComment#Cover_art for details.

It would be nice if this were supported. Patch attached.
diff -bBur xmms2-0.6DrMattDestruction.old/src/plugins/vorbis/vorbis.c 
xmms2-0.6DrMattDestruction/src/plugins/vorbis/vorbis.c
--- xmms2-0.6DrMattDestruction.old/src/plugins/vorbis/vorbis.c  2009-04-21 
13:51:11.000000000 -0400
+++ xmms2-0.6DrMattDestruction/src/plugins/vorbis/vorbis.c      2010-01-15 
22:45:08.971009555 -0500
@@ -246,6 +246,74 @@
        }
 }
 
+static void
+handle_image_comment (xmms_xform_t *xform, const gchar *value, gsize len)
+{
+       guint32 typ, mime_len, desc_len, img_len;
+       guchar *pos, *end, *mime_data, *img_data;
+       gchar hash[33];
+
+       pos = value;
+       end = value + len;
+
+       if (pos + 4 > end) {
+               XMMS_DBG ("Malformed picture comment");
+               return;
+       }
+       typ = GUINT32_FROM_BE (*(guint32 *)pos);
+       if (typ != 0 && typ != 3) {
+               XMMS_DBG ("Picture type %d not handled", typ);
+               return;
+       }
+       pos += 4;
+
+       if (pos + 4 > end) {
+               XMMS_DBG ("Malformed picture comment");
+               return;
+       }
+       mime_len = GUINT32_FROM_BE (*(guint32 *)pos);
+       pos += 4;
+       mime_data = pos;
+       pos += mime_len;
+
+       if (pos + 4 > end) {
+               XMMS_DBG ("Malformed picture comment");
+               return;
+       }
+       desc_len = GUINT32_FROM_BE (*(guint32 *)pos);
+       pos += 4;
+       pos += desc_len;
+
+       pos += 4; /* width */
+       pos += 4; /* height */
+       pos += 4; /* depth */
+       pos += 4; /* indexed palette length */
+
+       if (pos + 4 > end) {
+               XMMS_DBG ("Malformed picture comment");
+               return;
+       }
+       img_len = GUINT32_FROM_BE (*(guint32 *)pos);
+       pos += 4;
+       img_data = pos;
+
+       if (img_data + img_len > end) {
+               XMMS_DBG ("Malformed picture comment");
+               return;
+       }
+
+       if (xmms_bindata_plugin_add ((const guchar *)img_data, img_len, hash)) {
+               const gchar *metakey;
+
+               metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_PICTURE_FRONT;
+               xmms_xform_metadata_set_str (xform, metakey, hash);
+
+               metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_PICTURE_FRONT_MIME;
+               mime_data[mime_len] = '\0';
+               xmms_xform_metadata_set_str (xform, metakey, mime_data);
+       }
+}
+
 /* note that "key" is NOT NUL-terminated here,
  * but "value" is.
  */
@@ -256,6 +324,14 @@
 {
        gint i;
 
+       if (!g_ascii_strncasecmp (key, "METADATA_BLOCK_PICTURE", key_len)) {
+               gsize dlen;
+               gchar *dvalue = g_base64_decode (value, &dlen);
+               handle_image_comment (xform, dvalue, dlen);
+               g_free (dvalue);
+               return;
+       }
+
        for (i = 0; i < G_N_ELEMENTS (properties); i++) {
                if ((!g_ascii_strncasecmp (key, "MUSICBRAINZ_ALBUMARTISTID", 
key_len)) &&
                    (!g_ascii_strcasecmp (value, MUSICBRAINZ_VA_ID))) {

Reply via email to