From 3cda8abf5e056b91a81497cf698470dfac607c6f Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 1 Dec 2017 03:12:35 +0100 Subject: Improve Musicbrainz-Search Filter out Live albums and compilations. Sort the resulting album list by release year. Unfortunately, musicbrainz does not always agree with the release year from the file metadata :( --- webdownloader.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'webdownloader.cpp') diff --git a/webdownloader.cpp b/webdownloader.cpp index 78941fb..3003ad9 100644 --- a/webdownloader.cpp +++ b/webdownloader.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "webdownloader.h" @@ -28,6 +29,7 @@ void WebDownloader::dlFinished(QNetworkReply *reply){ mOtherData.clear(); mArtistId.clear(); mAlternateArtists.clear(); + QRegularExpression yearRE("(\\d{4})"); QByteArray res = reply->readAll(); QJsonDocument jDoc = QJsonDocument::fromJson(res); QJsonObject docObj = jDoc.object(); @@ -44,15 +46,36 @@ void WebDownloader::dlFinished(QNetworkReply *reply){ } QString aId = titleRes.toObject().value("artist-credit").toArray().at(0).toObject().value("artist").toObject().value("id").toString(); mArtistId = aId; - std::for_each(relArr.constBegin(), relArr.constEnd(), [this, aId](auto c){ + std::for_each(relArr.constBegin(), relArr.constEnd(), [this, aId, yearRE](auto c){ QString id = c.toObject().value("artist-credit").toArray().at(0).toObject().value("artist").toObject().value("id").toString(); QString linkId = c.toObject().value("release-group").toObject().value("id").toString(); QString title = c.toObject().value("title").toString().toLower(); if(id == aId){ QString primary = c.toObject().value("release-group").toObject().value("primary-type").toString().toLower(); + auto secondary = c.toObject().value("release-group").toObject().value("secondary-types").toArray(); + if(secondary.count()){ + return; + } QString status = c.toObject().value("status").toString().toLower(); if(primary == "album" && status == "official"){ - mOtherData.insert(linkId, title); + QString date = c.toObject().value("date").toString(); + int year = -1; + QRegularExpressionMatch match = yearRE.match(date); + if(match.hasMatch()){ + year = match.captured(0).toInt(); + }else{ + qDebug() << date; + } + auto otherIt = mOtherData.constEnd(); + if(year != -1){ + otherIt = std::find_if(mOtherData.constBegin(), mOtherData.constEnd(), [linkId](auto c){ + return c.at(0).toString() == linkId; + }); + if(otherIt == mOtherData.constEnd()){ + QVariantList cur = QVariantList() << linkId << title << year; + mOtherData.append(cur); + } + } } } }); -- cgit v1.2.3-70-g09d2