mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-17 03:45:56 +01:00
Remove the resolvers for now - they don't work properly and ought to use the global search.
This commit is contained in:
parent
42bf358b81
commit
7548919bc1
@ -214,9 +214,6 @@ set(SOURCES
|
||||
playlistparsers/xmlparser.cpp
|
||||
playlistparsers/xspfparser.cpp
|
||||
|
||||
resolvers/libraryresolver.cpp
|
||||
resolvers/songresolver.cpp
|
||||
|
||||
smartplaylists/generator.cpp
|
||||
smartplaylists/generatorinserter.cpp
|
||||
smartplaylists/querygenerator.cpp
|
||||
@ -451,10 +448,6 @@ set(HEADERS
|
||||
playlistparsers/plsparser.h
|
||||
playlistparsers/xspfparser.h
|
||||
|
||||
resolvers/libraryresolver.h
|
||||
resolvers/resolver.h
|
||||
resolvers/songresolver.h
|
||||
|
||||
smartplaylists/generator.h
|
||||
smartplaylists/generatorinserter.h
|
||||
smartplaylists/generatormimedata.h
|
||||
@ -707,14 +700,12 @@ optional_source(HAVE_SPOTIFY
|
||||
internet/spotifyserver.cpp
|
||||
internet/spotifyservice.cpp
|
||||
internet/spotifysettingspage.cpp
|
||||
resolvers/spotifyresolver.cpp
|
||||
HEADERS
|
||||
globalsearch/spotifysearchprovider.h
|
||||
internet/spotifyblobdownloader.h
|
||||
internet/spotifyserver.h
|
||||
internet/spotifyservice.h
|
||||
internet/spotifysettingspage.h
|
||||
resolvers/spotifyresolver.h
|
||||
)
|
||||
|
||||
optional_source(HAVE_QCA INCLUDE_DIRECTORIES ${QCA_INCLUDE_DIRS})
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "library/librarybackend.h"
|
||||
#include "library/libraryquery.h"
|
||||
#include "library/sqlrow.h"
|
||||
#include "resolvers/songresolver.h"
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
@ -32,9 +31,6 @@ ParserBase::ParserBase(LibraryBackendInterface* library, QObject *parent)
|
||||
void ParserBase::LoadSong(const QString& filename_or_url, qint64 beginning,
|
||||
const QDir& dir, Song* song) const {
|
||||
if (filename_or_url.isEmpty()) {
|
||||
// Try and resolve from various sources.
|
||||
SongResolver resolver(library_);
|
||||
resolver.ResolveSong(song);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -90,13 +90,13 @@ Song XSPFParser::ParseTrack(QXmlStreamReader* reader, const QDir& dir) const {
|
||||
}
|
||||
|
||||
return_song:
|
||||
Song song;
|
||||
Song song = LoadSong(location, 0, dir);
|
||||
|
||||
// Override metadata with what was in the playlist
|
||||
song.set_title(title);
|
||||
song.set_artist(artist);
|
||||
song.set_album(album);
|
||||
song.set_length_nanosec(nanosec);
|
||||
LoadSong(location, 0, dir, &song);
|
||||
|
||||
return song;
|
||||
}
|
||||
|
||||
|
@ -1,64 +0,0 @@
|
||||
#include "libraryresolver.h"
|
||||
|
||||
#include <QtConcurrentRun>
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
#include "core/boundfuturewatcher.h"
|
||||
#include "core/song.h"
|
||||
#include "library/librarybackend.h"
|
||||
#include "library/libraryquery.h"
|
||||
#include "library/sqlrow.h"
|
||||
|
||||
using boost::scoped_ptr;
|
||||
|
||||
LibraryResolver::LibraryResolver(LibraryBackendInterface* backend, QObject* parent)
|
||||
: Resolver(parent),
|
||||
backend_(backend),
|
||||
next_id_(0) {
|
||||
}
|
||||
|
||||
int LibraryResolver::ResolveSong(const Song& song) {
|
||||
LibraryQuery* query = new LibraryQuery;
|
||||
query->AddWhere("artist", song.artist());
|
||||
query->AddWhere("title", song.title());
|
||||
query->SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec);
|
||||
|
||||
QFuture<bool> future = QtConcurrent::run(
|
||||
backend_, &LibraryBackendInterface::ExecQuery, query);
|
||||
BoundFutureWatcher<bool, LibraryQuery*>* watcher =
|
||||
new BoundFutureWatcher<bool, LibraryQuery*>(query);
|
||||
watcher->setFuture(future);
|
||||
connect(watcher, SIGNAL(finished()), SLOT(QueryFinished()));
|
||||
|
||||
int id = next_id_++;
|
||||
queries_[query] = id;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void LibraryResolver::QueryFinished() {
|
||||
BoundFutureWatcher<bool, LibraryQuery*>* watcher =
|
||||
static_cast<BoundFutureWatcher<bool, LibraryQuery*>*>(sender());
|
||||
scoped_ptr<LibraryQuery> query(watcher->data());
|
||||
watcher->deleteLater();
|
||||
|
||||
QMap<LibraryQuery*, int>::iterator it = queries_.find(query.get());
|
||||
if (it == queries_.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int id = it.value();
|
||||
queries_.erase(it);
|
||||
|
||||
SongList songs;
|
||||
if (watcher->result() && query->Next()) {
|
||||
do {
|
||||
Song song;
|
||||
song.InitFromQuery(*query, true);
|
||||
songs << song;
|
||||
} while (query->Next());
|
||||
}
|
||||
|
||||
emit ResolveFinished(id, songs);
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
#ifndef LIBRARYRESOLVER_H
|
||||
#define LIBRARYRESOLVER_H
|
||||
|
||||
#include <QMap>
|
||||
|
||||
#include "resolver.h"
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
class LibraryBackendInterface;
|
||||
class LibraryQuery;
|
||||
|
||||
class LibraryResolver : public Resolver {
|
||||
Q_OBJECT
|
||||
public:
|
||||
LibraryResolver(LibraryBackendInterface* backend, QObject* parent = 0);
|
||||
int ResolveSong(const Song& song);
|
||||
|
||||
signals:
|
||||
void ResolveFinished(int id, const SongList& songs);
|
||||
|
||||
private slots:
|
||||
void QueryFinished();
|
||||
|
||||
private:
|
||||
LibraryBackendInterface* backend_;
|
||||
QMap<LibraryQuery*, int> queries_;
|
||||
int next_id_;
|
||||
};
|
||||
|
||||
#endif // LIBRARYRESOLVER_H
|
@ -1,20 +0,0 @@
|
||||
#ifndef RESOLVER_H
|
||||
#define RESOLVER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "core/song.h"
|
||||
|
||||
class Resolver : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Resolver(QObject* parent = 0) : QObject(parent) {}
|
||||
virtual ~Resolver() {}
|
||||
|
||||
virtual int ResolveSong(const Song& song) = 0;
|
||||
|
||||
signals:
|
||||
void ResolveFinished(int id, SongList songs);
|
||||
};
|
||||
|
||||
#endif // RESOLVER_H
|
@ -1,57 +0,0 @@
|
||||
#include "songresolver.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/song.h"
|
||||
#include "internet/internetmodel.h"
|
||||
#include "libraryresolver.h"
|
||||
|
||||
#ifdef HAVE_SPOTIFY
|
||||
#include "internet/spotifyservice.h"
|
||||
#include "spotifyresolver.h"
|
||||
#endif
|
||||
|
||||
SongResolver::SongResolver(LibraryBackendInterface* library, QObject* parent)
|
||||
: QObject(parent),
|
||||
song_(NULL),
|
||||
resolvers_finished_(0),
|
||||
resolved_(false) {
|
||||
// Register in the order they should be checked.
|
||||
RegisterResolver(new LibraryResolver(library));
|
||||
#ifdef HAVE_SPOTIFY
|
||||
RegisterResolver(new SpotifyResolver(InternetModel::Service<SpotifyService>()));
|
||||
#endif
|
||||
}
|
||||
|
||||
SongResolver::~SongResolver() {
|
||||
qDeleteAll(resolvers_);
|
||||
resolvers_.clear();
|
||||
}
|
||||
|
||||
void SongResolver::RegisterResolver(Resolver* resolver) {
|
||||
resolvers_ << resolver;
|
||||
connect(resolver, SIGNAL(ResolveFinished(int, SongList)), SLOT(ResolveFinished(int, SongList)));
|
||||
}
|
||||
|
||||
bool SongResolver::ResolveSong(Song* song) {
|
||||
song_ = song;
|
||||
foreach (Resolver* resolver, resolvers_) {
|
||||
resolver->ResolveSong(*song);
|
||||
}
|
||||
loop_.exec();
|
||||
return resolved_;
|
||||
}
|
||||
|
||||
void SongResolver::ResolveFinished(int, SongList resolved_songs) {
|
||||
++resolvers_finished_;
|
||||
if (resolvers_finished_ == resolvers_.size()) {
|
||||
loop_.quit();
|
||||
}
|
||||
|
||||
if (!resolved_songs.isEmpty()) {
|
||||
*song_ = resolved_songs.first();
|
||||
qLog(Debug) << "Resolved song:" << song_->title() << "from:" << sender()->metaObject()->className();
|
||||
resolved_ = true;
|
||||
loop_.quit();
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
#ifndef SONGRESOLVER_H
|
||||
#define SONGRESOLVER_H
|
||||
|
||||
#include <QEventLoop>
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
|
||||
#include "core/song.h"
|
||||
|
||||
class LibraryBackendInterface;
|
||||
class Resolver;
|
||||
|
||||
class SongResolver : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SongResolver(LibraryBackendInterface* library, QObject* parent = 0);
|
||||
virtual ~SongResolver();
|
||||
|
||||
// Blocking
|
||||
bool ResolveSong(Song* song);
|
||||
|
||||
private slots:
|
||||
void ResolveFinished(int, SongList resolved_songs);
|
||||
|
||||
private:
|
||||
void RegisterResolver(Resolver* resolver);
|
||||
|
||||
QList<Resolver*> resolvers_;
|
||||
Song* song_;
|
||||
|
||||
QEventLoop loop_;
|
||||
|
||||
int resolvers_finished_;
|
||||
bool resolved_;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,80 +0,0 @@
|
||||
#include "spotifyresolver.h"
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/timeconstants.h"
|
||||
#include "internet/spotifyserver.h"
|
||||
#include "internet/spotifyservice.h"
|
||||
#include "spotifyblob/common/spotifymessages.pb.h"
|
||||
|
||||
SpotifyResolver::SpotifyResolver(SpotifyService* service, QObject* parent)
|
||||
: Resolver(parent),
|
||||
service_(service),
|
||||
server_(NULL),
|
||||
next_id_(0)
|
||||
{
|
||||
}
|
||||
|
||||
SpotifyServer* SpotifyResolver::server() {
|
||||
if (server_)
|
||||
return server_;
|
||||
|
||||
if (service_->login_state() != SpotifyService::LoginState_LoggedIn)
|
||||
return NULL;
|
||||
|
||||
server_ = service_->server();
|
||||
connect(server_, SIGNAL(SearchResults(spotify_pb::SearchResponse)),
|
||||
SLOT(SearchFinished(spotify_pb::SearchResponse)));
|
||||
connect(server_, SIGNAL(destroyed()), SLOT(ServerDestroyed()));
|
||||
|
||||
return server_;
|
||||
}
|
||||
|
||||
void SpotifyResolver::ServerDestroyed() {
|
||||
server_ = NULL;
|
||||
}
|
||||
|
||||
int SpotifyResolver::ResolveSong(const Song& song) {
|
||||
SpotifyServer* s = server();
|
||||
if (!s) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
QString query_string;
|
||||
query_string += "artist:\"" + song.artist() + "\"";
|
||||
query_string += " title:\"" + song.title() + "\"";
|
||||
query_string += " album:\"" + song.album() + "\"";
|
||||
|
||||
qLog(Debug) << query_string;
|
||||
|
||||
s->Search(query_string, 25);
|
||||
|
||||
int id = next_id_++;
|
||||
queries_[query_string] = id;
|
||||
return id;
|
||||
}
|
||||
|
||||
void SpotifyResolver::SearchFinished(const spotify_pb::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 spotify_pb::Track& track = response.result(i);
|
||||
Song song;
|
||||
SpotifyService::SongFromProtobuf(track, &song);
|
||||
songs << song;
|
||||
}
|
||||
qLog(Debug) << "Resolved from spotify:" << songs.length();
|
||||
if (!songs.isEmpty()) {
|
||||
qLog(Debug) << songs[0].title() << songs[0].artist();
|
||||
}
|
||||
|
||||
emit ResolveFinished(id, songs);
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#ifndef SPOTIFYRESOLVER_H
|
||||
#define SPOTIFYRESOLVER_H
|
||||
|
||||
#include <QMap>
|
||||
|
||||
#include "resolver.h"
|
||||
|
||||
namespace spotify_pb {
|
||||
class SearchResponse;
|
||||
}
|
||||
|
||||
class SpotifyService;
|
||||
class SpotifyServer;
|
||||
|
||||
class SpotifyResolver : public Resolver {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SpotifyResolver(SpotifyService* service, QObject* parent = 0);
|
||||
int ResolveSong(const Song& song);
|
||||
|
||||
signals:
|
||||
void ResolveFinished(int id, SongList songs);
|
||||
|
||||
private slots:
|
||||
void SearchFinished(const spotify_pb::SearchResponse& response);
|
||||
void ServerDestroyed();
|
||||
|
||||
private:
|
||||
SpotifyServer* server();
|
||||
|
||||
private:
|
||||
SpotifyService* service_;
|
||||
SpotifyServer* server_;
|
||||
QMap<QString, int> queries_;
|
||||
int next_id_;
|
||||
};
|
||||
|
||||
#endif // SPOTIFYRESOLVER_H
|
Loading…
Reference in New Issue
Block a user