diff options
author | Arno <arno@disconnect.de> | 2017-12-01 03:12:35 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2017-12-01 03:12:35 +0100 |
commit | 3cda8abf5e056b91a81497cf698470dfac607c6f (patch) | |
tree | a7a331be0ebfb5a3ba143c95dd413f65597faffe | |
parent | 8b611b7c69b50bf2f252903a849dd41ed685fece (diff) | |
download | BeetPlayer-3cda8abf5e056b91a81497cf698470dfac607c6f.tar.gz BeetPlayer-3cda8abf5e056b91a81497cf698470dfac607c6f.tar.bz2 BeetPlayer-3cda8abf5e056b91a81497cf698470dfac607c6f.zip |
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 :(
-rw-r--r-- | playerwidget.cpp | 19 | ||||
-rw-r--r-- | webdownloader.cpp | 27 | ||||
-rw-r--r-- | webdownloader.h | 5 |
3 files changed, 41 insertions, 10 deletions
diff --git a/playerwidget.cpp b/playerwidget.cpp index 366ca78..0fb97ed 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -1483,13 +1483,20 @@ void PlayerWidget::webDlDone(){ text.append(QString("<tr><td style=\"padding-left: 30px\">Album</td><td style=\"padding-left: 30px\"><a href=\"https://musicbrainz.org/release-group/%1\">%2</a></td></tr>").arg(alId).arg(mWebDownloader->album())); } text.append("</table>"); - const QMap<QString, QString> other = mWebDownloader->otherData(); + QList<QList<QVariant> > other = mWebDownloader->otherData(); + std::sort(other.begin(), other.end(), [](auto a, auto b){ + return a.at(2).toInt() < b.at(2).toInt(); + }); text.append(QString(tr("<b>All Albums (%1):</b><ul>")).arg(QString::number(other.count()))); - QStringList albums = other.values(); - std::sort(albums.begin(), albums.end()); - foreach(QString a, albums){ - QString id = other.key(a); - text.append(QString("<li><a href=\"https://musicbrainz.org/release-group/%1\">%2</a></li>").arg(id).arg(a)); + foreach(const QVariant vl, other){ + QVariantList cur = vl.toList(); + QString id = cur.at(0).toString(); + QString album = cur.at(1).toString(); + QString year = cur.at(2).toString(); + if(year == "-1"){ + year = "nota"; + } + text.append(QString("<li>%1: <a href=\"https://musicbrainz.org/release-group/%2\">%3</a></li>").arg(year).arg(id).arg(album)); } text.append("</ul>"); }else{ diff --git a/webdownloader.cpp b/webdownloader.cpp index 78941fb..3003ad9 100644 --- a/webdownloader.cpp +++ b/webdownloader.cpp @@ -3,6 +3,7 @@ #include <QJsonDocument> #include <QJsonObject> #include <QJsonArray> +#include <QRegularExpression> #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); + } + } } } }); diff --git a/webdownloader.h b/webdownloader.h index f07ed52..353bd5a 100644 --- a/webdownloader.h +++ b/webdownloader.h @@ -4,6 +4,7 @@ #include <QObject> #include <QNetworkAccessManager> #include <QMap> +#include <QVariant> class WebDownloader : public QObject { Q_OBJECT @@ -14,7 +15,7 @@ class WebDownloader : public QObject { const QString artist() const { return mArtist; } const QString artistId() const { return mArtistId; } const QStringList data() const { return mData; } - const QMap<QString, QString> otherData() const { return mOtherData; } + const QList<QList<QVariant> > otherData() const { return mOtherData; } const QMap<QString, QString> alternateArtists() const { return mAlternateArtists; } signals: @@ -29,7 +30,7 @@ class WebDownloader : public QObject { QString mAlbum; QString mArtistId; QStringList mData; - QMap<QString, QString> mOtherData; + QList<QList<QVariant> > mOtherData; QMap<QString, QString> mAlternateArtists; }; |