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
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()) {
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
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;
}