diff --git a/autotests/extractortest.cpp b/autotests/extractortest.cpp index 09d4799..99072bf 100644 --- a/autotests/extractortest.cpp +++ b/autotests/extractortest.cpp @@ -1,62 +1,62 @@ /* * This file is part of the KDE Baloo Project * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "extractortest.h" #include #include #include #include #include #include #include #include #include void ExtractorTest::test() { QString fileUrl = QFINDTESTDATA("samplefiles/test.mp3"); QString exe = QStandardPaths::findExecutable(QLatin1String("baloo_filemetadata_temp_extractor")); QStringList args; args << fileUrl; QProcess process; process.start(exe, args); QVERIFY(process.waitForFinished(10000)); QCOMPARE(process.exitStatus(), QProcess::NormalExit); qDebug() << process.readAllStandardError(); - QByteArray bytearray = QByteArray::fromBase64(process.readAllStandardOutput()); + QByteArray bytearray = process.readAllStandardOutput(); QVariantMap data; QDataStream in(&bytearray, QIODevice::ReadOnly); in >> data; QCOMPARE(data.value(QLatin1String("channels")).toInt(), 2); QCOMPARE(data.value(QLatin1String("sampleRate")).toInt(), 44100); if (data.size() == 3) { QCOMPARE(data.value(QLatin1String("bitRate")).toInt(), 255000); } else { QCOMPARE(data.size(), 2); } } QTEST_MAIN(ExtractorTest) diff --git a/src/extractor.cpp b/src/extractor.cpp index 1d6e701..2c1933d 100644 --- a/src/extractor.cpp +++ b/src/extractor.cpp @@ -1,93 +1,94 @@ /* * This file is part of the KDE Baloo Project * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #include #include #include #include #include +#include #include #include #include #include #include #include int main(int argc, char **argv) { QCoreApplication app(argc, argv); QCommandLineParser parser; parser.addPositionalArgument(QLatin1String("url"), QString()); parser.process(app); if (parser.positionalArguments().size() != 1) { parser.showHelp(1); } const QString url = parser.positionalArguments().first(); const QString mimetype = QMimeDatabase().mimeTypeForFile(url, QMimeDatabase::MatchContent).name(); KFileMetaData::SimpleExtractionResult result(url, mimetype, KFileMetaData::ExtractionResult::ExtractMetaData); KFileMetaData::ExtractorCollection collection; QList exList = collection.fetchExtractors(mimetype); Q_FOREACH (KFileMetaData::Extractor *ex, exList) { ex->extract(&result); } - QByteArray arr; - QDataStream stream(&arr, QIODevice::WriteOnly); + QFile out; + out.open(stdout, QIODevice::WriteOnly); + QDataStream stream(&out); QVariantMap map; QMapIterator it(result.properties()); while (it.hasNext()) { it.next(); KFileMetaData::PropertyInfo pi(it.key()); map.insertMulti(pi.name(), it.value()); } KFileMetaData::UserMetaData md(url); QStringList tags = md.tags(); if (!tags.isEmpty()) { map.insert("tags", tags); } int rating = md.rating(); if (rating) { map.insert("rating", rating); } QString comment = md.userComment(); if (!comment.isEmpty()) { map.insert("userComment", comment); } stream << map; qDebug() << map; - std::cout << arr.toBase64().constData(); return 0; } diff --git a/src/indexeddataretriever.cpp b/src/indexeddataretriever.cpp index cd4603e..d71efe9 100644 --- a/src/indexeddataretriever.cpp +++ b/src/indexeddataretriever.cpp @@ -1,63 +1,63 @@ /* * * Copyright (C) 2012 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "indexeddataretriever.h" #include #include #include #include #include using namespace Baloo; IndexedDataRetriever::IndexedDataRetriever(const QString& fileUrl, QObject* parent): KJob(parent) { m_url = QFileInfo(fileUrl).canonicalFilePath(); } IndexedDataRetriever::~IndexedDataRetriever() { } void IndexedDataRetriever::start() { const QString exe = QStandardPaths::findExecutable(QLatin1String("baloo_filemetadata_temp_extractor")); m_process = new QProcess(this); m_process->setReadChannel(QProcess::StandardOutput); connect(m_process, static_cast(&QProcess::finished), this, &IndexedDataRetriever::slotIndexedFile); m_process->start(exe, QStringList() << m_url); } void IndexedDataRetriever::slotIndexedFile(int) { - QByteArray data = QByteArray::fromBase64(m_process->readAllStandardOutput()); + QByteArray data = m_process->readAllStandardOutput(); QDataStream in(&data, QIODevice::ReadOnly); in >> m_data; emitResult(); } QVariantMap IndexedDataRetriever::data() const { return m_data; }