Filter out bad wikipedia images better and support other locales better.
#5416
This commit is contained in:
parent
55af2b1d3b
commit
a9ba0f3bf2
|
@ -1479,8 +1479,7 @@ void Playlist::Restore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Playlist::ItemsLoaded(QFuture<PlaylistItemList> future) {
|
void Playlist::ItemsLoaded(QFuture<PlaylistItemList> future) {
|
||||||
if (cancel_restore_)
|
if (cancel_restore_) return;
|
||||||
return;
|
|
||||||
|
|
||||||
PlaylistItemList items = future.result();
|
PlaylistItemList items = future.result();
|
||||||
|
|
||||||
|
@ -1671,8 +1670,6 @@ void Playlist::StopAfter(int row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Playlist::SetStreamMetadata(const QUrl& url, const Song& song) {
|
void Playlist::SetStreamMetadata(const QUrl& url, const Song& song) {
|
||||||
qLog(Debug) << "Setting metadata for" << url << "to" << song.artist()
|
|
||||||
<< song.title();
|
|
||||||
if (!current_item()) return;
|
if (!current_item()) return;
|
||||||
|
|
||||||
if (current_item()->Url() != url) return;
|
if (current_item()->Url() != url) return;
|
||||||
|
|
|
@ -30,10 +30,12 @@
|
||||||
namespace {
|
namespace {
|
||||||
const char* kArtistBioUrl = "https://data.clementine-player.org/fetchbio";
|
const char* kArtistBioUrl = "https://data.clementine-player.org/fetchbio";
|
||||||
const char* kWikipediaImageListUrl =
|
const char* kWikipediaImageListUrl =
|
||||||
"https://en.wikipedia.org/w/api.php?action=query&prop=images&format=json";
|
"https://%1.wikipedia.org/w/"
|
||||||
|
"api.php?action=query&prop=images&format=json&imlimit=25";
|
||||||
const char* kWikipediaImageInfoUrl =
|
const char* kWikipediaImageInfoUrl =
|
||||||
"https://en.wikipedia.org/w/"
|
"https://%1.wikipedia.org/w/"
|
||||||
"api.php?action=query&prop=imageinfo&iiprop=url&format=json";
|
"api.php?action=query&prop=imageinfo&iiprop=url|size&format=json";
|
||||||
|
const int kMinimumImageSize = 400;
|
||||||
|
|
||||||
QString GetLocale() {
|
QString GetLocale() {
|
||||||
QLocale locale;
|
QLocale locale;
|
||||||
|
@ -56,6 +58,8 @@ void ArtistBiography::FetchInfo(int id, const Song& metadata) {
|
||||||
url.addQueryItem("artist", metadata.artist());
|
url.addQueryItem("artist", metadata.artist());
|
||||||
url.addQueryItem("lang", GetLocale());
|
url.addQueryItem("lang", GetLocale());
|
||||||
|
|
||||||
|
qLog(Debug) << "Biography url: " << url;
|
||||||
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
QNetworkReply* reply = network_->get(request);
|
QNetworkReply* reply = network_->get(request);
|
||||||
|
|
||||||
|
@ -126,6 +130,11 @@ QString ExtractImageUrl(const QVariantMap& json) {
|
||||||
} else if (it.key() == "imageinfo") {
|
} else if (it.key() == "imageinfo") {
|
||||||
QVariantList imageinfos = it.value().toList();
|
QVariantList imageinfos = it.value().toList();
|
||||||
QVariantMap imageinfo = imageinfos.first().toMap();
|
QVariantMap imageinfo = imageinfos.first().toMap();
|
||||||
|
int width = imageinfo["width"].toInt();
|
||||||
|
int height = imageinfo["height"].toInt();
|
||||||
|
if (width < kMinimumImageSize || height < kMinimumImageSize) {
|
||||||
|
return QString::null;
|
||||||
|
}
|
||||||
return imageinfo["url"].toString();
|
return imageinfo["url"].toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,20 +145,22 @@ QString ExtractImageUrl(const QVariantMap& json) {
|
||||||
|
|
||||||
void ArtistBiography::FetchWikipediaImages(int id,
|
void ArtistBiography::FetchWikipediaImages(int id,
|
||||||
const QString& wikipedia_url) {
|
const QString& wikipedia_url) {
|
||||||
QRegExp regex("/wiki/(.*)");
|
qLog(Debug) << wikipedia_url;
|
||||||
|
QRegExp regex("([a-z]+)\\.wikipedia\\.org/wiki/(.*)");
|
||||||
if (regex.indexIn(wikipedia_url) == -1) {
|
if (regex.indexIn(wikipedia_url) == -1) {
|
||||||
emit Finished(id);
|
emit Finished(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString wiki_title = regex.cap(1);
|
QString wiki_title = regex.cap(2);
|
||||||
QUrl url(kWikipediaImageListUrl);
|
QString language = regex.cap(1);
|
||||||
|
QUrl url(QString(kWikipediaImageListUrl).arg(language));
|
||||||
url.addQueryItem("titles", wiki_title);
|
url.addQueryItem("titles", wiki_title);
|
||||||
|
|
||||||
qLog(Debug) << "Wikipedia images:" << url;
|
qLog(Debug) << "Wikipedia images:" << url;
|
||||||
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
QNetworkReply* reply = network_->get(request);
|
QNetworkReply* reply = network_->get(request);
|
||||||
NewClosure(reply, SIGNAL(finished()), [this, id, reply]() {
|
NewClosure(reply, SIGNAL(finished()), [this, id, reply, language]() {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
QJson::Parser parser;
|
QJson::Parser parser;
|
||||||
|
@ -165,7 +176,7 @@ void ArtistBiography::FetchWikipediaImages(int id,
|
||||||
|
|
||||||
for (const QString& image_title : image_titles) {
|
for (const QString& image_title : image_titles) {
|
||||||
latch->Wait();
|
latch->Wait();
|
||||||
QUrl url(kWikipediaImageInfoUrl);
|
QUrl url(QString(kWikipediaImageInfoUrl).arg(language));
|
||||||
url.addQueryItem("titles", image_title);
|
url.addQueryItem("titles", image_title);
|
||||||
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
|
|
Loading…
Reference in New Issue