]>
diplodocus.org Git - flac-archive/blob - taglib.cc
dd6526bf8217baadf3e7524423481f999d77652c
1 #include <attachedpictureframe.h>
11 static PyObject
*taglib_error
;
14 taglib_apic(const char *fn
, const char *image
, int len
,
15 int type
, const char *mime_type
)
17 TagLib::ByteVector
*bv
;
18 TagLib::ID3v2::AttachedPictureFrame
*p
;
19 TagLib::MPEG::File
*f
;
20 TagLib::ID3v2::Tag
*t
;
22 bv
= new TagLib::ByteVector (image
, len
);
24 return PyErr_NoMemory();
27 p
= new TagLib::ID3v2::AttachedPictureFrame
;
29 return PyErr_NoMemory();
32 /* Um, look at all these void-returning functions. I'm sure they
33 * can fail, i just have no way to detect it... */
34 p
->setTextEncoding(TagLib::String::UTF8
);
35 p
->setType((TagLib::ID3v2::AttachedPictureFrame::Type
)type
);
36 p
->setMimeType(mime_type
);
39 /* GAH! Opening the file is entangled with allocating the object;
40 * if this fails, am i out of memory, or is there a problem with
41 * the file? Hate C++... */
42 f
= new TagLib::MPEG::File (fn
);
44 return PyErr_NoMemory();
47 t
= f
->ID3v2Tag(true);
49 PyErr_SetString(taglib_error
, "taglib failed to return ID3v2");
53 // another void-returning function that i bet fails
59 PyErr_SetFromErrnoWithFilename(PyExc_IOError
, (char *)fn
);
61 PyErr_SetString(taglib_error
, "taglib failed to save");
71 add_apic_frame_to_mp3(PyObject
*self
, PyObject
*args
)
73 const char *fn
, *image
, *mime_type
;
76 if (!PyArg_ParseTuple(args
, "ss#is", &fn
, &image
, &len
,
81 return taglib_apic(fn
, image
, len
, type
, mime_type
);
85 PyMethodDef methods
[] = {
86 {"add_apic_frame_to_mp3", add_apic_frame_to_mp3
, METH_VARARGS
,
94 PyObject
*m
= Py_InitModule("taglib", methods
);
99 taglib_error
= PyErr_NewException("org.diplodocus.taglib.error", 0, 0);
100 if (taglib_error
== 0) {
103 PyModule_AddObject(m
, "error", taglib_error
);