X-Git-Url: https://diplodocus.org/git/flac-archive/blobdiff_plain/7c8eeba5a67251012ecdebdba9a677b4aba04f9d..43110c1614d5335df6ebf6c2233812f47968b1c4:/taglib.cc diff --git a/taglib.cc b/taglib.cc index dd6526b..1f04d16 100644 --- a/taglib.cc +++ b/taglib.cc @@ -11,30 +11,15 @@ extern "C" { static PyObject *taglib_error; static PyObject * -taglib_apic(const char *fn, const char *image, int len, - int type, const char *mime_type) +taglib_apic(const char *fn, PyObject *list) { - TagLib::ByteVector *bv; - TagLib::ID3v2::AttachedPictureFrame *p; TagLib::MPEG::File *f; TagLib::ID3v2::Tag *t; - - bv = new TagLib::ByteVector (image, len); - if (bv == 0) { - return PyErr_NoMemory(); - } - - p = new TagLib::ID3v2::AttachedPictureFrame; - if (p == 0) { - return PyErr_NoMemory(); - } - - /* Um, look at all these void-returning functions. I'm sure they - * can fail, i just have no way to detect it... */ - p->setTextEncoding(TagLib::String::UTF8); - p->setType((TagLib::ID3v2::AttachedPictureFrame::Type)type); - p->setMimeType(mime_type); - p->setPicture(*bv); + PyObject *tuple, *description, *description_utf8; + int i, type, width, height, depth, colors, len; + const char *mime_type, *description_utf8_s, *image; + TagLib::ByteVector *bv; + TagLib::ID3v2::AttachedPictureFrame *p; /* GAH! Opening the file is entangled with allocating the object; * if this fails, am i out of memory, or is there a problem with @@ -50,8 +35,46 @@ taglib_apic(const char *fn, const char *image, int len, return 0; } - // another void-returning function that i bet fails - t->addFrame(p); + for (i = 0; i < PyList_Size(list); i++) { + tuple = PyList_GetItem(list, i); + if (!PyArg_ParseTuple(tuple, "isUiiiis#", + &type, &mime_type, &description, &width, &height, &depth, &colors, &image, &len)) { + return 0; + } + + description_utf8 = PyUnicode_AsEncodedString(description, "utf8", + "strict"); + if (description_utf8 == 0) { + return 0; + } + + description_utf8_s = PyString_AsString(description_utf8); + if (description_utf8_s == 0) { + return 0; + } + + bv = new TagLib::ByteVector (image, len); + if (bv == 0) { + return PyErr_NoMemory(); + } + + p = new TagLib::ID3v2::AttachedPictureFrame; + if (p == 0) { + return PyErr_NoMemory(); + } + + /* Um, look at all these void-returning functions. I'm sure + * they can fail, i just have no way to detect it... */ + p->setType((TagLib::ID3v2::AttachedPictureFrame::Type)type); + p->setMimeType(mime_type); + p->setDescription(description_utf8_s); + p->setTextEncoding(TagLib::String::UTF8); + // taglib doesn't support width, height, depth, colors. + p->setPicture(*bv); + + // another void-returning function that i bet fails + t->addFrame(p); + } errno = 0; if (!f->save()) { @@ -70,15 +93,14 @@ taglib_apic(const char *fn, const char *image, int len, static PyObject * add_apic_frame_to_mp3(PyObject *self, PyObject *args) { - const char *fn, *image, *mime_type; - int len, type; + const char *fn; + PyObject *list; - if (!PyArg_ParseTuple(args, "ss#is", &fn, &image, &len, - &type, &mime_type)) { + if (!PyArg_ParseTuple(args, "sO", &fn, &list)) { return 0; } - return taglib_apic(fn, image, len, type, mime_type); + return taglib_apic(fn, list); } static @@ -96,7 +118,7 @@ inittaglib(void) return; } - taglib_error = PyErr_NewException("org.diplodocus.taglib.error", 0, 0); + taglib_error = PyErr_NewException("flac_archive.taglib.error", 0, 0); if (taglib_error == 0) { return; }