From fac4ad5313a2af3f72a58bc71d039bfac9106974 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 27 Dec 2022 21:15:20 +0100 Subject: [PATCH] Scrobbler: Allow album artists to be "Various Artists" Fixes #1082 --- src/core/song.cpp | 1 - src/core/song.h | 2 -- src/scrobbler/listenbrainzscrobbler.cpp | 11 ++++++----- src/scrobbler/scrobblercache.cpp | 4 ++-- src/scrobbler/scrobblercacheitem.h | 4 +--- src/scrobbler/scrobblingapi20.cpp | 20 +++++++++++--------- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/core/song.cpp b/src/core/song.cpp index d8312b455..9ff45d8be 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -146,7 +146,6 @@ const QString Song::kEmbeddedCover = "(embedded)"; const QRegularExpression Song::kAlbumRemoveDisc(" ?-? ((\\(|\\[)?)(Disc|CD) ?([0-9]{1,2})((\\)|\\])?)$", QRegularExpression::CaseInsensitiveOption); const QRegularExpression Song::kAlbumRemoveMisc(" ?-? ((\\(|\\[)?)(Remastered|([0-9]{1,4}) *Remaster|Explicit) ?((\\)|\\])?)$", QRegularExpression::CaseInsensitiveOption); const QRegularExpression Song::kTitleRemoveMisc(" ?-? ((\\(|\\[)?)(Remastered|Remastered Version|([0-9]{1,4}) *Remaster) ?((\\)|\\])?)$", QRegularExpression::CaseInsensitiveOption); -const QString Song::kVariousArtists("various artists"); const QStringList Song::kArticles = QStringList() << "the " << "a " << "an "; diff --git a/src/core/song.h b/src/core/song.h index aab043fc2..441f4c734 100644 --- a/src/core/song.h +++ b/src/core/song.h @@ -132,8 +132,6 @@ class Song { static const QRegularExpression kAlbumRemoveMisc; static const QRegularExpression kTitleRemoveMisc; - static const QString kVariousArtists; - static const QStringList kArticles; static const QStringList kAcceptedExtensions; diff --git a/src/scrobbler/listenbrainzscrobbler.cpp b/src/scrobbler/listenbrainzscrobbler.cpp index 59788cbfa..41dd8e88d 100644 --- a/src/scrobbler/listenbrainzscrobbler.cpp +++ b/src/scrobbler/listenbrainzscrobbler.cpp @@ -430,20 +430,21 @@ void ListenBrainzScrobbler::UpdateNowPlaying(const Song &song) { QString album = song.album(); QString title = song.title(); - album = album.remove(Song::kAlbumRemoveDisc); - album = album.remove(Song::kAlbumRemoveMisc); + album = album.remove(Song::kAlbumRemoveDisc) + .remove(Song::kAlbumRemoveMisc); title = title.remove(Song::kTitleRemoveMisc); QJsonObject object_track_metadata; - if (!prefer_albumartist_ || song.albumartist().isEmpty() || song.albumartist().compare(Song::kVariousArtists, Qt::CaseInsensitive) == 0) { + if (!prefer_albumartist_ || song.albumartist().isEmpty()) { object_track_metadata.insert("artist_name", QJsonValue::fromVariant(song.artist())); } else { object_track_metadata.insert("artist_name", QJsonValue::fromVariant(song.albumartist())); } - if (!album.isEmpty()) + if (!album.isEmpty()) { object_track_metadata.insert("release_name", QJsonValue::fromVariant(album)); + } object_track_metadata.insert("track_name", QJsonValue::fromVariant(title)); @@ -573,7 +574,7 @@ void ListenBrainzScrobbler::Submit() { QJsonObject object_listen; object_listen.insert("listened_at", QJsonValue::fromVariant(item->timestamp_)); QJsonObject object_track_metadata; - if (!prefer_albumartist_ || item->albumartist_.isEmpty() || item->albumartist_.compare(Song::kVariousArtists, Qt::CaseInsensitive) == 0) { + if (!prefer_albumartist_ || item->albumartist_.isEmpty()) { object_track_metadata.insert("artist_name", QJsonValue::fromVariant(item->artist_)); } else { diff --git a/src/scrobbler/scrobblercache.cpp b/src/scrobbler/scrobblercache.cpp index b540b9748..1e207395a 100644 --- a/src/scrobbler/scrobblercache.cpp +++ b/src/scrobbler/scrobblercache.cpp @@ -205,8 +205,8 @@ ScrobblerCacheItemPtr ScrobblerCache::Add(const Song &song, const quint64 timest QString album = song.album(); QString title = song.title(); - album.remove(Song::kAlbumRemoveDisc); - album.remove(Song::kAlbumRemoveMisc); + album.remove(Song::kAlbumRemoveDisc) + .remove(Song::kAlbumRemoveMisc); title.remove(Song::kTitleRemoveMisc); ScrobblerCacheItemPtr item = std::make_shared(song.artist(), album, title, song.albumartist(), song.track(), song.length_nanosec(), timestamp); diff --git a/src/scrobbler/scrobblercacheitem.h b/src/scrobbler/scrobblercacheitem.h index 52d9497eb..3a3514bb5 100644 --- a/src/scrobbler/scrobblercacheitem.h +++ b/src/scrobbler/scrobblercacheitem.h @@ -28,15 +28,13 @@ #include #include -#include "core/song.h" - class ScrobblerCacheItem : public QObject { Q_OBJECT public: explicit ScrobblerCacheItem(const QString &artist, const QString &album, const QString &song, const QString &albumartist, const int track, const qint64 duration, const quint64 timestamp, QObject *parent = nullptr); - QString effective_albumartist() const { return albumartist_.isEmpty() || albumartist_.compare(Song::kVariousArtists, Qt::CaseInsensitive) == 0 ? artist_ : albumartist_; } + QString effective_albumartist() const { return albumartist_.isEmpty() ? artist_ : albumartist_; } public: QString artist_; diff --git a/src/scrobbler/scrobblingapi20.cpp b/src/scrobbler/scrobblingapi20.cpp index 7b18aa08e..367bc47fe 100644 --- a/src/scrobbler/scrobblingapi20.cpp +++ b/src/scrobbler/scrobblingapi20.cpp @@ -454,20 +454,20 @@ void ScrobblingAPI20::UpdateNowPlaying(const Song &song) { QString album = song.album(); QString title = song.title(); - album = album.remove(Song::kAlbumRemoveDisc); - album = album.remove(Song::kAlbumRemoveMisc); + album = album.remove(Song::kAlbumRemoveDisc) + .remove(Song::kAlbumRemoveMisc); title = title.remove(Song::kTitleRemoveMisc); ParamList params = ParamList() << Param("method", "track.updateNowPlaying") - << Param("artist", prefer_albumartist_ && song.effective_albumartist() != Song::kVariousArtists ? song.effective_albumartist() : song.artist()) + << Param("artist", prefer_albumartist_ ? song.effective_albumartist() : song.artist()) << Param("track", title); if (!album.isEmpty()) { params << Param("album", album); } - if (!prefer_albumartist_ && !song.albumartist().isEmpty() && song.albumartist().compare(Song::kVariousArtists, Qt::CaseInsensitive) != 0) { + if (!prefer_albumartist_ && !song.albumartist().isEmpty()) { params << Param("albumArtist", song.albumartist()); } @@ -582,7 +582,7 @@ void ScrobblingAPI20::Submit() { if (!item->album_.isEmpty()) { params << Param(QString("%1[%2]").arg("album").arg(i), item->album_); } - if (!prefer_albumartist_ && !item->albumartist_.isEmpty() && item->albumartist_.compare(Song::kVariousArtists, Qt::CaseInsensitive) != 0) { + if (!prefer_albumartist_ && !item->albumartist_.isEmpty()) { params << Param(QString("%1[%2]").arg("albumArtist").arg(i), item->albumartist_); } if (item->track_ > 0) { @@ -790,7 +790,7 @@ void ScrobblingAPI20::SendSingleScrobble(ScrobblerCacheItemPtr item) { if (!item->album_.isEmpty()) { params << Param("album", item->album_); } - if (!prefer_albumartist_ && !item->albumartist_.isEmpty() && item->albumartist_.compare(Song::kVariousArtists, Qt::CaseInsensitive) != 0) { + if (!prefer_albumartist_ && !item->albumartist_.isEmpty()) { params << Param("albumArtist", item->albumartist_); } if (item->track_ > 0) { @@ -939,14 +939,16 @@ void ScrobblingAPI20::Love() { ParamList params = ParamList() << Param("method", "track.love") - << Param("artist", prefer_albumartist_ && song_playing_.effective_albumartist() != Song::kVariousArtists ? song_playing_.effective_albumartist() : song_playing_.artist()) + << Param("artist", prefer_albumartist_ ? song_playing_.effective_albumartist() : song_playing_.artist()) << Param("track", song_playing_.title()); - if (!song_playing_.album().isEmpty()) + if (!song_playing_.album().isEmpty()) { params << Param("album", song_playing_.album()); + } - if (!prefer_albumartist_ && !song_playing_.albumartist().isEmpty() && song_playing_.albumartist().compare(Song::kVariousArtists, Qt::CaseInsensitive) != 0) + if (!prefer_albumartist_ && !song_playing_.albumartist().isEmpty()) { params << Param("albumArtist", song_playing_.albumartist()); + } QNetworkReply *reply = CreateRequest(params); QObject::connect(reply, &QNetworkReply::finished, this, [this, reply] { LoveRequestFinished(reply); });