parent
a8a0f2e4fd
commit
7c0ef13bb7
|
@ -297,6 +297,7 @@ set(SOURCES
|
||||||
smartplaylists/wizard.cpp
|
smartplaylists/wizard.cpp
|
||||||
smartplaylists/wizardplugin.cpp
|
smartplaylists/wizardplugin.cpp
|
||||||
|
|
||||||
|
songinfo/artistbiography.cpp
|
||||||
songinfo/artistinfoview.cpp
|
songinfo/artistinfoview.cpp
|
||||||
songinfo/collapsibleinfoheader.cpp
|
songinfo/collapsibleinfoheader.cpp
|
||||||
songinfo/collapsibleinfopane.cpp
|
songinfo/collapsibleinfopane.cpp
|
||||||
|
@ -588,6 +589,7 @@ set(HEADERS
|
||||||
smartplaylists/wizard.h
|
smartplaylists/wizard.h
|
||||||
smartplaylists/wizardplugin.h
|
smartplaylists/wizardplugin.h
|
||||||
|
|
||||||
|
songinfo/artistbiography.h
|
||||||
songinfo/artistinfoview.h
|
songinfo/artistinfoview.h
|
||||||
songinfo/collapsibleinfoheader.h
|
songinfo/collapsibleinfoheader.h
|
||||||
songinfo/collapsibleinfopane.h
|
songinfo/collapsibleinfopane.h
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
/* This file is part of Clementine.
|
||||||
|
Copyright 2016, John Maguire <john.maguire@gmail.com>
|
||||||
|
|
||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "artistbiography.h"
|
||||||
|
|
||||||
|
#include <QLocale>
|
||||||
|
|
||||||
|
#include <qjson/parser.h>
|
||||||
|
|
||||||
|
#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 +=
|
||||||
|
"<p><a href=\"" + url + "\">" + tr("Open in your browser") + "</a></p>";
|
||||||
|
|
||||||
|
text += body;
|
||||||
|
SongInfoTextView* editor = new SongInfoTextView;
|
||||||
|
editor->SetHtml(text);
|
||||||
|
data.contents_ = editor;
|
||||||
|
emit InfoReady(id, data);
|
||||||
|
emit Finished(id);
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/* This file is part of Clementine.
|
||||||
|
Copyright 2016, John Maguire <john.maguire@gmail.com>
|
||||||
|
|
||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ARTISTBIOGRAPHY_H
|
||||||
|
#define ARTISTBIOGRAPHY_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#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<NetworkAccessManager> network_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ARTISTBIOGRAPHY_H
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "artistinfoview.h"
|
#include "artistinfoview.h"
|
||||||
|
|
||||||
|
#include "songinfo/artistbiography.h"
|
||||||
#include "songinfo/songinfofetcher.h"
|
#include "songinfo/songinfofetcher.h"
|
||||||
#include "songinfo/songkickconcerts.h"
|
#include "songinfo/songkickconcerts.h"
|
||||||
#include "songinfo/spotifyimages.h"
|
#include "songinfo/spotifyimages.h"
|
||||||
|
@ -25,6 +26,7 @@
|
||||||
ArtistInfoView::ArtistInfoView(QWidget* parent) : SongInfoBase(parent) {
|
ArtistInfoView::ArtistInfoView(QWidget* parent) : SongInfoBase(parent) {
|
||||||
fetcher_->AddProvider(new SongkickConcerts);
|
fetcher_->AddProvider(new SongkickConcerts);
|
||||||
fetcher_->AddProvider(new SpotifyImages);
|
fetcher_->AddProvider(new SpotifyImages);
|
||||||
|
fetcher_->AddProvider(new ArtistBiography);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArtistInfoView::~ArtistInfoView() {}
|
ArtistInfoView::~ArtistInfoView() {}
|
||||||
|
|
Loading…
Reference in New Issue