on xenial help sign in
Remove gstreamer bits, make mediaartcache use artist/album passed with the uri.
8058215Pawel Stolowski
plugins/Unity/iconutils.cpp+2−2
@@ -101,9 +101,9 @@ QString uriToThumbnailerProviderString(QString const &uri, QString const &mimety
101 thumbnailerUri = BASE_ALBUMART_URI;
101 thumbnailerUri = BASE_ALBUMART_URI;
102 const QString album = metadata["album"].toString();
102 const QString album = metadata["album"].toString();
103 const QString artist = metadata["artist"].toString();
103 const QString artist = metadata["artist"].toString();
104− thumbnailerUri.append(QUrl::toPercentEncoding(album));
105− thumbnailerUri.append("/");
106 thumbnailerUri.append(QUrl::toPercentEncoding(artist));
104 thumbnailerUri.append(QUrl::toPercentEncoding(artist));
105+ thumbnailerUri.append("/");
106+ thumbnailerUri.append(QUrl::toPercentEncoding(album));
107 } else {
107 } else {
108 thumbnailerUri = BASE_THUMBNAILER_URI;
108 thumbnailerUri = BASE_THUMBNAILER_URI;
109 thumbnailerUri.append(uri.midRef(7));
109 thumbnailerUri.append(uri.midRef(7));
plugins/Utils/CMakeLists.txt−5
@@ -1,12 +1,10 @@
1# Dependencies
1# Dependencies
2include(FindPkgConfig)
2include(FindPkgConfig)
3−pkg_search_module(GST gstreamer-1.0 REQUIRED)
4
3
5include_directories(
4include_directories(
6 ${CMAKE_CURRENT_SOURCE_DIR}
5 ${CMAKE_CURRENT_SOURCE_DIR}
7 ${CMAKE_CURRENT_BINARY_DIR}
6 ${CMAKE_CURRENT_BINARY_DIR}
8 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
7 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
9− ${GST_INCLUDE_DIRS}
10)
8)
11
9
12set(QMLPLUGIN_SRC
10set(QMLPLUGIN_SRC
@@ -24,9 +22,6 @@ add_library(Utils-qml SHARED
24 ${QMLPLUGIN_SRC}
22 ${QMLPLUGIN_SRC}
25 )
23 )
26
24
27−target_link_libraries(Utils-qml
28− ${GST_LDFLAGS}
29− )
30# Because this is an internal support library, we want
25# Because this is an internal support library, we want
31# to expose all symbols in it. Consider changing this
26# to expose all symbols in it. Consider changing this
32# either to a static library or just using the
27# either to a static library or just using the
plugins/Utils/albumartprovider.cpp+24−115
@@ -25,114 +25,20 @@
25#include <QNetworkReply>
25#include <QNetworkReply>
26#include <QXmlQuery>
26#include <QXmlQuery>
27#include <QBuffer>
27#include <QBuffer>
28−#include<cstdio>
28+#include <cstdio>
29−#include<QDebug>
29+#include <QDebug>
30−#include<QFile>
30+#include <QFile>
31+#include <QStringList>
31−#include<QByteArray>
32+#include <QByteArray>
32−#include<gst/gst.h>
33+#include <unistd.h>
33−#include<unistd.h>
34−#include<memory>
34+#include <memory>
35−#include<QImage>
35+#include <QImage>
36+#include <QUrl>
36
37
37using namespace std;
38using namespace std;
38
39
39const std::string AlbumArtProvider::DEFAULT_ALBUM_ART = "/usr/share/unity/icons/album_missing.png";
40const std::string AlbumArtProvider::DEFAULT_ALBUM_ART = "/usr/share/unity/icons/album_missing.png";
40
41
41−static void on_new_pad (GstElement * /*dec*/, GstPad * pad, GstElement * fakesink) {
42− GstPad *sinkpad;
43−
44− sinkpad = gst_element_get_static_pad (fakesink, "sink");
45− if (!gst_pad_is_linked (sinkpad)) {
46− if (gst_pad_link (pad, sinkpad) != GST_PAD_LINK_OK)
47− g_error ("Failed to link pads!");
48− }
49− gst_object_unref (sinkpad);
50−}
51−
52−static void process_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data) {
53− struct albuminfo *md = (struct albuminfo*) user_data;
54− int i, num;
55− string tagname(tag);
56−
57− num = gst_tag_list_get_tag_size (list, tag);
58− for (i = 0; i < num; ++i) {
59− gchar *val;
60− if (gst_tag_get_type(tag) == G_TYPE_STRING) {
61− if (gst_tag_list_get_string_index (list, tag, i, &val)) {
62− if(tagname == "artist")
63− md->artist = std::string(val);
64− if(tagname == "album")
65− md->album = std::string(val);
66− }}
67− }
68−}
69−
70−albuminfo AlbumArtProvider::get_album_info(const std::string &filename) throw (runtime_error)
71−{
72− albuminfo ai;
73− // FIXME: Need to do quoting. Files with %'s in their names seem to confuse gstreamer.
74−
75− const string uri = "file://" + filename;
76−
77− GstElement *dec = gst_element_factory_make ("uridecodebin", NULL);
78− if (dec == nullptr)
79− throw runtime_error("Failed to create uridecodebin element");
80−
81− GstElement *pipe = gst_pipeline_new ("pipeline");
82−
83− g_object_set (dec, "uri", uri.c_str(), NULL);
84− gst_bin_add (GST_BIN (pipe), dec);
85−
86− GstElement *sink = gst_element_factory_make ("fakesink", NULL);
87− gst_bin_add (GST_BIN (pipe), sink);
88− g_signal_connect (dec, "pad-added", G_CALLBACK (on_new_pad), sink);
89−
90− gst_element_set_state (pipe, GST_STATE_PAUSED);
91−
92− GstMessage *msg;
93− while (true) {
94− GstTagList *tags = NULL;
95−
96− msg = gst_bus_timed_pop_filtered(GST_ELEMENT_BUS (pipe),
97− GST_CLOCK_TIME_NONE, (GstMessageType) (GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_TAG | GST_MESSAGE_ERROR));
98−
99− if (GST_MESSAGE_TYPE (msg) != GST_MESSAGE_TAG) /* error or async_done */
100− break;
101−
102− gst_message_parse_tag (msg, &tags);
103− gst_tag_list_foreach (tags, process_one_tag, &ai);
104− gst_tag_list_unref (tags);
105−
106− gst_message_unref (msg);
107− };
108−
109− gst_element_set_state (pipe, GST_STATE_NULL);
110− gst_object_unref (pipe);
111−
112− if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
113− GError *err;
114− gchar *dbg_info;
115− gst_message_parse_error(msg, &err, &dbg_info);
116− string errortxt(err->message);
117− string dbtxt(dbg_info);
118− g_error_free(err);
119− g_free(dbg_info);
120−
121− gst_message_unref (msg);
122− string msg = "Extracting metadata of file ";
123− msg += filename;
124− msg += " failed: ";
125− msg += errortxt;
126− msg += " ";
127− msg += dbg_info;
128− throw runtime_error(msg);
129− }
130−
131− gst_message_unref (msg);
132−
133− return ai;
134−}
135−
136std::string AlbumArtProvider::get_lastfm_url(const albuminfo &ai) {
42std::string AlbumArtProvider::get_lastfm_url(const albuminfo &ai) {
137 QString artist = QString::fromStdString(ai.artist);
43 QString artist = QString::fromStdString(ai.artist);
138 QString album = QString::fromStdString(ai.album);
44 QString album = QString::fromStdString(ai.album);
@@ -154,8 +60,6 @@ std::string AlbumArtProvider::get_lastfm_url(const albuminfo &ai) {
154 return "";
60 return "";
155 }
61 }
156
62
157−
158−
159 QXmlQuery query;
63 QXmlQuery query;
160 QBuffer tmp;
64 QBuffer tmp;
161 tmp.setData(reply->readAll());
65 tmp.setData(reply->readAll());
@@ -212,14 +116,12 @@ void AlbumArtProvider::fix_format(const std::string &fname) {
212 im.save(fname.c_str(), "JPEG");
116 im.save(fname.c_str(), "JPEG");
213}
117}
214
118
215−std::string AlbumArtProvider::get_image(const std::string &filename) {
119+std::string AlbumArtProvider::get_image(const std::string &artist, const std::string &album) {
216 albuminfo info;
120 albuminfo info;
217− try {
121+
218− info = get_album_info(filename);
122+ info.artist = artist;
219− } catch(std::exception &e) {
123+ info.album = album;
220− qDebug() << "Could not determine album info: " << e.what();
124+
221− return DEFAULT_ALBUM_ART;
222− }
223 if(info.album.empty() || info.artist.empty()) {
125 if(info.album.empty() || info.artist.empty()) {
224 return DEFAULT_ALBUM_ART;
126 return DEFAULT_ALBUM_ART;
225 }
127 }
@@ -256,10 +158,17 @@ std::string AlbumArtProvider::get_image(const std::string &filename) {
256QImage AlbumArtProvider::requestImage(const QString &id, QSize *realSize, const QSize &requestedSize) {
158QImage AlbumArtProvider::requestImage(const QString &id, QSize *realSize, const QSize &requestedSize) {
257 Q_UNUSED(requestedSize)
159 Q_UNUSED(requestedSize)
258
160
259− std::string src_path(id.toUtf8().data());
161+ const QStringList parts = id.split("/");
162+ if (parts.size() != 2) {
163+ qWarning("Invalid albumart uri");
164+ return QImage(QString::fromStdString(DEFAULT_ALBUM_ART));
165+ }
166+ const std::string artist = QUrl::fromPercentEncoding(parts[0].toUtf8()).toStdString();
167+ const std::string album = QUrl::fromPercentEncoding(parts[1].toUtf8()).toStdString();
168+
260 std::string tgt_path;
169 std::string tgt_path;
261 try {
170 try {
262− tgt_path = get_image(src_path);
171+ tgt_path = get_image(artist, album);
263 if(!tgt_path.empty()) {
172 if(!tgt_path.empty()) {
264 QString tgt(tgt_path.c_str());
173 QString tgt(tgt_path.c_str());
265 QImage image;
174 QImage image;
@@ -275,5 +184,5 @@ QImage AlbumArtProvider::requestImage(const QString &id, QSize *realSize, const
275 }
184 }
276
185
277 *realSize = QSize(0, 0);
186 *realSize = QSize(0, 0);
278− return QImage();
187+ return QImage(QString::fromStdString(DEFAULT_ALBUM_ART));
279}
188}
plugins/Utils/albumartprovider.h+1−3
@@ -36,7 +36,7 @@ public:
36 AlbumArtProvider() : QQuickImageProvider(QQmlImageProviderBase::Image, QQmlImageProviderBase::ForceAsynchronousImageLoading) {}
36 AlbumArtProvider() : QQuickImageProvider(QQmlImageProviderBase::Image, QQmlImageProviderBase::ForceAsynchronousImageLoading) {}
37 QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
37 QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
38
38
39− std::string get_image(const std::string &filename);
39+ std::string get_image(const std::string &artist, const std::string &album);
40
40
41 const static std::string DEFAULT_ALBUM_ART;
41 const static std::string DEFAULT_ALBUM_ART;
42private:
42private:
@@ -44,8 +44,6 @@ private:
44
44
45 void fix_format(const std::string &fname);
45 void fix_format(const std::string &fname);
46
46
47− albuminfo get_album_info(const std::string &filename) throw (std::runtime_error);
48−
49 std::string get_lastfm_url(const albuminfo &ai);
47 std::string get_lastfm_url(const albuminfo &ai);
50
48
51 bool download_and_store(const std::string &image_url, const std::string &output_file);
49 bool download_and_store(const std::string &image_url, const std::string &output_file);