diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 99d1a3155..f2905a166 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -297,6 +297,7 @@ set(SOURCES smartplaylists/wizard.cpp smartplaylists/wizardplugin.cpp + songinfo/artistbiography.cpp songinfo/artistinfoview.cpp songinfo/collapsibleinfoheader.cpp songinfo/collapsibleinfopane.cpp @@ -588,6 +589,7 @@ set(HEADERS smartplaylists/wizard.h smartplaylists/wizardplugin.h + songinfo/artistbiography.h songinfo/artistinfoview.h songinfo/collapsibleinfoheader.h songinfo/collapsibleinfopane.h diff --git a/src/songinfo/artistbiography.cpp b/src/songinfo/artistbiography.cpp new file mode 100644 index 000000000..28304d2fd --- /dev/null +++ b/src/songinfo/artistbiography.cpp @@ -0,0 +1,80 @@ +/* This file is part of Clementine. + Copyright 2016, John Maguire + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include "artistbiography.h" + +#include + +#include + +#include "core/closure.h" +#include "core/network.h" +#include "songinfo/songinfotextview.h" + +namespace { +const char* kArtistBioUrl = "https://data.clementine-player.org/fetchbio"; + +QString GetLocale() { + QLocale locale; + return locale.name().split('_')[0]; +} + +} // namespace + +ArtistBiography::ArtistBiography() : network_(new NetworkAccessManager) {} + +ArtistBiography::~ArtistBiography() {} + +void ArtistBiography::FetchInfo(int id, const Song& metadata) { + if (metadata.artist().isEmpty()) { + emit Finished(id); + return; + } + + QUrl url(kArtistBioUrl); + url.addQueryItem("artist", metadata.artist()); + url.addQueryItem("lang", GetLocale()); + + QNetworkRequest request(url); + QNetworkReply* reply = network_->get(request); + + NewClosure(reply, SIGNAL(finished()), [this, reply, id]() { + reply->deleteLater(); + + QJson::Parser parser; + QVariantMap response = parser.parse(reply).toMap(); + + QString body = response["articleBody"].toString(); + QString url = response["url"].toString(); + + CollapsibleInfoPane::Data data; + data.id_ = url; + data.title_ = tr("Biography"); + data.type_ = CollapsibleInfoPane::Data::Type_Biography; + + QString text; + text += + "

" + tr("Open in your browser") + "

"; + + text += body; + SongInfoTextView* editor = new SongInfoTextView; + editor->SetHtml(text); + data.contents_ = editor; + emit InfoReady(id, data); + emit Finished(id); + }); +} diff --git a/src/songinfo/artistbiography.h b/src/songinfo/artistbiography.h new file mode 100644 index 000000000..eb6da873b --- /dev/null +++ b/src/songinfo/artistbiography.h @@ -0,0 +1,40 @@ +/* This file is part of Clementine. + Copyright 2016, John Maguire + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef ARTISTBIOGRAPHY_H +#define ARTISTBIOGRAPHY_H + +#include + +#include "songinfoprovider.h" + +class NetworkAccessManager; + +class ArtistBiography : public SongInfoProvider { + Q_OBJECT + + public: + ArtistBiography(); + ~ArtistBiography(); + + void FetchInfo(int id, const Song& metadata) override; + + private: + std::unique_ptr network_; +}; + +#endif // ARTISTBIOGRAPHY_H diff --git a/src/songinfo/artistinfoview.cpp b/src/songinfo/artistinfoview.cpp index 3ee92784d..8a1f77582 100644 --- a/src/songinfo/artistinfoview.cpp +++ b/src/songinfo/artistinfoview.cpp @@ -17,6 +17,7 @@ #include "artistinfoview.h" +#include "songinfo/artistbiography.h" #include "songinfo/songinfofetcher.h" #include "songinfo/songkickconcerts.h" #include "songinfo/spotifyimages.h" @@ -25,6 +26,7 @@ ArtistInfoView::ArtistInfoView(QWidget* parent) : SongInfoBase(parent) { fetcher_->AddProvider(new SongkickConcerts); fetcher_->AddProvider(new SpotifyImages); + fetcher_->AddProvider(new ArtistBiography); } ArtistInfoView::~ArtistInfoView() {}