]>
diplodocus.org Git - flac-archive/blob - apic-read.cc
194e3406eb219556d8107e962214dd0646d8b7ec
9 #include <attachedpictureframe.h>
13 // some demo apic reading code; would be nice to save all APIC frames.
15 using TagLib::ID3v2::Tag
;
16 using TagLib::ID3v2::FrameList
;
17 using TagLib::ID3v2::AttachedPictureFrame
;
20 main(int argc
, char **argv
)
22 const char *mp3_path
= argv
[1];
23 TagLib::MPEG::File
f(mp3_path
);
24 Tag
*id3v2tag
= f
.ID3v2Tag();
28 const FrameList
&frames
= id3v2tag
->frameList();
29 FrameList::ConstIterator it
;
30 for (it
= frames
.begin(); it
!= frames
.end(); it
++) {
31 TagLib::ByteVector frameid
= (*it
)->frameID();
32 uint frameid_size
= frameid
.size();
33 char *frameid_s
= new char[frameid_size
+ 1];
34 memcpy(frameid_s
, frameid
.data(), frameid_size
);
35 frameid_s
[frameid_size
] = '\0';
36 printf("%s: %s\n", frameid_s
, (*it
)->toString().toCString());
37 if (frameid
!= "APIC") {
40 AttachedPictureFrame
*frame
= (AttachedPictureFrame
*)(*it
);
41 TagLib::ByteVector data
= frame
->picture();
42 int fd
= open(argv
[2], O_CREAT
| O_WRONLY
);
43 ssize_t size
= data
.size();
44 ssize_t status
= write(fd
, data
.data(), size
);
50 fprintf(stderr
, "wrote only %d bytes out of %d\n", status
, size
);