MoodbarPipeline: Fix saving moodbar if the URL contains host

Fixes #1101
This commit is contained in:
Jonas Kvinge 2023-01-10 18:18:49 +01:00
parent 194e81205b
commit be6b974334
2 changed files with 25 additions and 8 deletions

View File

@ -19,7 +19,10 @@
#include <memory>
#include <cstdlib>
#include <glib.h>
#include <glib-object.h>
#include <gst/gst.h>
#include <gst/app/gstappsink.h>
#include <QObject>
#include <QCoreApplication>
@ -36,9 +39,9 @@
const int MoodbarPipeline::kBands = 128;
MoodbarPipeline::MoodbarPipeline(const QUrl &local_filename, QObject *parent)
MoodbarPipeline::MoodbarPipeline(const QUrl &url, QObject *parent)
: QObject(parent),
local_filename_(local_filename),
url_(url),
pipeline_(nullptr),
convert_element_(nullptr),
success_(false),
@ -61,6 +64,16 @@ GstElement *MoodbarPipeline::CreateElement(const QString &factory_name) {
}
QByteArray MoodbarPipeline::ToGstUrl(const QUrl &url) {
if (url.isLocalFile() && !url.host().isEmpty()) {
QString str = "file:////" + url.host() + url.path();
return str.toUtf8();
}
return url.toEncoded();
}
void MoodbarPipeline::Start() {
Q_ASSERT(QThread::currentThread() != qApp->thread());
@ -97,7 +110,9 @@ void MoodbarPipeline::Start() {
builder_ = std::make_unique<MoodbarBuilder>();
// Set properties
g_object_set(decodebin, "uri", local_filename_.toEncoded().constData(), nullptr);
QByteArray gst_url = ToGstUrl(url_);
g_object_set(decodebin, "uri", gst_url.constData(), nullptr);
g_object_set(spectrum, "bands", kBands, nullptr);
GstFastSpectrum *fast_spectrum = reinterpret_cast<GstFastSpectrum*>(spectrum);
@ -128,7 +143,7 @@ void MoodbarPipeline::ReportError(GstMessage *msg) {
g_error_free(error);
g_free(debugs);
qLog(Error) << "Error processing" << local_filename_ << ":" << message;
qLog(Error) << "Error processing" << url_ << ":" << message;
}

View File

@ -23,12 +23,13 @@
#include <QString>
#include <QUrl>
#include <memory>
#include <glib.h>
#include <glib-object.h>
#include <gst/gst.h>
#include <gst/app/gstappsink.h>
#include <memory>
class MoodbarBuilder;
// Creates moodbar data for a single local music file.
@ -36,7 +37,7 @@ class MoodbarPipeline : public QObject {
Q_OBJECT
public:
explicit MoodbarPipeline(const QUrl &local_filename, QObject *parent = nullptr);
explicit MoodbarPipeline(const QUrl &url, QObject *parent = nullptr);
~MoodbarPipeline() override;
bool success() const { return success_; }
@ -51,6 +52,7 @@ class MoodbarPipeline : public QObject {
private:
GstElement *CreateElement(const QString &factory_name);
QByteArray ToGstUrl(const QUrl &url);
void ReportError(GstMessage *msg);
void Stop(const bool success);
void Cleanup();
@ -63,7 +65,7 @@ class MoodbarPipeline : public QObject {
private:
static const int kBands;
QUrl local_filename_;
QUrl url_;
GstElement *pipeline_;
GstElement *convert_element_;