Scrobbler: Allow album artists to be "Various Artists"

Fixes #1082
This commit is contained in:
Jonas Kvinge 2022-12-27 21:15:20 +01:00
parent fee63891ac
commit fac4ad5313
6 changed files with 20 additions and 22 deletions

View File

@ -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 ";

View File

@ -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;

View File

@ -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 {

View File

@ -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<ScrobblerCacheItem>(song.artist(), album, title, song.albumartist(), song.track(), song.length_nanosec(), timestamp);

View File

@ -28,15 +28,13 @@
#include <QObject>
#include <QString>
#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_;

View File

@ -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); });