File indexing completed on 2024-11-10 07:17:19

0001 /*
0002     SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "extractorutil_p.h"
0008 
0009 #include <QCommandLineParser>
0010 #include <QCoreApplication>
0011 #include <QDataStream>
0012 #include <QFile>
0013 #include <QMimeDatabase>
0014 
0015 #include <KFileMetaData/Extractor>
0016 #include <KFileMetaData/ExtractorCollection>
0017 #include <KFileMetaData/MimeUtils>
0018 #include <KFileMetaData/SimpleExtractionResult>
0019 
0020 #include <iostream>
0021 
0022 int main(int argc, char **argv)
0023 {
0024     QCoreApplication app(argc, argv);
0025 
0026     QCommandLineParser parser;
0027     parser.addPositionalArgument(QLatin1String("url"), QString());
0028     parser.process(app);
0029 
0030     if (parser.positionalArguments().size() != 1) {
0031         parser.showHelp(1);
0032     }
0033 
0034     const QString url = parser.positionalArguments().constFirst();
0035     const QString mimetype = KFileMetaData::MimeUtils::strictMimeType(url, QMimeDatabase()).name();
0036 
0037     KFileMetaData::SimpleExtractionResult result(url, mimetype, KFileMetaData::ExtractionResult::ExtractMetaData);
0038     KFileMetaData::ExtractorCollection collection;
0039 
0040     const QList<KFileMetaData::Extractor *> exList = collection.fetchExtractors(mimetype);
0041 
0042     for (KFileMetaData::Extractor *ex : exList) {
0043         ex->extract(&result);
0044     }
0045 
0046     QFile out;
0047     out.open(stdout, QIODevice::WriteOnly);
0048     QDataStream stream(&out);
0049 
0050     stream << result.properties();
0051 
0052     return 0;
0053 }