]>
diplodocus.org Git - flac-archive/blob - taglib.cc
750bd870ead2e74721a0437bef2a04c6a6095861
11 #include <attachedpictureframe.h>
16 taglib_apic(const char *mp3_path
, const char *image_bytes
, size_t image_len
,
17 const char *description_utf8
, const char *mime_type
)
19 TagLib::MPEG::File
*f
;
20 TagLib::ID3v2::Tag
*t
;
21 TagLib::ByteVector
*bv
;
22 TagLib::ID3v2::AttachedPictureFrame
*p
;
24 /* GAH! Opening the file is entangled with allocating the object;
25 * if this fails, am i out of memory, or is there a problem with
26 * the file? Hate C++... */
27 f
= new TagLib::MPEG::File (mp3_path
);
29 return "new TagLib::MPEG::File failed";
32 t
= f
->ID3v2Tag(true);
34 return "taglib failed to return ID3v2";
37 bv
= new TagLib::ByteVector (image_bytes
, image_len
);
39 return "new TagLib::ByteVector failed";
42 p
= new TagLib::ID3v2::AttachedPictureFrame
;
44 return "new TagLib::ID3v2::AttachedPictureFrame failed";
47 /* Um, look at all these void-returning functions. I'm sure they can fail,
48 * i just have no way to detect it... */
49 p
->setType(TagLib::ID3v2::AttachedPictureFrame::FrontCover
);
50 p
->setMimeType(mime_type
);
51 if (description_utf8
!= 0) {
52 p
->setDescription(description_utf8
);
53 p
->setTextEncoding(TagLib::String::UTF8
);
57 // another void-returning function that i bet fails
63 return strerror(errno
);
65 return "taglib failed to save";
72 main(int argc
, char **argv
)
74 char *description
= 0;
78 while ((c
= getopt(argc
, argv
, "d:m:")) != -1) {
87 // getopt printed an error.
93 fputs("must specify MIME type with -m\n", stderr
);
97 argc
-= optind
; argv
+= optind
;
100 fputs("must specify mp3 filename", stderr
);
103 const char *mp3_path
= argv
[0];
108 const char *image_path
= argv
[1];
109 int fd
= open(image_path
, O_RDONLY
);
111 fprintf(stderr
, "open(%s): %s\n", image_path
, strerror(errno
));
115 if (fstat(fd
, &st
) != 0) {
116 fprintf(stderr
, "stat(%s): %s\n", image_path
, strerror(errno
));
119 image_len
= st
.st_size
;
120 image_bytes
= (char *)malloc(image_len
);
121 if (read(fd
, image_bytes
, image_len
) != image_len
) {
122 fprintf(stderr
, "read(%s): %s\n", image_path
, strerror(errno
));
126 fputs("not yet reading image from stdin\n", stderr
);
130 printf("mp3: %s imagelen: %ld desc: %s mime: %s\n",
131 mp3_path
, (long)image_len
, description
, mime_type
);
134 const char *result
= taglib_apic(mp3_path
, image_bytes
, image_len
, description
, mime_type
);
136 fprintf(stderr
, "%s\n", result
);