Adapt to changes in tagparser (without making actually use of the new API)

This commit is contained in:
Martchus 2021-02-04 23:22:43 +01:00
parent 16c1d96a28
commit 9fbb375924
7 changed files with 47 additions and 31 deletions

View File

@ -2,6 +2,7 @@
#include <tagparser/abstractattachment.h>
#include <tagparser/abstractcontainer.h>
#include <tagparser/progressfeedback.h>
#include <c++utilities/conversion/conversionexception.h>
#include <c++utilities/conversion/stringbuilder.h>
@ -118,7 +119,8 @@ void AttachmentInfo::apply(AbstractAttachment *attachment, TagParser::Diagnostic
attachment->setId(id);
}
if (path) {
attachment->setFile(path, diag);
AbortableProgressFeedback progress;
attachment->setFile(path, diag, progress);
}
if (name) {
attachment->setName(name);

View File

@ -107,7 +107,8 @@ void generateFileInfo(const ArgumentOccurrence &, const Argument &inputFileArg,
inputFileInfo.setForceFullParse(validateArg.isPresent());
inputFileInfo.open(true);
Diagnostics diag;
inputFileInfo.parseEverything(diag);
AbortableProgressFeedback progress; // FIXME: actually use the progress object
inputFileInfo.parseEverything(diag, progress);
// generate and save info
Diagnostics diagReparsing;
@ -148,12 +149,13 @@ void displayFileInfo(const ArgumentOccurrence &, const Argument &filesArg, const
MediaFileInfo fileInfo;
for (const char *file : filesArg.values()) {
Diagnostics diag;
AbortableProgressFeedback progress; // FIXME: actually use the progress object
try {
// parse tags
fileInfo.setPath(file);
fileInfo.open(true);
fileInfo.parseContainerFormat(diag);
fileInfo.parseEverything(diag);
fileInfo.parseContainerFormat(diag, progress);
fileInfo.parseEverything(diag, progress);
// print general/container-related info
cout << "Technical information for \"" << file << "\":\n";
@ -331,12 +333,13 @@ void displayTagInfo(const Argument &fieldsArg, const Argument &showUnsupportedAr
MediaFileInfo fileInfo;
for (const char *file : filesArg.values()) {
Diagnostics diag;
AbortableProgressFeedback progress; // FIXME: actually use the progress object
try {
// parse tags
fileInfo.setPath(file);
fileInfo.open(true);
fileInfo.parseContainerFormat(diag);
fileInfo.parseTags(diag);
fileInfo.parseContainerFormat(diag, progress);
fileInfo.parseTags(diag, progress);
cout << "Tag information for \"" << file << "\":\n";
const auto tags = fileInfo.tags();
if (tags.empty()) {
@ -503,14 +506,15 @@ void setTagInfo(const SetTagInfoArgs &args)
static string context("setting tags");
for (const char *file : args.filesArg.values()) {
Diagnostics diag;
AbortableProgressFeedback progress; // FIXME: actually use the progress object
try {
// parse tags and tracks (tracks are relevent because track meta-data such as language can be changed as well)
cout << TextAttribute::Bold << "Setting tag information for \"" << file << "\" ..." << Phrases::EndFlush;
fileInfo.setPath(file);
fileInfo.parseContainerFormat(diag);
fileInfo.parseTags(diag);
fileInfo.parseTracks(diag);
fileInfo.parseAttachments(diag);
fileInfo.parseContainerFormat(diag, progress);
fileInfo.parseTags(diag, progress);
fileInfo.parseTracks(diag, progress);
fileInfo.parseAttachments(diag, progress);
vector<Tag *> tags;
// remove tags with the specified targets
@ -616,8 +620,9 @@ void setTagInfo(const SetTagInfoArgs &args)
// assume the file refers to a picture
MediaFileInfo fileInfo(relevantDenotedValue->value);
Diagnostics diag;
AbortableProgressFeedback progress; // FIXME: actually use the progress object
fileInfo.open(true);
fileInfo.parseContainerFormat(diag);
fileInfo.parseContainerFormat(diag, progress);
auto buff = make_unique<char[]>(fileInfo.size());
fileInfo.stream().seekg(static_cast<streamoff>(fileInfo.containerOffset()));
fileInfo.stream().read(buff.get(), static_cast<streamoff>(fileInfo.size()));
@ -699,7 +704,7 @@ void setTagInfo(const SetTagInfoArgs &args)
if (args.addAttachmentArg.isPresent() || args.updateAttachmentArg.isPresent() || args.removeAttachmentArg.isPresent()
|| args.removeExistingAttachmentsArg.isPresent()) {
static const string context("setting attachments");
fileInfo.parseAttachments(diag);
fileInfo.parseAttachments(diag, progress);
if (fileInfo.attachmentsParsingStatus() == ParsingStatus::Ok && container) {
// ignore all existing attachments if argument is specified
if (args.removeExistingAttachmentsArg.isPresent()) {
@ -800,6 +805,7 @@ void extractField(
MediaFileInfo inputFileInfo;
for (const char *file : inputFilesArg.values()) {
Diagnostics diag;
AbortableProgressFeedback progress; // FIXME: actually use the progress object
try {
// setup media file info
inputFileInfo.setPath(file);
@ -809,8 +815,8 @@ void extractField(
if (!fieldDenotations.empty()) {
// extract tag field
(outputFileArg.isPresent() ? cout : cerr) << "Extracting field " << fieldArg.values().front() << " of \"" << file << "\" ..." << endl;
inputFileInfo.parseContainerFormat(diag);
inputFileInfo.parseTags(diag);
inputFileInfo.parseContainerFormat(diag, progress);
inputFileInfo.parseTags(diag, progress);
auto tags = inputFileInfo.tags();
vector<pair<const TagValue *, string>> values;
// iterate through all tags
@ -873,8 +879,8 @@ void extractField(
}
logStream << " of \"" << file << "\" ..." << endl;
inputFileInfo.parseContainerFormat(diag);
inputFileInfo.parseAttachments(diag);
inputFileInfo.parseContainerFormat(diag, progress);
inputFileInfo.parseAttachments(diag, progress);
vector<pair<const AbstractAttachment *, string>> attachments;
// iterate through all attachments
for (const AbstractAttachment *attachment : inputFileInfo.attachments()) {
@ -938,15 +944,16 @@ void exportToJson(const ArgumentOccurrence &, const Argument &filesArg, const Ar
MediaFileInfo fileInfo;
// gather tags for each file
Diagnostics diag; // FIXME: actually use diag object
AbortableProgressFeedback progress; // FIXME: actually use the progress object
for (const char *file : filesArg.values()) {
Diagnostics diag;
try {
// parse tags
fileInfo.setPath(file);
fileInfo.open(true);
fileInfo.parseContainerFormat(diag);
fileInfo.parseTags(diag);
fileInfo.parseTracks(diag);
fileInfo.parseContainerFormat(diag, progress);
fileInfo.parseTags(diag, progress);
fileInfo.parseTracks(diag, progress);
jsonData.emplace_back(fileInfo, document.GetAllocator());
} catch (const TagParser::Failure &) {
cerr << Phrases::Error << "A parsing failure occured when reading the file \"" << file << "\"." << Phrases::EndFlush;

View File

@ -7,6 +7,7 @@
#include <tagparser/abstractattachment.h>
#include <tagparser/diagnostics.h>
#include <tagparser/mediafileinfo.h>
#include <tagparser/progressfeedback.h>
#include <qtutilities/misc/conversion.h>
@ -99,7 +100,8 @@ void AttachmentsEdit::addFile(const QString &path)
auto *const attachment = fileInfo()->container()->createAttachment();
attachment->setIgnored(true);
Diagnostics diag;
attachment->setFile(toNativeFileName(path).data(), diag);
AbortableProgressFeedback progress; // FIXME: actually use the progress object
attachment->setFile(toNativeFileName(path).data(), diag, progress);
// TODO: show diag messages
m_addedAttachments << attachment;
m_model->addAttachment(-1, attachment, true, path);

View File

@ -10,6 +10,7 @@
#include <tagparser/id3/id3v2frame.h>
#include <tagparser/id3/id3v2tag.h>
#include <tagparser/mediafileinfo.h>
#include <tagparser/progressfeedback.h>
#include <tagparser/tag.h>
#include <tagparser/vorbis/vorbiscomment.h>
#include <tagparser/vorbis/vorbiscommentfield.h>
@ -416,10 +417,10 @@ void PicturePreviewSelection::addOfSelectedType(const QString &path)
TagValue &selectedCover = m_values[m_currentTypeIndex];
try {
MediaFileInfo fileInfo(toNativeFileName(path).constData());
Diagnostics diag;
Diagnostics diag; // FIXME: show diagnostic messages
AbortableProgressFeedback progress; // FIXME: actually use the progress object
fileInfo.open(true);
fileInfo.parseContainerFormat(diag);
// TODO: show diagnostic messages
fileInfo.parseContainerFormat(diag, progress);
const auto detectedMimeType = fileInfo.mimeType();
auto mimeType = QString::fromUtf8(detectedMimeType.data(), detectedMimeType.size());

View File

@ -832,13 +832,14 @@ bool TagEditorWidget::startParsing(const QString &path, bool forceRefresh)
// write diagnostics to m_diagReparsing if making results are avalable
m_makingResultsAvailable &= sameFile;
Diagnostics &diag = m_makingResultsAvailable ? m_diagReparsing : m_diag;
AbortableProgressFeedback progress; // FIXME: actually use the progress object
// clear diagnostics
diag.clear();
m_diagReparsing.clear();
// show filename
m_ui->fileNameLabel->setText(m_fileName);
// define function to parse the file
const auto startThread = [this, &diag] {
const auto startThread = [this, &diag, &progress] {
char result;
try {
// try to open with write access
@ -849,7 +850,7 @@ bool TagEditorWidget::startParsing(const QString &path, bool forceRefresh)
m_fileInfo.reopen(true);
}
m_fileInfo.setForceFullParse(Settings::values().editor.forceFullParse);
m_fileInfo.parseEverything(diag);
m_fileInfo.parseEverything(diag, progress);
result = ParsingSuccessful;
} catch (const Failure &) {
// the file has been opened; parsing notifications will be shown in the info box
@ -975,8 +976,7 @@ void TagEditorWidget::showFile(char result)
if (diagLevel >= TagParser::DiagLevel::Critical) {
m_ui->parsingNotificationWidget->setNotificationType(NotificationType::Critical);
m_ui->parsingNotificationWidget->appendLine(tr("Errors occured."));
} else if (diagLevel == TagParser::DiagLevel::Warning || m_fileInfo.isReadOnly() || !m_fileInfo.areTagsSupported()
|| multipleSegmentsNotTested) {
} else if (diagLevel == TagParser::DiagLevel::Warning || m_fileInfo.isReadOnly() || !m_fileInfo.areTagsSupported() || multipleSegmentsNotTested) {
m_ui->parsingNotificationWidget->setNotificationType(NotificationType::Warning);
if (diagLevel == TagParser::DiagLevel::Warning) {
m_ui->parsingNotificationWidget->appendLine(tr("There are warnings."));

View File

@ -9,6 +9,7 @@
#include <tagparser/abstracttrack.h>
#include <tagparser/exceptions.h>
#include <tagparser/mediafileinfo.h>
#include <tagparser/progressfeedback.h>
#include <tagparser/tag.h>
#include <tagparser/tagvalue.h>
@ -143,6 +144,7 @@ const QString &TagEditorObject::newRelativeDirectory() const
TAGEDITOR_JS_VALUE TagEditorObject::parseFileInfo(const QString &fileName)
{
Diagnostics diag;
AbortableProgressFeedback progress; // FIXME: actually use the progress object
MediaFileInfo fileInfo(toNativeFileName(fileName).data());
// add basic file information
@ -160,7 +162,7 @@ TAGEDITOR_JS_VALUE TagEditorObject::parseFileInfo(const QString &fileName)
// parse further file information
bool criticalParseingErrorOccured = false, ioErrorOccured = false;
try {
fileInfo.parseEverything(diag);
fileInfo.parseEverything(diag, progress);
} catch (const Failure &) {
// parsing notifications will be addded anyways
criticalParseingErrorOccured = true;

View File

@ -7,6 +7,7 @@
#include <tagparser/diagnostics.h>
#include <tagparser/mediafileinfo.h>
#include <tagparser/progressfeedback.h>
namespace CppUtilities {
@ -900,9 +901,10 @@ void CliTests::testExtraction()
const char *const args1[] = { "tageditor", "extract", "cover", "-f", mp4File1.data(), "-o", "/tmp/extracted.jpeg", nullptr };
TESTUTILS_ASSERT_EXEC(args1);
Diagnostics diag;
AbortableProgressFeedback progress;
MediaFileInfo extractedInfo("/tmp/extracted.jpeg");
extractedInfo.open(true);
extractedInfo.parseContainerFormat(diag);
extractedInfo.parseContainerFormat(diag, progress);
CPPUNIT_ASSERT_EQUAL(static_cast<std::uint64_t>(22771), extractedInfo.size());
CPPUNIT_ASSERT(ContainerFormat::Jpeg == extractedInfo.containerFormat());
extractedInfo.invalidate();
@ -915,7 +917,7 @@ void CliTests::testExtraction()
CPPUNIT_ASSERT_EQUAL(0, remove("/tmp/extracted.jpeg"));
TESTUTILS_ASSERT_EXEC(args3);
extractedInfo.open(true);
extractedInfo.parseContainerFormat(diag);
extractedInfo.parseContainerFormat(diag, progress);
CPPUNIT_ASSERT_EQUAL(static_cast<std::uint64_t>(22771), extractedInfo.size());
CPPUNIT_ASSERT(ContainerFormat::Jpeg == extractedInfo.containerFormat());
CPPUNIT_ASSERT_EQUAL(0, remove("/tmp/extracted.jpeg"));