]> diplodocus.org Git - flac-archive/commitdiff
some demo apic reading code; would be nice to save all APIC frames.
authorepg@pretzelnet.org <>
Fri, 2 Nov 2012 07:52:13 +0000 (00:52 -0700)
committerepg@pretzelnet.org <>
Fri, 2 Nov 2012 07:52:13 +0000 (00:52 -0700)
apic-read.cc [new file with mode: 0644]

diff --git a/apic-read.cc b/apic-read.cc
new file mode 100644 (file)
index 0000000..0438a02
--- /dev/null
@@ -0,0 +1,45 @@
+#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;
+}