mirror of
https://github.com/taglib/taglib.git
synced 2026-02-12 11:12:58 -05:00
Make AttachedFile immutable. This is consistent with SimpleTag and Chapter and avoids using attached files which do not have all required attributes. Provide methods to insert and remove a single simple tag, so that they can be modified without setting all of them while still not exposing internal lists to the API. Use DATE_RECORDED instead of DATE_RELEASED for year() and the "DATE" property. This is more consistent with other tag formats, e.g. for ID3v2 "TDRC" is used, which is the recording time.
46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
#include <cstdio>
|
|
#include "matroskafile.h"
|
|
#include "matroskatag.h"
|
|
#include "matroskasimpletag.h"
|
|
#include "matroskaattachments.h"
|
|
#include "matroskaattachedfile.h"
|
|
#include "tfilestream.h"
|
|
#include "tstring.h"
|
|
#include "tutils.h"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
if(argc != 3) {
|
|
printf("Usage: matroskawriter FILE ARTWORK\n");
|
|
return 1;
|
|
}
|
|
TagLib::Matroska::File file(argv[1]);
|
|
if(!file.isValid()) {
|
|
printf("File is not valid\n");
|
|
return 1;
|
|
}
|
|
auto tag = file.tag(true);
|
|
tag->clearSimpleTags();
|
|
|
|
tag->addSimpleTag(TagLib::Matroska::SimpleTag(
|
|
"Test Name 1", TagLib::String("Test Value 1"),
|
|
TagLib::Matroska::SimpleTag::TargetTypeValue::Track, "en"));
|
|
|
|
tag->addSimpleTag(TagLib::Matroska::SimpleTag(
|
|
"Test Name 2", TagLib::String("Test Value 2"),
|
|
TagLib::Matroska::SimpleTag::TargetTypeValue::Album));
|
|
tag->setTitle("Test title");
|
|
tag->setArtist("Test artist");
|
|
tag->setYear(1969);
|
|
|
|
TagLib::FileStream image(argv[2]);
|
|
auto data = image.readBlock(image.length());
|
|
auto attachments = file.attachments(true);
|
|
attachments->addAttachedFile(TagLib::Matroska::AttachedFile(
|
|
data, "cover.jpg", "image/jpeg"));
|
|
|
|
file.save();
|
|
|
|
return 0;
|
|
}
|