2011-05-31 17:33:46 +02:00
|
|
|
#include "spotifyresolver.h"
|
|
|
|
|
|
|
|
#include "core/logging.h"
|
|
|
|
#include "core/timeconstants.h"
|
|
|
|
#include "radio/spotifyserver.h"
|
2011-06-01 17:53:05 +02:00
|
|
|
#include "radio/spotifyservice.h"
|
2011-05-31 17:33:46 +02:00
|
|
|
#include "spotifyblob/common/spotifymessages.pb.h"
|
|
|
|
|
|
|
|
SpotifyResolver::SpotifyResolver(SpotifyServer* spotify, QObject* parent)
|
|
|
|
: Resolver(parent),
|
|
|
|
spotify_(spotify),
|
|
|
|
next_id_(0) {
|
2011-06-01 17:53:05 +02:00
|
|
|
connect(spotify_, SIGNAL(SearchResults(protobuf::SearchResponse)),
|
|
|
|
SLOT(SearchFinished(protobuf::SearchResponse)));
|
2011-05-31 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int SpotifyResolver::ResolveSong(const Song& song) {
|
|
|
|
QString query_string;
|
|
|
|
query_string += "artist:\"" + song.artist() + "\"";
|
|
|
|
query_string += " title:\"" + song.title() + "\"";
|
|
|
|
query_string += " album:\"" + song.album() + "\"";
|
|
|
|
|
|
|
|
qLog(Debug) << query_string;
|
|
|
|
|
|
|
|
spotify_->Search(query_string, 25);
|
|
|
|
|
|
|
|
int id = next_id_++;
|
|
|
|
queries_[query_string] = id;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpotifyResolver::SearchFinished(const protobuf::SearchResponse& response) {
|
|
|
|
QString query_string = QString::fromUtf8(response.request().query().c_str());
|
|
|
|
qLog(Debug) << query_string;
|
|
|
|
QMap<QString, int>::iterator it = queries_.find(query_string);
|
|
|
|
if (it == queries_.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int id = it.value();
|
|
|
|
queries_.erase(it);
|
|
|
|
|
|
|
|
SongList songs;
|
|
|
|
for (int i = 0; i < response.result_size(); ++i) {
|
|
|
|
const protobuf::Track& track = response.result(i);
|
|
|
|
Song song;
|
2011-06-01 17:53:05 +02:00
|
|
|
SpotifyService::SongFromProtobuf(track, &song);
|
2011-05-31 17:33:46 +02:00
|
|
|
songs << song;
|
|
|
|
}
|
|
|
|
qLog(Debug) << "Resolved from spotify:" << songs.length();
|
|
|
|
if (!songs.isEmpty()) {
|
|
|
|
qLog(Debug) << songs[0].title() << songs[0].artist();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit ResolveFinished(id, songs);
|
|
|
|
}
|