Add album effective_artist filter that falls back to artist when unavailable (Issue 509)

This commit is contained in:
Angus Gratton 2011-11-28 16:58:27 +11:00 committed by David Sansome
parent 92d2d644d0
commit edb9b0b4fe
8 changed files with 21 additions and 11 deletions

View File

@ -335,5 +335,6 @@
<file>icons/22x22/user-away.png</file> <file>icons/22x22/user-away.png</file>
<file>icons/32x32/search.png</file> <file>icons/32x32/search.png</file>
<file>schema/schema-35.sql</file> <file>schema/schema-35.sql</file>
<file>schema/schema-36.sql</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -0,0 +1,7 @@
ALTER TABLE %allsongstables ADD COLUMN effective_albumartist TEXT;
UPDATE %allsongstables SET effective_albumartist = albumartist;
UPDATE %allsongstables SET effective_albumartist = artist WHERE effective_albumartist = "";
UPDATE schema_version SET version=36;

View File

@ -33,7 +33,7 @@
#include <QVariant> #include <QVariant>
const char* Database::kDatabaseFilename = "clementine.db"; const char* Database::kDatabaseFilename = "clementine.db";
const int Database::kSchemaVersion = 35; const int Database::kSchemaVersion = 36;
const char* Database::kMagicAllSongsTables = "%allsongstables"; const char* Database::kMagicAllSongsTables = "%allsongstables";
int Database::sNextConnectionId = 1; int Database::sNextConnectionId = 1;

View File

@ -140,13 +140,11 @@ QString OrganiseFormat::TagValue(const QString &tag, const Song &song) const {
else if (tag == "samplerate") value = QString::number(song.samplerate()); else if (tag == "samplerate") value = QString::number(song.samplerate());
else if (tag == "extension") value = song.url().toLocalFile().section('.', -1, -1); else if (tag == "extension") value = song.url().toLocalFile().section('.', -1, -1);
else if (tag == "artistinitial") { else if (tag == "artistinitial") {
value = song.albumartist().trimmed(); value = song.effective_albumartist().trimmed();
if (value.isEmpty()) value = song.artist().trimmed();
if (!value.isEmpty()) value = value[0].toUpper(); if (!value.isEmpty()) value = value[0].toUpper();
} }
else if (tag == "albumartist") { else if (tag == "albumartist") {
value = song.albumartist(); value = song.is_compilation() ? "Various Artists" : song.effective_albumartist();
if (value.isEmpty()) value = song.artist();
} }
if (replace_the_ && (tag == "artist" || tag == "albumartist")) if (replace_the_ && (tag == "artist" || tag == "albumartist"))

View File

@ -105,7 +105,7 @@ const QStringList Song::kColumns = QStringList()
<< "art_manual" << "filetype" << "playcount" << "lastplayed" << "rating" << "art_manual" << "filetype" << "playcount" << "lastplayed" << "rating"
<< "forced_compilation_on" << "forced_compilation_off" << "forced_compilation_on" << "forced_compilation_off"
<< "effective_compilation" << "skipcount" << "score" << "beginning" << "length" << "effective_compilation" << "skipcount" << "score" << "beginning" << "length"
<< "cue_path" << "unavailable"; << "cue_path" << "unavailable" << "effective_albumartist";
const QString Song::kColumnSpec = Song::kColumns.join(", "); const QString Song::kColumnSpec = Song::kColumns.join(", ");
const QString Song::kBindSpec = Prepend(":", Song::kColumns).join(", "); const QString Song::kBindSpec = Prepend(":", Song::kColumns).join(", ");
@ -588,6 +588,8 @@ void Song::InitFromQuery(const SqlRow& q, bool reliable_metadata, int col) {
d->cue_path_ = tostr(col + 34); d->cue_path_ = tostr(col + 34);
d->unavailable_ = q.value(col + 35).toBool(); d->unavailable_ = q.value(col + 35).toBool();
// effective_albumartist = 36
#undef tostr #undef tostr
#undef toint #undef toint
#undef tolonglong #undef tolonglong
@ -1069,6 +1071,7 @@ void Song::BindToQuery(QSqlQuery *query) const {
query->bindValue(":cue_path", d->cue_path_); query->bindValue(":cue_path", d->cue_path_);
query->bindValue(":unavailable", d->unavailable_ ? 1 : 0); query->bindValue(":unavailable", d->unavailable_ ? 1 : 0);
query->bindValue(":effective_albumartist", this->effective_albumartist());
#undef intval #undef intval
#undef notnullintval #undef notnullintval

View File

@ -187,6 +187,7 @@ class Song {
const QString& album() const { return d->album_; } const QString& album() const { return d->album_; }
const QString& artist() const { return d->artist_; } const QString& artist() const { return d->artist_; }
const QString& albumartist() const { return d->albumartist_; } const QString& albumartist() const { return d->albumartist_; }
const QString& effective_albumartist() const { return d->albumartist_.isEmpty() ? d->artist_ : d->albumartist_; }
const QString& composer() const { return d->composer_; } const QString& composer() const { return d->composer_; }
int track() const { return d->track_; } int track() const { return d->track_; }
int disc() const { return d->disc_; } int disc() const { return d->disc_; }

View File

@ -174,7 +174,7 @@ void LibraryModel::SongsDiscovered(const SongList& songs) {
case GroupBy_Artist: key = song.artist(); break; case GroupBy_Artist: key = song.artist(); break;
case GroupBy_Composer: key = song.composer(); break; case GroupBy_Composer: key = song.composer(); break;
case GroupBy_Genre: key = song.genre(); break; case GroupBy_Genre: key = song.genre(); break;
case GroupBy_AlbumArtist: key = song.albumartist(); break; case GroupBy_AlbumArtist: key = song.effective_albumartist(); break;
case GroupBy_Year: case GroupBy_Year:
key = QString::number(qMax(0, song.year())); break; key = QString::number(qMax(0, song.year())); break;
case GroupBy_YearAlbum: case GroupBy_YearAlbum:
@ -700,7 +700,7 @@ void LibraryModel::InitQuery(GroupBy type, LibraryQuery* q) {
q->SetColumnSpec("DISTINCT genre"); q->SetColumnSpec("DISTINCT genre");
break; break;
case GroupBy_AlbumArtist: case GroupBy_AlbumArtist:
q->SetColumnSpec("DISTINCT albumartist"); q->SetColumnSpec("DISTINCT effective_albumartist");
break; break;
case GroupBy_None: case GroupBy_None:
q->SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec); q->SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec);
@ -742,7 +742,7 @@ void LibraryModel::FilterQuery(GroupBy type, LibraryItem* item, LibraryQuery* q)
q->AddWhere("genre", item->key); q->AddWhere("genre", item->key);
break; break;
case GroupBy_AlbumArtist: case GroupBy_AlbumArtist:
q->AddWhere("albumartist", item->key); q->AddWhere("effective_albumartist", item->key);
break; break;
case GroupBy_FileType: case GroupBy_FileType:
q->AddWhere("filetype", item->metadata.filetype()); q->AddWhere("filetype", item->metadata.filetype());
@ -854,7 +854,7 @@ LibraryItem* LibraryModel::ItemFromSong(GroupBy type,
case GroupBy_Composer: item->key = s.composer(); case GroupBy_Composer: item->key = s.composer();
case GroupBy_Genre: if (item->key.isNull()) item->key = s.genre(); case GroupBy_Genre: if (item->key.isNull()) item->key = s.genre();
case GroupBy_Album: if (item->key.isNull()) item->key = s.album(); case GroupBy_Album: if (item->key.isNull()) item->key = s.album();
case GroupBy_AlbumArtist: if (item->key.isNull()) item->key = s.albumartist(); case GroupBy_AlbumArtist: if (item->key.isNull()) item->key = s.effective_albumartist();
item->display_text = TextOrUnknown(item->key); item->display_text = TextOrUnknown(item->key);
item->sort_text = SortTextForArtist(item->key); item->sort_text = SortTextForArtist(item->key);
break; break;

View File

@ -322,7 +322,7 @@ QString OSD::ReplaceVariable(const QString& variable, const Song& song) {
} else if (variable == "%title%") { } else if (variable == "%title%") {
return song.PrettyTitle(); return song.PrettyTitle();
} else if (variable == "%albumartist%") { } else if (variable == "%albumartist%") {
return song.albumartist(); return song.effective_albumartist();
} else if (variable == "%year%") { } else if (variable == "%year%") {
return song.PrettyYear(); return song.PrettyYear();
} else if (variable == "%composer%") { } else if (variable == "%composer%") {