diff --git a/src/extractors/epubextractor.cpp b/src/extractors/epubextractor.cpp --- a/src/extractors/epubextractor.cpp +++ b/src/extractors/epubextractor.cpp @@ -78,34 +78,36 @@ result->addType(Type::Document); - QString value = fetchMetadata(ePubDoc, EPUB_TITLE); - if (!value.isEmpty()) { - result->add(Property::Title, value); - } + if (result->inputFlags() & ExtractionResult::ExtractMetaData) { - value = fetchMetadata(ePubDoc, EPUB_SUBJECT); - if (!value.isEmpty()) { - result->add(Property::Subject, value); - } + QString value = fetchMetadata(ePubDoc, EPUB_TITLE); + if (!value.isEmpty()) { + result->add(Property::Title, value); + } - value = fetchMetadata(ePubDoc, EPUB_CREATOR); - if (!value.isEmpty()) { - if (value.startsWith(QLatin1String("aut:"), Qt::CaseInsensitive)) { - value = value.mid(4).simplified(); - } else if (value.startsWith(QLatin1String("author:"), Qt::CaseInsensitive)) { - value = value.mid(7).simplified(); + value = fetchMetadata(ePubDoc, EPUB_SUBJECT); + if (!value.isEmpty()) { + result->add(Property::Subject, value); } - // A lot of authors have their name written in () again. We discard that part - int index = value.indexOf(QLatin1Char('(')); - if (index) - value = value.mid(0, index); + value = fetchMetadata(ePubDoc, EPUB_CREATOR); + if (!value.isEmpty()) { + if (value.startsWith(QLatin1String("aut:"), Qt::CaseInsensitive)) { + value = value.mid(4).simplified(); + } else if (value.startsWith(QLatin1String("author:"), Qt::CaseInsensitive)) { + value = value.mid(7).simplified(); + } + + // A lot of authors have their name written in () again. We discard that part + int index = value.indexOf(QLatin1Char('(')); + if (index) + value = value.mid(0, index); - result->add(Property::Author, value); - } + result->add(Property::Author, value); + } - // The Contributor just seems to be mostly Calibre aka the Generator - /* + // The Contributor just seems to be mostly Calibre aka the Generator + /* value = fetchMetadata(ePubDoc, EPUB_CONTRIB); if( !value.isEmpty() ) { SimpleResource con; @@ -116,29 +118,30 @@ graph << con; }*/ - value = fetchMetadata(ePubDoc, EPUB_PUBLISHER); - if (!value.isEmpty()) { - result->add(Property::Publisher, value); - } - - value = fetchMetadata(ePubDoc, EPUB_DESCRIPTION); - if (!value.isEmpty()) { - result->add(Property::Description, value); - } - - value = fetchMetadata(ePubDoc, EPUB_DATE); - if (!value.isEmpty()) { - if (value.startsWith(QLatin1String("Unspecified:"), Qt::CaseInsensitive)) { - value = value.mid(QByteArray("Unspecified:").size()).simplified(); + value = fetchMetadata(ePubDoc, EPUB_PUBLISHER); + if (!value.isEmpty()) { + result->add(Property::Publisher, value); } - int ind = value.indexOf(QLatin1String("publication:"), Qt::CaseInsensitive); - if (ind != -1) { - value = value.mid(ind + QByteArray("publication:").size()).simplified(); + + value = fetchMetadata(ePubDoc, EPUB_DESCRIPTION); + if (!value.isEmpty()) { + result->add(Property::Description, value); } - QDateTime dt = ExtractorPlugin::dateTimeFromString(value); - if (!dt.isNull()) { - result->add(Property::CreationDate, dt); - result->add(Property::ReleaseYear, dt.date().year()); + + value = fetchMetadata(ePubDoc, EPUB_DATE); + if (!value.isEmpty()) { + if (value.startsWith(QLatin1String("Unspecified:"), Qt::CaseInsensitive)) { + value = value.mid(QByteArray("Unspecified:").size()).simplified(); + } + int ind = value.indexOf(QLatin1String("publication:"), Qt::CaseInsensitive); + if (ind != -1) { + value = value.mid(ind + QByteArray("publication:").size()).simplified(); + } + QDateTime dt = ExtractorPlugin::dateTimeFromString(value); + if (!dt.isNull()) { + result->add(Property::CreationDate, dt); + result->add(Property::ReleaseYear, dt.date().year()); + } } } diff --git a/src/extractors/exiv2extractor.cpp b/src/extractors/exiv2extractor.cpp --- a/src/extractors/exiv2extractor.cpp +++ b/src/extractors/exiv2extractor.cpp @@ -169,67 +169,70 @@ } result->addType(Type::Image); - if (image->pixelHeight()) { - result->add(Property::Height, image->pixelHeight()); - } + if (result->inputFlags() & ExtractionResult::ExtractMetaData) { - if (image->pixelWidth()) { - result->add(Property::Width, image->pixelWidth()); - } + if (image->pixelHeight()) { + result->add(Property::Height, image->pixelHeight()); + } - std::string comment = image->comment(); - if (!comment.empty()) { - result->add(Property::Comment, QString::fromUtf8(comment.c_str(), comment.length())); - } + if (image->pixelWidth()) { + result->add(Property::Width, image->pixelWidth()); + } - const Exiv2::ExifData& data = image->exifData(); - - add(result, data, Property::Manufacturer, "Exif.Image.Make", QVariant::String); - add(result, data, Property::Model, "Exif.Image.Model", QVariant::String); - add(result, data, Property::Description, "Exif.Image.ImageDescription", QVariant::String); - add(result, data, Property::Artist, "Exif.Image.Artist", QVariant::String); - add(result, data, Property::Copyright, "Exif.Image.Copyright", QVariant::String); - add(result, data, Property::Generator, "Exif.Image.Software", QVariant::String); - add(result, data, Property::ImageDateTime, "Exif.Image.DateTime", QVariant::DateTime); - add(result, data, Property::ImageOrientation, "Exif.Image.Orientation", QVariant::Int); - add(result, data, Property::PhotoFlash, "Exif.Photo.Flash", QVariant::Int); - add(result, data, Property::PhotoPixelXDimension, "Exif.Photo.PixelXDimension", QVariant::Int); - add(result, data, Property::PhotoPixelYDimension, "Exif.Photo.PixelYDimension", QVariant::Int); - add(result, data, Property::PhotoDateTimeOriginal, "Exif.Photo.DateTimeOriginal", QVariant::DateTime); - add(result, data, Property::PhotoFocalLength, "Exif.Photo.FocalLength", QVariant::Double); - add(result, data, Property::PhotoFocalLengthIn35mmFilm, "Exif.Photo.FocalLengthIn35mmFilm", QVariant::Double); - add(result, data, Property::PhotoExposureTime, "Exif.Photo.ExposureTime", QVariant::Double); - add(result, data, Property::PhotoExposureBiasValue, "Exif.Photo.ExposureBiasValue", QVariant::Double); - add(result, data, Property::PhotoFNumber, "Exif.Photo.FNumber", QVariant::Double); - add(result, data, Property::PhotoApertureValue, "Exif.Photo.ApertureValue", QVariant::Double); - add(result, data, Property::PhotoWhiteBalance, "Exif.Photo.WhiteBalance", QVariant::Int); - add(result, data, Property::PhotoMeteringMode, "Exif.Photo.MeteringMode", QVariant::Int); - add(result, data, Property::PhotoISOSpeedRatings, "Exif.Photo.ISOSpeedRatings", QVariant::Int); - add(result, data, Property::PhotoSaturation, "Exif.Photo.Saturation", QVariant::Int); - add(result, data, Property::PhotoSharpness, "Exif.Photo.Sharpness", QVariant::Int); - - double latitude = fetchGpsDouble(data, "Exif.GPSInfo.GPSLatitude"); - double longitude = fetchGpsDouble(data, "Exif.GPSInfo.GPSLongitude"); - double altitude = fetchGpsAltitude(data); - - QByteArray latRef = fetchByteArray(data, "Exif.GPSInfo.GPSLatitudeRef"); - if (!latRef.isEmpty() && latRef[0] == 'S') - latitude *= -1; - - QByteArray longRef = fetchByteArray(data, "Exif.GPSInfo.GPSLongitudeRef"); - if (!longRef.isEmpty() && longRef[0] == 'W') - longitude *= -1; - - if (!std::isnan(latitude)) { - result->add(Property::PhotoGpsLatitude, latitude); - } + std::string comment = image->comment(); + if (!comment.empty()) { + result->add(Property::Comment, QString::fromUtf8(comment.c_str(), comment.length())); + } - if (!std::isnan(longitude)) { - result->add(Property::PhotoGpsLongitude, longitude); - } + const Exiv2::ExifData& data = image->exifData(); + + add(result, data, Property::Manufacturer, "Exif.Image.Make", QVariant::String); + add(result, data, Property::Model, "Exif.Image.Model", QVariant::String); + add(result, data, Property::Description, "Exif.Image.ImageDescription", QVariant::String); + add(result, data, Property::Artist, "Exif.Image.Artist", QVariant::String); + add(result, data, Property::Copyright, "Exif.Image.Copyright", QVariant::String); + add(result, data, Property::Generator, "Exif.Image.Software", QVariant::String); + add(result, data, Property::ImageDateTime, "Exif.Image.DateTime", QVariant::DateTime); + add(result, data, Property::ImageOrientation, "Exif.Image.Orientation", QVariant::Int); + add(result, data, Property::PhotoFlash, "Exif.Photo.Flash", QVariant::Int); + add(result, data, Property::PhotoPixelXDimension, "Exif.Photo.PixelXDimension", QVariant::Int); + add(result, data, Property::PhotoPixelYDimension, "Exif.Photo.PixelYDimension", QVariant::Int); + add(result, data, Property::PhotoDateTimeOriginal, "Exif.Photo.DateTimeOriginal", QVariant::DateTime); + add(result, data, Property::PhotoFocalLength, "Exif.Photo.FocalLength", QVariant::Double); + add(result, data, Property::PhotoFocalLengthIn35mmFilm, "Exif.Photo.FocalLengthIn35mmFilm", QVariant::Double); + add(result, data, Property::PhotoExposureTime, "Exif.Photo.ExposureTime", QVariant::Double); + add(result, data, Property::PhotoExposureBiasValue, "Exif.Photo.ExposureBiasValue", QVariant::Double); + add(result, data, Property::PhotoFNumber, "Exif.Photo.FNumber", QVariant::Double); + add(result, data, Property::PhotoApertureValue, "Exif.Photo.ApertureValue", QVariant::Double); + add(result, data, Property::PhotoWhiteBalance, "Exif.Photo.WhiteBalance", QVariant::Int); + add(result, data, Property::PhotoMeteringMode, "Exif.Photo.MeteringMode", QVariant::Int); + add(result, data, Property::PhotoISOSpeedRatings, "Exif.Photo.ISOSpeedRatings", QVariant::Int); + add(result, data, Property::PhotoSaturation, "Exif.Photo.Saturation", QVariant::Int); + add(result, data, Property::PhotoSharpness, "Exif.Photo.Sharpness", QVariant::Int); + + double latitude = fetchGpsDouble(data, "Exif.GPSInfo.GPSLatitude"); + double longitude = fetchGpsDouble(data, "Exif.GPSInfo.GPSLongitude"); + double altitude = fetchGpsAltitude(data); + + QByteArray latRef = fetchByteArray(data, "Exif.GPSInfo.GPSLatitudeRef"); + if (!latRef.isEmpty() && latRef[0] == 'S') + latitude *= -1; + + QByteArray longRef = fetchByteArray(data, "Exif.GPSInfo.GPSLongitudeRef"); + if (!longRef.isEmpty() && longRef[0] == 'W') + longitude *= -1; + + if (!std::isnan(latitude)) { + result->add(Property::PhotoGpsLatitude, latitude); + } - if (!std::isnan(altitude)) { - result->add(Property::PhotoGpsAltitude, altitude); + if (!std::isnan(longitude)) { + result->add(Property::PhotoGpsLongitude, longitude); + } + + if (!std::isnan(altitude)) { + result->add(Property::PhotoGpsAltitude, altitude); + } } } diff --git a/src/extractors/ffmpegextractor.cpp b/src/extractors/ffmpegextractor.cpp --- a/src/extractors/ffmpegextractor.cpp +++ b/src/extractors/ffmpegextractor.cpp @@ -89,93 +89,95 @@ result->addType(Type::Video); - int totalSecs = fmt_ctx->duration / AV_TIME_BASE; - int bitrate = fmt_ctx->bit_rate; + if (result->inputFlags() & ExtractionResult::ExtractMetaData) { + int totalSecs = fmt_ctx->duration / AV_TIME_BASE; + int bitrate = fmt_ctx->bit_rate; - result->add(Property::Duration, totalSecs); - result->add(Property::BitRate, bitrate); + result->add(Property::Duration, totalSecs); + result->add(Property::BitRate, bitrate); - for (uint i = 0; i < fmt_ctx->nb_streams; i++) { - AVStream* stream = fmt_ctx->streams[i]; + for (uint i = 0; i < fmt_ctx->nb_streams; i++) { + AVStream* stream = fmt_ctx->streams[i]; #if defined HAVE_AVSTREAM_CODECPAR && HAVE_AVSTREAM_CODECPAR - const AVCodecParameters* codec = stream->codecpar; + const AVCodecParameters* codec = stream->codecpar; #else - const AVCodecContext* codec = stream->codec; + const AVCodecContext* codec = stream->codec; #endif - if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { - result->add(Property::Width, codec->width); - result->add(Property::Height, codec->height); - - AVRational avSampleAspectRatio = av_guess_sample_aspect_ratio(fmt_ctx, stream, nullptr); - AVRational avDisplayAspectRatio; - av_reduce(&avDisplayAspectRatio.num, &avDisplayAspectRatio.den, - codec->width * avSampleAspectRatio.num, - codec->height * avSampleAspectRatio.den, - 1024*1024); - double displayAspectRatio = avDisplayAspectRatio.num; - if (avDisplayAspectRatio.den) - displayAspectRatio /= avDisplayAspectRatio.den; - if (displayAspectRatio) - result->add(Property::AspectRatio, displayAspectRatio); - - AVRational avFrameRate = av_guess_frame_rate(fmt_ctx, stream, nullptr); - double frameRate = avFrameRate.num; - if (avFrameRate.den) - frameRate /= avFrameRate.den; - if (frameRate) - result->add(Property::FrameRate, frameRate); + if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { + result->add(Property::Width, codec->width); + result->add(Property::Height, codec->height); + + AVRational avSampleAspectRatio = av_guess_sample_aspect_ratio(fmt_ctx, stream, nullptr); + AVRational avDisplayAspectRatio; + av_reduce(&avDisplayAspectRatio.num, &avDisplayAspectRatio.den, + codec->width * avSampleAspectRatio.num, + codec->height * avSampleAspectRatio.den, + 1024*1024); + double displayAspectRatio = avDisplayAspectRatio.num; + if (avDisplayAspectRatio.den) + displayAspectRatio /= avDisplayAspectRatio.den; + if (displayAspectRatio) + result->add(Property::AspectRatio, displayAspectRatio); + + AVRational avFrameRate = av_guess_frame_rate(fmt_ctx, stream, nullptr); + double frameRate = avFrameRate.num; + if (avFrameRate.den) + frameRate /= avFrameRate.den; + if (frameRate) + result->add(Property::FrameRate, frameRate); + } } - } - AVDictionary* dict = fmt_ctx->metadata; - AVDictionaryEntry* entry; + AVDictionary* dict = fmt_ctx->metadata; + AVDictionaryEntry* entry; - entry = av_dict_get(dict, "title", nullptr, 0); - if (entry) { - result->add(Property::Title, QString::fromUtf8(entry->value)); - } + entry = av_dict_get(dict, "title", nullptr, 0); + if (entry) { + result->add(Property::Title, QString::fromUtf8(entry->value)); + } - entry = av_dict_get(dict, "author", nullptr, 0); - if (entry) { - result->add(Property::Author, QString::fromUtf8(entry->value)); - } + entry = av_dict_get(dict, "author", nullptr, 0); + if (entry) { + result->add(Property::Author, QString::fromUtf8(entry->value)); + } - entry = av_dict_get(dict, "copyright", nullptr, 0); - if (entry) { - result->add(Property::Copyright, QString::fromUtf8(entry->value)); - } + entry = av_dict_get(dict, "copyright", nullptr, 0); + if (entry) { + result->add(Property::Copyright, QString::fromUtf8(entry->value)); + } - entry = av_dict_get(dict, "comment", nullptr, 0); - if (entry) { - result->add(Property::Comment, QString::fromUtf8(entry->value)); - } + entry = av_dict_get(dict, "comment", nullptr, 0); + if (entry) { + result->add(Property::Comment, QString::fromUtf8(entry->value)); + } - entry = av_dict_get(dict, "album", nullptr, 0); - if (entry) { - result->add(Property::Album, QString::fromUtf8(entry->value)); - } + entry = av_dict_get(dict, "album", nullptr, 0); + if (entry) { + result->add(Property::Album, QString::fromUtf8(entry->value)); + } - entry = av_dict_get(dict, "genre", nullptr, 0); - if (entry) { - result->add(Property::Genre, QString::fromUtf8(entry->value)); - } + entry = av_dict_get(dict, "genre", nullptr, 0); + if (entry) { + result->add(Property::Genre, QString::fromUtf8(entry->value)); + } - entry = av_dict_get(dict, "track", nullptr, 0); - if (entry) { - QString value = QString::fromUtf8(entry->value); + entry = av_dict_get(dict, "track", nullptr, 0); + if (entry) { + QString value = QString::fromUtf8(entry->value); - bool ok = false; - int track = value.toInt(&ok); - if (ok && track) - result->add(Property::TrackNumber, track); - } + bool ok = false; + int track = value.toInt(&ok); + if (ok && track) + result->add(Property::TrackNumber, track); + } - entry = av_dict_get(dict, "year", nullptr, 0); - if (entry) { - int year = QString::fromUtf8(entry->value).toInt(); - result->add(Property::ReleaseYear, year); + entry = av_dict_get(dict, "year", nullptr, 0); + if (entry) { + int year = QString::fromUtf8(entry->value).toInt(); + result->add(Property::ReleaseYear, year); + } } avformat_close_input(&fmt_ctx); diff --git a/src/extractors/odfextractor.cpp b/src/extractors/odfextractor.cpp --- a/src/extractors/odfextractor.cpp +++ b/src/extractors/odfextractor.cpp @@ -87,61 +87,63 @@ return; } - QDomDocument metaData(QStringLiteral("metaData")); - metaData.setContent(static_cast(metaXml)->data(), true); - - // parse metadata ... - QDomElement meta = firstChildElementNS(firstChildElementNS(metaData, - officeNS(), QStringLiteral("document-meta")), - officeNS(), QStringLiteral("meta")); - - QDomNode n = meta.firstChild(); - while (!n.isNull()) { - QDomElement e = n.toElement(); - if (!e.isNull()) { - const QString namespaceURI = e.namespaceURI(); - const QString localName = e.localName(); - - // Dublin Core - if (namespaceURI == dcNS()) { - if (localName == QLatin1String("description")) { - result->add(Property::Description, e.text()); - } else if (localName == QLatin1String("subject")) { - result->add(Property::Subject, e.text()); - } else if (localName == QLatin1String("title")) { - result->add(Property::Title, e.text()); - } else if (localName == QLatin1String("creator")) { - result->add(Property::Author, e.text()); - } else if (localName == QLatin1String("language")) { - result->add(Property::Language, e.text()); - } - } - // Meta Properties - else if (namespaceURI == metaNS()) { - if (localName == QLatin1String("document-statistic")) { - bool ok = false; - int pageCount = e.attributeNS(metaNS(), QStringLiteral("page-count")).toInt(&ok); - if (ok) { - result->add(Property::PageCount, pageCount); + if (result->inputFlags() & ExtractionResult::ExtractMetaData) { + QDomDocument metaData(QStringLiteral("metaData")); + metaData.setContent(static_cast(metaXml)->data(), true); + + // parse metadata ... + QDomElement meta = firstChildElementNS(firstChildElementNS(metaData, + officeNS(), QStringLiteral("document-meta")), + officeNS(), QStringLiteral("meta")); + + QDomNode n = meta.firstChild(); + while (!n.isNull()) { + QDomElement e = n.toElement(); + if (!e.isNull()) { + const QString namespaceURI = e.namespaceURI(); + const QString localName = e.localName(); + + // Dublin Core + if (namespaceURI == dcNS()) { + if (localName == QLatin1String("description")) { + result->add(Property::Description, e.text()); + } else if (localName == QLatin1String("subject")) { + result->add(Property::Subject, e.text()); + } else if (localName == QLatin1String("title")) { + result->add(Property::Title, e.text()); + } else if (localName == QLatin1String("creator")) { + result->add(Property::Author, e.text()); + } else if (localName == QLatin1String("language")) { + result->add(Property::Language, e.text()); } - - int wordCount = e.attributeNS(metaNS(), QStringLiteral("word-count")).toInt(&ok); - if (ok) { - result->add(Property::WordCount, wordCount); + } + // Meta Properties + else if (namespaceURI == metaNS()) { + if (localName == QLatin1String("document-statistic")) { + bool ok = false; + int pageCount = e.attributeNS(metaNS(), QStringLiteral("page-count")).toInt(&ok); + if (ok) { + result->add(Property::PageCount, pageCount); + } + + int wordCount = e.attributeNS(metaNS(), QStringLiteral("word-count")).toInt(&ok); + if (ok) { + result->add(Property::WordCount, wordCount); + } + } else if (localName == QLatin1String("keyword")) { + QString keywords = e.text(); + result->add(Property::Keywords, keywords); + } else if (localName == QLatin1String("generator")) { + result->add(Property::Generator, e.text()); + } else if (localName == QLatin1String("creation-date")) { + QDateTime dt = ExtractorPlugin::dateTimeFromString(e.text()); + if (!dt.isNull()) + result->add(Property::CreationDate, dt); } - } else if (localName == QLatin1String("keyword")) { - QString keywords = e.text(); - result->add(Property::Keywords, keywords); - } else if (localName == QLatin1String("generator")) { - result->add(Property::Generator, e.text()); - } else if (localName == QLatin1String("creation-date")) { - QDateTime dt = ExtractorPlugin::dateTimeFromString(e.text()); - if (!dt.isNull()) - result->add(Property::CreationDate, dt); } } + n = n.nextSibling(); } - n = n.nextSibling(); } result->addType(Type::Document); diff --git a/src/extractors/office2007extractor.cpp b/src/extractors/office2007extractor.cpp --- a/src/extractors/office2007extractor.cpp +++ b/src/extractors/office2007extractor.cpp @@ -74,7 +74,9 @@ const KArchiveDirectory* docPropDirectory = dynamic_cast(docPropEntry); const QStringList docPropsEntries = docPropDirectory->entries(); - if (docPropsEntries.contains(QStringLiteral("core.xml"))) { + + + if (docPropsEntries.contains(QStringLiteral("core.xml")) && result->inputFlags() & ExtractionResult::ExtractMetaData) { QDomDocument coreDoc(QStringLiteral("core")); const KArchiveFile* file = static_cast(docPropDirectory->entry(QStringLiteral("core.xml"))); coreDoc.setContent(file->data()); @@ -139,7 +141,7 @@ } } - if (docPropsEntries.contains(QStringLiteral("app.xml"))) { + if (docPropsEntries.contains(QStringLiteral("app.xml")) && result->inputFlags() & ExtractionResult::ExtractMetaData) { QDomDocument appDoc(QStringLiteral("app")); const KArchiveFile* file = static_cast(docPropDirectory->entry(QStringLiteral("app.xml"))); appDoc.setContent(file->data()); diff --git a/src/extractors/plaintextextractor.cpp b/src/extractors/plaintextextractor.cpp --- a/src/extractors/plaintextextractor.cpp +++ b/src/extractors/plaintextextractor.cpp @@ -98,8 +98,9 @@ lines += 1; } - - result->add(Property::LineCount, lines); + if (result->inputFlags() & ExtractionResult::ExtractMetaData) { + result->add(Property::LineCount, lines); + } free(line); close(fd); diff --git a/src/extractors/popplerextractor.cpp b/src/extractors/popplerextractor.cpp --- a/src/extractors/popplerextractor.cpp +++ b/src/extractors/popplerextractor.cpp @@ -52,31 +52,33 @@ result->addType(Type::Document); - QString title = pdfDoc->info(QStringLiteral("Title")).trimmed(); + if (result->inputFlags() & ExtractionResult::ExtractMetaData) { + QString title = pdfDoc->info(QStringLiteral("Title")).trimmed(); - if (!title.isEmpty()) { - result->add(Property::Title, title); - } + if (!title.isEmpty()) { + result->add(Property::Title, title); + } - QString subject = pdfDoc->info(QStringLiteral("Subject")); - if (!subject.isEmpty()) { - result->add(Property::Subject, subject); - } + QString subject = pdfDoc->info(QStringLiteral("Subject")); + if (!subject.isEmpty()) { + result->add(Property::Subject, subject); + } - QString author = pdfDoc->info(QStringLiteral("Author")); - if (!author.isEmpty()) { - result->add(Property::Author, author); - } + QString author = pdfDoc->info(QStringLiteral("Author")); + if (!author.isEmpty()) { + result->add(Property::Author, author); + } - QString generator = pdfDoc->info(QStringLiteral("Producer")); - if (!generator.isEmpty()) { - result->add(Property::Generator, generator); - } + QString generator = pdfDoc->info(QStringLiteral("Producer")); + if (!generator.isEmpty()) { + result->add(Property::Generator, generator); + } - QString creationDate = pdfDoc->info(QStringLiteral("CreationDate")); - if (!creationDate.isEmpty()) { - QByteArray utf8 = creationDate.toUtf8(); - result->add(Property::CreationDate, Poppler::convertDate(utf8.data())); + QString creationDate = pdfDoc->info(QStringLiteral("CreationDate")); + if (!creationDate.isEmpty()) { + QByteArray utf8 = creationDate.toUtf8(); + result->add(Property::CreationDate, Poppler::convertDate(utf8.data())); + } } if (!(result->inputFlags() & ExtractionResult::ExtractPlainText)) { diff --git a/src/extractors/postscriptdscextractor.cpp b/src/extractors/postscriptdscextractor.cpp --- a/src/extractors/postscriptdscextractor.cpp +++ b/src/extractors/postscriptdscextractor.cpp @@ -42,11 +42,6 @@ void DscExtractor::extract(ExtractionResult* result) { - auto flags = result->inputFlags(); - if (!(flags & ExtractionResult::ExtractMetaData)) { - return; - } - QFile file(result->inputUrl()); if (!file.open(QIODevice::ReadOnly)) { qCWarning(KFILEMETADATA_LOG) << "Document is not a valid file"; @@ -60,6 +55,9 @@ result->addType(Type::Image); } + if (!(result->inputFlags() & ExtractionResult::ExtractMetaData)) { + return; + } // Try to find some DSC (PostScript Language Document Structuring Conventions) conforming data QTextStream stream(&file); QString line; diff --git a/src/extractors/taglibextractor.cpp b/src/extractors/taglibextractor.cpp --- a/src/extractors/taglibextractor.cpp +++ b/src/extractors/taglibextractor.cpp @@ -74,7 +74,7 @@ void extractAudioProperties(TagLib::File* file, ExtractionResult* result) { TagLib::AudioProperties* audioProp = file->audioProperties(); - if (audioProp) { + if (audioProp && result->inputFlags() & ExtractionResult::ExtractMetaData) { if (audioProp->length()) { // What about the xml duration? result->add(Property::Duration, audioProp->length()); @@ -99,155 +99,158 @@ if (savedProperties.isEmpty()) { return; } - if (savedProperties.contains("TITLE")) { - result->add(Property::Title, TStringToQString(savedProperties["TITLE"].toString()).trimmed()); - } - if (savedProperties.contains("ALBUM")) { - result->add(Property::Album, TStringToQString(savedProperties["ALBUM"].toString()).trimmed()); - } - if (savedProperties.contains("COMMENT")) { - result->add(Property::Comment, TStringToQString(savedProperties["COMMENT"].toString()).trimmed()); - } - if (savedProperties.contains("TRACKNUMBER")) { - result->add(Property::TrackNumber, savedProperties["TRACKNUMBER"].toString().toInt()); - } - if (savedProperties.contains("DATE")) { - result->add(Property::ReleaseYear, savedProperties["DATE"].toString().toInt()); - } - if (savedProperties.contains("OPUS")) { - result->add(Property::Opus, savedProperties["OPUS"].toString().toInt()); - } - if (savedProperties.contains("DISCNUMBER")) { - result->add(Property::DiscNumber, savedProperties["DISCNUMBER"].toString().toInt()); - } - if (savedProperties.contains("RATING")) { - /* + + if (result->inputFlags() & ExtractionResult::ExtractMetaData) { + if (savedProperties.contains("TITLE")) { + result->add(Property::Title, TStringToQString(savedProperties["TITLE"].toString()).trimmed()); + } + if (savedProperties.contains("ALBUM")) { + result->add(Property::Album, TStringToQString(savedProperties["ALBUM"].toString()).trimmed()); + } + if (savedProperties.contains("COMMENT")) { + result->add(Property::Comment, TStringToQString(savedProperties["COMMENT"].toString()).trimmed()); + } + if (savedProperties.contains("TRACKNUMBER")) { + result->add(Property::TrackNumber, savedProperties["TRACKNUMBER"].toString().toInt()); + } + if (savedProperties.contains("DATE")) { + result->add(Property::ReleaseYear, savedProperties["DATE"].toString().toInt()); + } + if (savedProperties.contains("OPUS")) { + result->add(Property::Opus, savedProperties["OPUS"].toString().toInt()); + } + if (savedProperties.contains("DISCNUMBER")) { + result->add(Property::DiscNumber, savedProperties["DISCNUMBER"].toString().toInt()); + } + if (savedProperties.contains("RATING")) { + /* * There is no standard regarding ratings. Mimic MediaMonkey's behavior * with a range of 0 to 100 (stored in steps of 10) and make it compatible * with baloo rating with a range from 0 to 10 */ - result->add(Property::Rating, savedProperties["RATING"].toString().toInt() / 10); - } - if (savedProperties.contains("LOCATION")) { - result->add(Property::Location, TStringToQString(savedProperties["LOCATION"].toString()).trimmed()); - } - if (savedProperties.contains("LANGUAGE")) { - result->add(Property::Language, TStringToQString(savedProperties["LANGUAGE"].toString()).trimmed()); - } - if (savedProperties.contains("LICENSE")) { - result->add(Property::License, TStringToQString(savedProperties["LICENSE"].toString()).trimmed()); - } - if (savedProperties.contains("PUBLISHER")) { - result->add(Property::Publisher, TStringToQString(savedProperties["PUBLISHER"].toString()).trimmed()); - } - if (savedProperties.contains("COPYRIGHT")) { - result->add(Property::Copyright, TStringToQString(savedProperties["COPYRIGHT"].toString()).trimmed()); - } - if (savedProperties.contains("LABEL")) { - result->add(Property::Label, TStringToQString(savedProperties["LABEL"].toString()).trimmed()); - } - if (savedProperties.contains("ENSEMBLE")) { - result->add(Property::Ensemble, TStringToQString(savedProperties["ENSEMBLE"].toString()).trimmed()); - } - if (savedProperties.contains("COMPILATION")) { - result->add(Property::Compilation, TStringToQString(savedProperties["COMPILATION"].toString()).trimmed()); - } - if (savedProperties.contains("LYRICS")) { - result->add(Property::Lyrics, TStringToQString(savedProperties["LYRICS"].toString()).trimmed()); - } - if (savedProperties.contains("ARTIST")) { - const auto artists = savedProperties["ARTIST"]; - for (const auto& artist : artists) { - result->add(Property::Artist, TStringToQString(artist).trimmed()); + result->add(Property::Rating, savedProperties["RATING"].toString().toInt() / 10); } - } - if (savedProperties.contains("GENRE")) { - const auto genres = savedProperties["GENRE"]; - for (const auto& genre : genres) { - result->add(Property::Genre, TStringToQString(genre).trimmed()); + if (savedProperties.contains("LOCATION")) { + result->add(Property::Location, TStringToQString(savedProperties["LOCATION"].toString()).trimmed()); } - } - if (savedProperties.contains("ALBUMARTIST")) { - const auto albumArtists = savedProperties["ALBUMARTIST"]; - for (const auto& albumArtist : albumArtists) { - result->add(Property::AlbumArtist, TStringToQString(albumArtist).trimmed()); + if (savedProperties.contains("LANGUAGE")) { + result->add(Property::Language, TStringToQString(savedProperties["LANGUAGE"].toString()).trimmed()); } - } - if (savedProperties.contains("COMPOSER")) { - const auto composers = savedProperties["COMPOSER"]; - for (const auto& composer : composers) { - result->add(Property::Composer, TStringToQString(composer).trimmed()); + if (savedProperties.contains("LICENSE")) { + result->add(Property::License, TStringToQString(savedProperties["LICENSE"].toString()).trimmed()); } - } - if (savedProperties.contains("LYRICIST")) { - const auto lyricists = savedProperties["LYRICIST"]; - for (const auto& lyricist : lyricists) { - result->add(Property::Lyricist, TStringToQString(lyricist).trimmed()); + if (savedProperties.contains("PUBLISHER")) { + result->add(Property::Publisher, TStringToQString(savedProperties["PUBLISHER"].toString()).trimmed()); } - } - if (savedProperties.contains("CONDUCTOR")) { - const auto conductors = savedProperties["CONDUCTOR"]; - for (const auto& conductor : conductors) { - result->add(Property::Conductor, TStringToQString(conductor).trimmed()); + if (savedProperties.contains("COPYRIGHT")) { + result->add(Property::Copyright, TStringToQString(savedProperties["COPYRIGHT"].toString()).trimmed()); } - } - if (savedProperties.contains("ARRANGER")) { - const auto arrangers = savedProperties["ARRANGER"]; - for (const auto& arranger : arrangers) { - result->add(Property::Arranger, TStringToQString(arranger).trimmed()); + if (savedProperties.contains("LABEL")) { + result->add(Property::Label, TStringToQString(savedProperties["LABEL"].toString()).trimmed()); } - } - if (savedProperties.contains("PERFORMER")) { - const auto performers = savedProperties["PERFORMER"]; - for (const auto& performer : performers) { - result->add(Property::Performer, TStringToQString(performer).trimmed()); + if (savedProperties.contains("ENSEMBLE")) { + result->add(Property::Ensemble, TStringToQString(savedProperties["ENSEMBLE"].toString()).trimmed()); } - } - if (savedProperties.contains("AUTHOR")) { - const auto authors = savedProperties["AUTHOR"]; - for (const auto& author: authors) { - result->add(Property::Author, TStringToQString(author).trimmed()); + if (savedProperties.contains("COMPILATION")) { + result->add(Property::Compilation, TStringToQString(savedProperties["COMPILATION"].toString()).trimmed()); } - } - - if (savedProperties.contains("REPLAYGAIN_TRACK_GAIN")) { - auto trackGainString = TStringToQString(savedProperties["REPLAYGAIN_TRACK_GAIN"].toString(";")).trimmed(); - // remove " dB" suffix - if (trackGainString.endsWith(QStringLiteral(" dB"), Qt::CaseInsensitive)) { - trackGainString.chop(3); + if (savedProperties.contains("LYRICS")) { + result->add(Property::Lyrics, TStringToQString(savedProperties["LYRICS"].toString()).trimmed()); } - bool success = false; - double replayGainTrackGain = trackGainString.toDouble(&success); - if (success) { - result->add(Property::ReplayGainTrackGain, replayGainTrackGain); + if (savedProperties.contains("ARTIST")) { + const auto artists = savedProperties["ARTIST"]; + for (const auto& artist : artists) { + result->add(Property::Artist, TStringToQString(artist).trimmed()); + } } - } - if (savedProperties.contains("REPLAYGAIN_ALBUM_GAIN")) { - auto albumGainString = TStringToQString(savedProperties["REPLAYGAIN_ALBUM_GAIN"].toString(";")).trimmed(); - // remove " dB" suffix - if (albumGainString.endsWith(QStringLiteral(" dB"), Qt::CaseInsensitive)) { - albumGainString.chop(3); + if (savedProperties.contains("GENRE")) { + const auto genres = savedProperties["GENRE"]; + for (const auto& genre : genres) { + result->add(Property::Genre, TStringToQString(genre).trimmed()); + } } - bool success = false; - double replayGainAlbumGain = albumGainString.toDouble(&success); - if (success) { - result->add(Property::ReplayGainAlbumGain, replayGainAlbumGain); + if (savedProperties.contains("ALBUMARTIST")) { + const auto albumArtists = savedProperties["ALBUMARTIST"]; + for (const auto& albumArtist : albumArtists) { + result->add(Property::AlbumArtist, TStringToQString(albumArtist).trimmed()); + } } - } - if (savedProperties.contains("REPLAYGAIN_TRACK_PEAK")) { - auto trackPeakString = TStringToQString(savedProperties["REPLAYGAIN_TRACK_PEAK"].toString(";")).trimmed(); - bool success = false; - double replayGainTrackPeak = trackPeakString.toDouble(&success); - if (success) { - result->add(Property::ReplayGainTrackPeak, replayGainTrackPeak); + if (savedProperties.contains("COMPOSER")) { + const auto composers = savedProperties["COMPOSER"]; + for (const auto& composer : composers) { + result->add(Property::Composer, TStringToQString(composer).trimmed()); + } } - } - if (savedProperties.contains("REPLAYGAIN_ALBUM_PEAK")) { - auto albumPeakString = TStringToQString(savedProperties["REPLAYGAIN_ALBUM_PEAK"].toString(";")).trimmed(); - bool success = false; - double replayGainAlbumPeak = albumPeakString.toDouble(&success); - if (success) { - result->add(Property::ReplayGainAlbumPeak, replayGainAlbumPeak); + if (savedProperties.contains("LYRICIST")) { + const auto lyricists = savedProperties["LYRICIST"]; + for (const auto& lyricist : lyricists) { + result->add(Property::Lyricist, TStringToQString(lyricist).trimmed()); + } + } + if (savedProperties.contains("CONDUCTOR")) { + const auto conductors = savedProperties["CONDUCTOR"]; + for (const auto& conductor : conductors) { + result->add(Property::Conductor, TStringToQString(conductor).trimmed()); + } + } + if (savedProperties.contains("ARRANGER")) { + const auto arrangers = savedProperties["ARRANGER"]; + for (const auto& arranger : arrangers) { + result->add(Property::Arranger, TStringToQString(arranger).trimmed()); + } + } + if (savedProperties.contains("PERFORMER")) { + const auto performers = savedProperties["PERFORMER"]; + for (const auto& performer : performers) { + result->add(Property::Performer, TStringToQString(performer).trimmed()); + } + } + if (savedProperties.contains("AUTHOR")) { + const auto authors = savedProperties["AUTHOR"]; + for (const auto& author: authors) { + result->add(Property::Author, TStringToQString(author).trimmed()); + } + } + + if (savedProperties.contains("REPLAYGAIN_TRACK_GAIN")) { + auto trackGainString = TStringToQString(savedProperties["REPLAYGAIN_TRACK_GAIN"].toString(";")).trimmed(); + // remove " dB" suffix + if (trackGainString.endsWith(QStringLiteral(" dB"), Qt::CaseInsensitive)) { + trackGainString.chop(3); + } + bool success = false; + double replayGainTrackGain = trackGainString.toDouble(&success); + if (success) { + result->add(Property::ReplayGainTrackGain, replayGainTrackGain); + } + } + if (savedProperties.contains("REPLAYGAIN_ALBUM_GAIN")) { + auto albumGainString = TStringToQString(savedProperties["REPLAYGAIN_ALBUM_GAIN"].toString(";")).trimmed(); + // remove " dB" suffix + if (albumGainString.endsWith(QStringLiteral(" dB"), Qt::CaseInsensitive)) { + albumGainString.chop(3); + } + bool success = false; + double replayGainAlbumGain = albumGainString.toDouble(&success); + if (success) { + result->add(Property::ReplayGainAlbumGain, replayGainAlbumGain); + } + } + if (savedProperties.contains("REPLAYGAIN_TRACK_PEAK")) { + auto trackPeakString = TStringToQString(savedProperties["REPLAYGAIN_TRACK_PEAK"].toString(";")).trimmed(); + bool success = false; + double replayGainTrackPeak = trackPeakString.toDouble(&success); + if (success) { + result->add(Property::ReplayGainTrackPeak, replayGainTrackPeak); + } + } + if (savedProperties.contains("REPLAYGAIN_ALBUM_PEAK")) { + auto albumPeakString = TStringToQString(savedProperties["REPLAYGAIN_ALBUM_PEAK"].toString(";")).trimmed(); + bool success = false; + double replayGainAlbumPeak = albumPeakString.toDouble(&success); + if (success) { + result->add(Property::ReplayGainAlbumPeak, replayGainAlbumPeak); + } } } } @@ -257,65 +260,71 @@ if (Id3Tags->isEmpty()) { return; } - TagLib::ID3v2::FrameList lstID3v2; - /* + if (result->inputFlags() & ExtractionResult::ExtractMetaData) { + TagLib::ID3v2::FrameList lstID3v2; + + /* * Publisher. * Special handling because TagLib::PropertyMap maps "TPUB" to "LABEL" * Insert manually for Publisher. */ - lstID3v2 = Id3Tags->frameListMap()["TPUB"]; - if (!lstID3v2.isEmpty()) { - result->add(Property::Publisher, TStringToQString(lstID3v2.front()->toString())); - } + lstID3v2 = Id3Tags->frameListMap()["TPUB"]; + if (!lstID3v2.isEmpty()) { + result->add(Property::Publisher, TStringToQString(lstID3v2.front()->toString())); + } - // Compilation. - lstID3v2 = Id3Tags->frameListMap()["TCMP"]; - if (!lstID3v2.isEmpty()) { - result->add(Property::Compilation, TStringToQString(lstID3v2.front()->toString())); - } + // Compilation. + lstID3v2 = Id3Tags->frameListMap()["TCMP"]; + if (!lstID3v2.isEmpty()) { + result->add(Property::Compilation, TStringToQString(lstID3v2.front()->toString())); + } - /* + /* * Rating. * There is no standard regarding ratings. Most of the implementations match * a 5 stars rating to a range of 0-255 for MP3. * Map it to baloo rating with a range of 0 - 10. */ - lstID3v2 = Id3Tags->frameListMap()["POPM"]; - if (!lstID3v2.isEmpty()) { - TagLib::ID3v2::PopularimeterFrame *ratingFrame = static_cast(lstID3v2.front()); - int rating = ratingFrame->rating(); - if (rating == 0) { - rating = 0; - } else if (rating == 1) { - TagLib::String ratingProvider = ratingFrame->email(); - if (ratingProvider == "no@email" || ratingProvider == "org.kde.kfilemetadata") { - rating = 1; - } else { - rating = 2; + lstID3v2 = Id3Tags->frameListMap()["POPM"]; + if (!lstID3v2.isEmpty()) { + TagLib::ID3v2::PopularimeterFrame *ratingFrame = static_cast(lstID3v2.front()); + int rating = ratingFrame->rating(); + if (rating == 0) { + rating = 0; + } else if (rating == 1) { + TagLib::String ratingProvider = ratingFrame->email(); + if (ratingProvider == "no@email" || ratingProvider == "org.kde.kfilemetadata") { + rating = 1; + } else { + rating = 2; + } + } else if (rating >= 1 && rating <= 255) { + rating = static_cast(0.032 * rating + 2); } - } else if (rating >= 1 && rating <= 255) { - rating = static_cast(0.032 * rating + 2); + result->add(Property::Rating, rating); } - result->add(Property::Rating, rating); } } void extractMp4Tags(TagLib::MP4::Tag* mp4Tags, ExtractionResult* result) { if (mp4Tags->isEmpty()) { return; } - TagLib::MP4::ItemListMap allTags = mp4Tags->itemListMap(); - /* + if (result->inputFlags() & ExtractionResult::ExtractMetaData) { + TagLib::MP4::ItemListMap allTags = mp4Tags->itemListMap(); + + /* * There is no standard regarding ratings. Mimic MediaMonkey's behavior * with a range of 0 to 100 (stored in steps of 10) and make it compatible * with baloo rating with a range from 0 to 10. */ - TagLib::MP4::ItemListMap::Iterator itRating = allTags.find("rate"); - if (itRating != allTags.end()) { - result->add(Property::Rating, itRating->second.toStringList().toString().toInt() / 10); + TagLib::MP4::ItemListMap::Iterator itRating = allTags.find("rate"); + if (itRating != allTags.end()) { + result->add(Property::Rating, itRating->second.toStringList().toString().toInt() / 10); + } } } @@ -325,44 +334,46 @@ return; } - TagLib::ASF::AttributeList lstASF = asfTags->attribute("WM/SharedUserRating"); - if (!lstASF.isEmpty()) { - int rating = lstASF.front().toString().toInt(); - /* + if (result->inputFlags() & ExtractionResult::ExtractMetaData) { + TagLib::ASF::AttributeList lstASF = asfTags->attribute("WM/SharedUserRating"); + if (!lstASF.isEmpty()) { + int rating = lstASF.front().toString().toInt(); + /* * Map the rating values of WMP to Baloo rating. * 0->0, 1->2, 25->4, 50->6, 75->8, 99->10 */ - if (rating == 0) { - rating = 0; - } else if (rating == 1) { - rating = 2; - } else { - rating = static_cast(0.09 * rating + 2); - } - result->add(Property::Rating, rating); - } + if (rating == 0) { + rating = 0; + } else if (rating == 1) { + rating = 2; + } else { + rating = static_cast(0.09 * rating + 2); + } + result->add(Property::Rating, rating); + } - lstASF = asfTags->attribute("Author"); - if (!lstASF.isEmpty()) { - const auto attribute = lstASF.front(); - result->add(Property::Author, TStringToQString(attribute.toString()).trimmed()); - } + lstASF = asfTags->attribute("Author"); + if (!lstASF.isEmpty()) { + const auto attribute = lstASF.front(); + result->add(Property::Author, TStringToQString(attribute.toString()).trimmed()); + } - // Lyricist is called "WRITER" for wma/asf files - lstASF = asfTags->attribute("WM/Writer"); - if (!lstASF.isEmpty()) { - const auto attribute = lstASF.front(); - result->add(Property::Lyricist, TStringToQString(attribute.toString()).trimmed()); - } + // Lyricist is called "WRITER" for wma/asf files + lstASF = asfTags->attribute("WM/Writer"); + if (!lstASF.isEmpty()) { + const auto attribute = lstASF.front(); + result->add(Property::Lyricist, TStringToQString(attribute.toString()).trimmed()); + } - /* + /* * TagLib exports "WM/PUBLISHER" as "LABEL" in the PropertyMap, * add it manually to Publisher. */ - lstASF = asfTags->attribute("WM/Publisher"); - if (!lstASF.isEmpty()) { - const auto attribute = lstASF.front(); - result->add(Property::Publisher, TStringToQString(attribute.toString()).trimmed()); + lstASF = asfTags->attribute("WM/Publisher"); + if (!lstASF.isEmpty()) { + const auto attribute = lstASF.front(); + result->add(Property::Publisher, TStringToQString(attribute.toString()).trimmed()); + } } } diff --git a/src/extractors/xmlextractor.cpp b/src/extractors/xmlextractor.cpp --- a/src/extractors/xmlextractor.cpp +++ b/src/extractors/xmlextractor.cpp @@ -111,7 +111,9 @@ continue; } - DublinCoreExtractor::extract(result, cc); + if (result->inputFlags() & ExtractionResult::ExtractMetaData) { + DublinCoreExtractor::extract(result, cc); + } } else if (e.localName() == QLatin1String("defs")) { // skip