--- /dev/null
+#include <sys/stat.h>
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <attachedpictureframe.h>
+#include <id3v2tag.h>
+#include <mpegfile.h>
+
+// some demo apic reading code; would be nice to save all APIC frames.
+
+int
+main(int argc, char **argv)
+{
+ const char *mp3_path = argv[1];
+ TagLib::MPEG::File f(mp3_path);
+ TagLib::ID3v2::Tag *id3v2tag = f.ID3v2Tag();
+ if (!id3v2tag) {
+ return 0;
+ }
+ TagLib::ID3v2::FrameList::ConstIterator it;
+ for (it = id3v2tag->frameList().begin();
+ it != id3v2tag->frameList().end();
+ it++) {
+ TagLib::ByteVector frameid = (*it)->frameID();
+ uint frameid_size = frameid.size();
+ char *frameid_s = new char[frameid_size + 1];
+ memcpy(frameid_s, frameid.data(), frameid_size);
+ frameid_s[frameid_size] = '\0';
+ printf("%s: %s\n", frameid_s, (*it)->toString().toCString());
+ if (frameid != "APIC") {
+ continue;
+ }
+ TagLib::ID3v2::AttachedPictureFrame *frame =
+ (TagLib::ID3v2::AttachedPictureFrame *)(*it);
+ TagLib::ByteVector data = frame->picture();
+ int fd = open(argv[2], O_CREAT | O_WRONLY);
+ write(fd, data.data(), data.size());
+ close(fd);
+ }
+
+ return 0;
+}