]> diplodocus.org Git - flac-archive/blob - apic-read.cc
0438a026d73e927a08d2756770e74d0203bbef26
[flac-archive] / apic-read.cc
1 #include <sys/stat.h>
2
3 #include <fcntl.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <unistd.h>
7
8 #include <attachedpictureframe.h>
9 #include <id3v2tag.h>
10 #include <mpegfile.h>
11
12 // some demo apic reading code; would be nice to save all APIC frames.
13
14 int
15 main(int argc, char **argv)
16 {
17 const char *mp3_path = argv[1];
18 TagLib::MPEG::File f(mp3_path);
19 TagLib::ID3v2::Tag *id3v2tag = f.ID3v2Tag();
20 if (!id3v2tag) {
21 return 0;
22 }
23 TagLib::ID3v2::FrameList::ConstIterator it;
24 for (it = id3v2tag->frameList().begin();
25 it != id3v2tag->frameList().end();
26 it++) {
27 TagLib::ByteVector frameid = (*it)->frameID();
28 uint frameid_size = frameid.size();
29 char *frameid_s = new char[frameid_size + 1];
30 memcpy(frameid_s, frameid.data(), frameid_size);
31 frameid_s[frameid_size] = '\0';
32 printf("%s: %s\n", frameid_s, (*it)->toString().toCString());
33 if (frameid != "APIC") {
34 continue;
35 }
36 TagLib::ID3v2::AttachedPictureFrame *frame =
37 (TagLib::ID3v2::AttachedPictureFrame *)(*it);
38 TagLib::ByteVector data = frame->picture();
39 int fd = open(argv[2], O_CREAT | O_WRONLY);
40 write(fd, data.data(), data.size());
41 close(fd);
42 }
43
44 return 0;
45 }