diff options
author | Arno <am@disconnect.de> | 2013-07-27 03:59:47 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2013-07-27 04:02:21 +0200 |
commit | 0afebd0e3cb3da831cd5ffba1eefbe9e61e408a1 (patch) | |
tree | e92bd13b2ddda3af1af51d25c22d5042fb635139 /helper.cpp | |
parent | 46a552d89c70895abc75d94f3c647be29873afd9 (diff) | |
download | SheMov-0afebd0e3cb3da831cd5ffba1eefbe9e61e408a1.tar.gz SheMov-0afebd0e3cb3da831cd5ffba1eefbe9e61e408a1.tar.bz2 SheMov-0afebd0e3cb3da831cd5ffba1eefbe9e61e408a1.zip |
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.
Diffstat (limited to 'helper.cpp')
-rw-r--r-- | helper.cpp | 36 |
1 files changed, 14 insertions, 22 deletions
@@ -19,9 +19,11 @@ #include <QProcess> #include <QRect> #include <QTime> -#include <QtWidgets/QWidget> -#include <QtWidgets/QDesktopWidget> -#include <QtWidgets/QApplication> +#include <QWidget> +#include <QDesktopWidget> +#include <QApplication> +#include <QJsonDocument> +#include <QJsonObject> #include <stdio.h> @@ -216,32 +218,22 @@ namespace Helper { widget->move(widgetRect.topLeft()); } - QList<QVariant> duration(const QString &path){ + + QVariantMap ffmpegData(const QString &path){ QSettings s; QString ffProbe = s.value("paths/ffprobe").toString(); QStringList args; - QList<QVariant> retval = QList<QVariant>() << 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<QByteArray> 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 |