File indexing completed on 2025-01-19 03:57:48
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2013-11-28 0007 * Description : a command line tool to check ExifTool with multicore. 0008 * 0009 * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 // Qt includes 0016 0017 #include <QFile> 0018 #include <QFileInfo> 0019 #include <QString> 0020 #include <QStringList> 0021 #include <QTextStream> 0022 #include <QCoreApplication> 0023 #include <QVariant> 0024 #include <QObject> 0025 #include <QtConcurrent> // krazy:exclude=includes 0026 0027 // Local includes 0028 0029 #include "digikam_debug.h" 0030 #include "digikam_globals.h" 0031 #include "exiftoolparser.h" 0032 0033 using namespace Digikam; 0034 0035 bool s_exifToolParseThreaded(const QString& file) 0036 { 0037 QScopedPointer<ExifToolParser> const parser(new ExifToolParser(nullptr)); 0038 0039 // Read metadata from the file. Start ExifToolParser 0040 0041 if (!parser->load(file)) 0042 { 0043 qCWarning(DIGIKAM_TESTS_LOG) << "Cannot process" << file; 0044 0045 return false; 0046 } 0047 0048 QString path = parser->currentPath(); 0049 ExifToolParser::ExifToolData parsed = parser->currentData(); 0050 0051 qCDebug(DIGIKAM_TESTS_LOG).noquote() << "Processing source file:" << path; 0052 0053 // Print returned and sorted tags. 0054 0055 QFileInfo fi(file); 0056 QFile output(QString::fromLatin1("%1-exiftool.txt").arg(fi.fileName())); 0057 0058 if (!output.open(QIODevice::WriteOnly)) 0059 { 0060 qCDebug(DIGIKAM_TESTS_LOG) << "Cannot open ExifTool output file to write..."; 0061 0062 return false; 0063 } 0064 0065 QTextStream stream(&output); 0066 QStringList tagsLst; 0067 0068 const int section1 = -40; // ExifTool Tag name simplified 0069 const int section2 = -30; // Tag value as string. 0070 QString sep = QString().fill(QLatin1Char('-'), qAbs(section1 + section2) + 4); 0071 0072 // Header 0073 0074 stream << sep 0075 << QT_ENDL 0076 << QString::fromLatin1("%1").arg(QLatin1String("ExifTool::group0.name"), section1) << " | " 0077 << QString::fromLatin1("%1").arg(QLatin1String("String Value"), section2) 0078 << QT_ENDL 0079 << sep 0080 << QT_ENDL; 0081 0082 for (ExifToolParser::ExifToolData::const_iterator it = parsed.constBegin() ; 0083 it != parsed.constEnd() ; ++it) 0084 { 0085 QString tagNameExifTool = it.key().section(QLatin1Char('.'), 0, 0) + 0086 QLatin1Char('.') + 0087 it.key().section(QLatin1Char('.'), -1); 0088 QString tagType = it.value()[1].toString(); 0089 QString data = it.value()[0].toString(); 0090 0091 if (data.size() > -section2) 0092 { 0093 data = data.left(-section2 - 3) + QLatin1String("..."); 0094 } 0095 0096 tagsLst 0097 << QString::fromLatin1("%1 | %2") 0098 .arg(tagNameExifTool, section1) 0099 .arg(data, section2) 0100 ; 0101 } 0102 0103 tagsLst.sort(); 0104 0105 Q_FOREACH (const QString& tag, tagsLst) 0106 { 0107 stream << tag << QT_ENDL; 0108 } 0109 0110 stream << sep << QT_ENDL; 0111 0112 output.close(); 0113 0114 qCDebug(DIGIKAM_TESTS_LOG).noquote() << "Processed source file:" << path; 0115 0116 return true; 0117 } 0118 0119 int main(int argc, char** argv) 0120 { 0121 QCoreApplication app(argc, argv); 0122 0123 if (argc != 2) 0124 { 0125 qCDebug(DIGIKAM_TESTS_LOG) << "exiftooloutpu_cli - CLI tool to check ExifTool with multicore"; 0126 qCDebug(DIGIKAM_TESTS_LOG) << "Usage: <dir>"; 0127 0128 return -1; 0129 } 0130 0131 QDir imageDir(QString::fromUtf8(argv[1])); 0132 imageDir.setNameFilters(QStringList() << QLatin1String("*.jpg")); 0133 QStringList imageFiles = imageDir.entryList(); 0134 0135 qCDebug(DIGIKAM_TESTS_LOG) << "ExifTool parsing images:" << imageFiles; 0136 0137 QList <QFuture<bool> > tasks; 0138 0139 Q_FOREACH (const QString& imageFile, imageFiles) 0140 { 0141 tasks.append(QtConcurrent::run( 0142 &s_exifToolParseThreaded, 0143 imageDir.path() + QLatin1Char('/') + imageFile 0144 ) 0145 ); 0146 } 0147 0148 bool result = false; 0149 0150 Q_FOREACH (QFuture<bool> t, tasks) 0151 { 0152 t.waitForFinished(); 0153 result |= t.result(); 0154 } 0155 0156 qCDebug(DIGIKAM_TESTS_LOG) << "ExifTool parsing completed:" << result; 0157 0158 return 0; 0159 }