From 0afebd0e3cb3da831cd5ffba1eefbe9e61e408a1 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 27 Jul 2013 03:59:47 +0200 Subject: Read JSON from ffprobe Use JSON output from ffprobe instead of string parsing to get some kind of type safety. For doing that, some changes were needed in FileView: Use delegates for displaying Duration and Bitrate instead of mangling output in Qt::Displayrole. To reuse code, move all delegates from the new Archive to a separate file. And, of course, the initial objective: Show the accumulated size and duration of selected files in the status bar from the experimental archive. --- helper.cpp | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'helper.cpp') diff --git a/helper.cpp b/helper.cpp index b73ea2a..1881102 100644 --- a/helper.cpp +++ b/helper.cpp @@ -19,9 +19,11 @@ #include #include #include -#include -#include -#include +#include +#include +#include +#include +#include #include @@ -216,32 +218,22 @@ namespace Helper { widget->move(widgetRect.topLeft()); } - QList duration(const QString &path){ + + QVariantMap ffmpegData(const QString &path){ QSettings s; QString ffProbe = s.value("paths/ffprobe").toString(); QStringList args; - QList retval = QList() << QVariant() << QVariant(); - args << "-show_streams" << path; + QVariantMap retval; + args << "-v" << "quiet" << "-print_format" << "json" << "-show_format" << path; QProcess ffproc; ffproc.start(ffProbe, args); if(!ffproc.waitForStarted()){ - return retval; + return QVariantMap(); } ffproc.waitForFinished(); - QByteArray ffData = ffproc.readAllStandardError(); - QList lines = ffData.split('\n'); - - foreach(QString l, lines){ - QString llc = l.toLower(); - if(llc.contains("duration")){ - int idx = llc.indexOf("duration:"); - retval[0].setValue(Duration(llc.mid(idx + 10, 8))); - idx = llc.indexOf("bitrate:"); - retval[1] = llc.mid(idx + 9); - break; - } - } - return retval; + QByteArray ffData = ffproc.readAllStandardOutput(); + QJsonDocument jsDoc = QJsonDocument::fromJson(ffData); + return jsDoc.object().value("format").toObject().toVariantMap(); } Duration::Duration() : mHours(0), mMinutes(0), mSeconds(0) {} @@ -249,7 +241,7 @@ namespace Helper { Duration::Duration(qint64 seconds){ int sec(0), min(0), h(0); // get hours - h = (seconds / 60 / 60) % 24; + h = (seconds / 60 / 60); // remaining minutes min = (seconds / 60) % 60; // seconds -- cgit v1.2.3-70-g09d2