diff --git a/3rdparty/libechonest/Artist.cpp b/3rdparty/libechonest/Artist.cpp index 56351dcb2..0b5510187 100644 --- a/3rdparty/libechonest/Artist.cpp +++ b/3rdparty/libechonest/Artist.cpp @@ -581,6 +581,8 @@ QByteArray Echonest::Artist::searchParamToString(Echonest::Artist::SearchParam p return "sort"; case Mood: return "mood"; + case IdSpace: + return "bucket"; default: return ""; } @@ -622,4 +624,3 @@ QDebug Echonest::operator<<(QDebug d, const Echonest::Artist& artist) { return d.maybeSpace() << QString::fromLatin1( "Artist(%1, %2)" ).arg( artist.name() ).arg( QString::fromLatin1(artist.id()) ); } - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6eac41b84..5eea6f231 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -276,6 +276,7 @@ set(SOURCES songinfo/songinfosettingspage.cpp songinfo/songinfotextview.cpp songinfo/songinfoview.cpp + songinfo/songkickconcerts.cpp songinfo/songplaystats.cpp songinfo/ultimatelyricsprovider.cpp songinfo/ultimatelyricsreader.cpp @@ -528,6 +529,7 @@ set(HEADERS songinfo/songinfosettingspage.h songinfo/songinfotextview.h songinfo/songinfoview.h + songinfo/songkickconcerts.h songinfo/songplaystats.h songinfo/ultimatelyricsprovider.h songinfo/ultimatelyricsreader.h diff --git a/src/songinfo/artistinfoview.cpp b/src/songinfo/artistinfoview.cpp index 6c13bea14..cdf3879ae 100644 --- a/src/songinfo/artistinfoview.cpp +++ b/src/songinfo/artistinfoview.cpp @@ -19,6 +19,7 @@ #include "echonestbiographies.h" #include "echonestimages.h" #include "songinfofetcher.h" +#include "songkickconcerts.h" #include "widgets/prettyimageview.h" #ifdef HAVE_LIBLASTFM @@ -31,6 +32,7 @@ ArtistInfoView::ArtistInfoView(QWidget *parent) { fetcher_->AddProvider(new EchoNestBiographies); fetcher_->AddProvider(new EchoNestImages); + fetcher_->AddProvider(new SongkickConcerts); #ifdef HAVE_LIBLASTFM fetcher_->AddProvider(new EchoNestSimilarArtists); fetcher_->AddProvider(new EchoNestTags); diff --git a/src/songinfo/songkickconcerts.cpp b/src/songinfo/songkickconcerts.cpp new file mode 100644 index 000000000..d030d2be5 --- /dev/null +++ b/src/songinfo/songkickconcerts.cpp @@ -0,0 +1,61 @@ +#include "songkickconcerts.h" + +#include +#include "core/closure.h" + +const char* SongkickConcerts::kSongkickArtistBucket = "id:songkick"; +const char* SongkickConcerts::kSongkickArtistCalendarUrl = + "http://api.songkick.com/api/3.0/artists/%1/calendar.json?apikey="; + +SongkickConcerts::SongkickConcerts() { + +} + +void SongkickConcerts::FetchInfo(int id, const Song& metadata) { + Echonest::Artist::SearchParams params; + params.push_back(qMakePair(Echonest::Artist::Name, QVariant(metadata.artist()))); + params.push_back(qMakePair(Echonest::Artist::IdSpace, QVariant(kSongkickArtistBucket))); + qLog(Debug) << "Params:" << params; + QNetworkReply* reply = Echonest::Artist::search(params); + qLog(Debug) << reply->request().url(); + NewClosure(reply, SIGNAL(finished()), this, SLOT(ArtistSearchFinished(QNetworkReply*, int)), reply, id); +} + +void SongkickConcerts::ArtistSearchFinished(QNetworkReply* reply, int id) { + reply->deleteLater(); + try { + Echonest::Artists artists = Echonest::Artist::parseSearch(reply); + if (artists.isEmpty()) { + qLog(Debug) << "Failed to find artist in echonest"; + return; + } + + const Echonest::Artist& artist = artists[0]; + const Echonest::ForeignIds& foreign_ids = artist.foreignIds(); + QString songkick_id; + foreach (const Echonest::ForeignId& id, foreign_ids) { + if (id.catalog == "songkick") { + songkick_id = id.foreign_id; + break; + } + } + + if (songkick_id.isEmpty()) { + qLog(Debug) << "Failed to fetch songkick foreign id for artist"; + return; + } + + FetchSongkickCalendar(songkick_id, id); + } catch (Echonest::ParseError& e) { + qLog(Error) << "Error parsing echonest reply:" << e.errorType() << e.what(); + } +} + +void SongkickConcerts::FetchSongkickCalendar(const QString& artist_id, int id) { + QUrl url(QString(kSongkickArtistCalendarUrl).arg(artist_id)); + qLog(Debug) << "Would send request to:" << url; +} + +void SongkickConcerts::CalendarRequestFinished() { + +} diff --git a/src/songinfo/songkickconcerts.h b/src/songinfo/songkickconcerts.h new file mode 100644 index 000000000..7c9b69bff --- /dev/null +++ b/src/songinfo/songkickconcerts.h @@ -0,0 +1,26 @@ +#ifndef SONGKICKCONCERTS_H +#define SONGKICKCONCERTS_H + +#include "songinfoprovider.h" + +class QNetworkReply; + +class SongkickConcerts : public SongInfoProvider { + Q_OBJECT + + public: + SongkickConcerts(); + void FetchInfo(int id, const Song& metadata); + + private slots: + void ArtistSearchFinished(QNetworkReply* reply, int id); + void CalendarRequestFinished(); + + private: + void FetchSongkickCalendar(const QString& artist_id, int id); + + static const char* kSongkickArtistBucket; + static const char* kSongkickArtistCalendarUrl; +}; + +#endif