From be6b97433404ecdfc9367ffa9503ff66dcc210b3 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 10 Jan 2023 18:18:49 +0100 Subject: [PATCH] MoodbarPipeline: Fix saving moodbar if the URL contains host Fixes #1101 --- src/moodbar/moodbarpipeline.cpp | 23 +++++++++++++++++++---- src/moodbar/moodbarpipeline.h | 10 ++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/moodbar/moodbarpipeline.cpp b/src/moodbar/moodbarpipeline.cpp index 6e52c5333..5d3de4d65 100644 --- a/src/moodbar/moodbarpipeline.cpp +++ b/src/moodbar/moodbarpipeline.cpp @@ -19,7 +19,10 @@ #include #include +#include #include +#include +#include #include #include @@ -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(); // 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(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; } diff --git a/src/moodbar/moodbarpipeline.h b/src/moodbar/moodbarpipeline.h index b40c1c29c..3f29dba10 100644 --- a/src/moodbar/moodbarpipeline.h +++ b/src/moodbar/moodbarpipeline.h @@ -23,12 +23,13 @@ #include #include +#include + #include +#include #include #include -#include - 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_;