@@ -29,107 +29,13 @@
29#include<QDebug>
29#include<QDebug>
30#include<QFile>
30#include<QFile>
31#include<QByteArray>
31#include<QByteArray>
33#include<unistd.h>
32#include<unistd.h>
34#include<memory>
33#include<memory>
35#include<QImage>
34#include<QImage>
37using namespace std;
36using namespace std;
39−static void on_new_pad (GstElement * /*dec*/, GstPad * pad, GstElement * fakesink) {
42− sinkpad = gst_element_get_static_pad (fakesink, "sink");
43− if (!gst_pad_is_linked (sinkpad)) {
44− if (gst_pad_link (pad, sinkpad) != GST_PAD_LINK_OK)
45− g_error ("Failed to link pads!");
47− gst_object_unref (sinkpad);
50−static void process_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data) {
51− struct albuminfo *md = (struct albuminfo*) user_data;
55− num = gst_tag_list_get_tag_size (list, tag);
56− for (i = 0; i < num; ++i) {
58− if (gst_tag_get_type(tag) == G_TYPE_STRING) {
59− if (gst_tag_list_get_string_index (list, tag, i, &val)) {
60− if(tagname == "artist")
61− md->artist = std::string(val);
62− if(tagname == "album")
63− md->album = std::string(val);
68−albuminfo AlbumArtProvider::get_album_info(const std::string &filename) throw (runtime_error)
71− // FIXME: Need to do quoting. Files with %'s in their names seem to confuse gstreamer.
73− const string uri = "file://" + filename;
75− GstElement *dec = gst_element_factory_make ("uridecodebin", NULL);
77− throw runtime_error("Failed to create uridecodebin element");
79− GstElement *pipe = gst_pipeline_new ("pipeline");
81− g_object_set (dec, "uri", uri.c_str(), NULL);
82− gst_bin_add (GST_BIN (pipe), dec);
84− GstElement *sink = gst_element_factory_make ("fakesink", NULL);
85− gst_bin_add (GST_BIN (pipe), sink);
86− g_signal_connect (dec, "pad-added", G_CALLBACK (on_new_pad), sink);
88− gst_element_set_state (pipe, GST_STATE_PAUSED);
92− GstTagList *tags = NULL;
94− msg = gst_bus_timed_pop_filtered(GST_ELEMENT_BUS (pipe),
95− GST_CLOCK_TIME_NONE, (GstMessageType) (GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_TAG | GST_MESSAGE_ERROR));
97− if (GST_MESSAGE_TYPE (msg) != GST_MESSAGE_TAG) /* error or async_done */
100− gst_message_parse_tag (msg, &tags);
101− gst_tag_list_foreach (tags, process_one_tag, &ai);
102− gst_tag_list_unref (tags);
104− gst_message_unref (msg);
107− gst_element_set_state (pipe, GST_STATE_NULL);
108− gst_object_unref (pipe);
110− if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
113− gst_message_parse_error(msg, &err, &dbg_info);
114− string errortxt(err->message);
115− string dbtxt(dbg_info);
119− gst_message_unref (msg);
120− string msg = "Extracting metadata of file ";
126− throw runtime_error(msg);
129− gst_message_unref (msg);
134std::string AlbumArtProvider::get_lastfm_url(const albuminfo &ai) {
40std::string AlbumArtProvider::get_lastfm_url(const albuminfo &ai) {
135 QString artist = QString::fromStdString(ai.artist);
41 QString artist = QString::fromStdString(ai.artist);
@@ -208,14 +114,11 @@ void AlbumArtProvider::fix_format(const std::string &fname) {
208 im.save(fname.c_str(), "JPEG");
114 im.save(fname.c_str(), "JPEG");
211−std::string AlbumArtProvider::get_image(const std::string &filename) {
117+std::string AlbumArtProvider::get_image(const std::string &artist, const std::string &album) {
212 albuminfo info;
118 albuminfo info;
213− try {
119+ info.artist = artist;
214− info = get_album_info(filename);
120+ info.album = album;
215− } catch(std::exception &e) {
121+
216− qDebug() << "Could not determine album info: " << e.what();
219 if(info.album.empty() || info.artist.empty()) {
122 if(info.album.empty() || info.artist.empty()) {
220 return "";
123 return "";