Add support for 'album artist' field in the LibraryBackendInterface
This commit is contained in:
parent
58b7c62f25
commit
deb7c33c64
|
@ -554,12 +554,17 @@ QStringList LibraryBackend::GetAllArtistsWithAlbums(const QueryOptions& opt) {
|
||||||
|
|
||||||
LibraryBackend::AlbumList LibraryBackend::GetAllAlbums(
|
LibraryBackend::AlbumList LibraryBackend::GetAllAlbums(
|
||||||
const QueryOptions& opt) {
|
const QueryOptions& opt) {
|
||||||
return GetAlbums(QString(), false, opt);
|
return GetAlbums(QString(), QString(), false, opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
LibraryBackend::AlbumList LibraryBackend::GetAlbumsByArtist(
|
LibraryBackend::AlbumList LibraryBackend::GetAlbumsByArtist(
|
||||||
const QString& artist, const QueryOptions& opt) {
|
const QString& artist, const QueryOptions& opt) {
|
||||||
return GetAlbums(artist, false, opt);
|
return GetAlbums(artist, QString(), false, opt);
|
||||||
|
}
|
||||||
|
|
||||||
|
LibraryBackend::AlbumList LibraryBackend::GetAlbumsByAlbumArtist(
|
||||||
|
const QString& album_artist, const QueryOptions& opt) {
|
||||||
|
return GetAlbums(QString(), album_artist, false, opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
SongList LibraryBackend::GetSongsByAlbum(const QString& album,
|
SongList LibraryBackend::GetSongsByAlbum(const QString& album,
|
||||||
|
@ -706,7 +711,7 @@ SongList LibraryBackend::GetSongsByUrl(const QUrl& url) {
|
||||||
|
|
||||||
LibraryBackend::AlbumList LibraryBackend::GetCompilationAlbums(
|
LibraryBackend::AlbumList LibraryBackend::GetCompilationAlbums(
|
||||||
const QueryOptions& opt) {
|
const QueryOptions& opt) {
|
||||||
return GetAlbums(QString(), true, opt);
|
return GetAlbums(QString(), QString(), true, opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
SongList LibraryBackend::GetCompilationSongs(const QString& album,
|
SongList LibraryBackend::GetCompilationSongs(const QString& album,
|
||||||
|
@ -844,18 +849,22 @@ void LibraryBackend::UpdateCompilations(QSqlQuery& find_songs,
|
||||||
}
|
}
|
||||||
|
|
||||||
LibraryBackend::AlbumList LibraryBackend::GetAlbums(const QString& artist,
|
LibraryBackend::AlbumList LibraryBackend::GetAlbums(const QString& artist,
|
||||||
|
const QString& album_artist,
|
||||||
bool compilation,
|
bool compilation,
|
||||||
const QueryOptions& opt) {
|
const QueryOptions& opt) {
|
||||||
AlbumList ret;
|
AlbumList ret;
|
||||||
|
|
||||||
LibraryQuery query(opt);
|
LibraryQuery query(opt);
|
||||||
query.SetColumnSpec(
|
query.SetColumnSpec(
|
||||||
"album, artist, compilation, sampler, art_automatic, "
|
"album, artist, albumartist, compilation, sampler, art_automatic, "
|
||||||
"art_manual, filename");
|
"art_manual, filename");
|
||||||
query.SetOrderBy("album");
|
query.SetOrderBy("album");
|
||||||
|
|
||||||
if (compilation) {
|
if (compilation) {
|
||||||
query.AddCompilationRequirement(true);
|
query.AddCompilationRequirement(true);
|
||||||
|
} else if (!album_artist.isNull()) {
|
||||||
|
query.AddCompilationRequirement(false);
|
||||||
|
query.AddWhere("albumartist", album_artist);
|
||||||
} else if (!artist.isNull()) {
|
} else if (!artist.isNull()) {
|
||||||
query.AddCompilationRequirement(false);
|
query.AddCompilationRequirement(false);
|
||||||
query.AddWhere("artist", artist);
|
query.AddWhere("artist", artist);
|
||||||
|
@ -863,39 +872,51 @@ LibraryBackend::AlbumList LibraryBackend::GetAlbums(const QString& artist,
|
||||||
|
|
||||||
QMutexLocker l(db_->Mutex());
|
QMutexLocker l(db_->Mutex());
|
||||||
if (!ExecQuery(&query)) return ret;
|
if (!ExecQuery(&query)) return ret;
|
||||||
|
l.unlock();
|
||||||
|
|
||||||
QString last_album;
|
QString last_album;
|
||||||
QString last_artist;
|
QString last_artist, last_album_artist;
|
||||||
while (query.Next()) {
|
while (query.Next()) {
|
||||||
bool compilation = query.Value(2).toBool() | query.Value(3).toBool();
|
bool compilation = query.Value(3).toBool() | query.Value(4).toBool();
|
||||||
|
|
||||||
Album info;
|
Album info;
|
||||||
info.artist = compilation ? QString() : query.Value(1).toString();
|
info.artist = compilation ? QString() : query.Value(1).toString();
|
||||||
|
info.album_artist = compilation ? QString() : query.Value(2).toString();
|
||||||
info.album_name = query.Value(0).toString();
|
info.album_name = query.Value(0).toString();
|
||||||
info.art_automatic = query.Value(4).toString();
|
info.art_automatic = query.Value(5).toString();
|
||||||
info.art_manual = query.Value(5).toString();
|
info.art_manual = query.Value(6).toString();
|
||||||
info.first_url = QUrl::fromEncoded(query.Value(6).toByteArray());
|
info.first_url = QUrl::fromEncoded(query.Value(7).toByteArray());
|
||||||
|
|
||||||
if (info.artist == last_artist && info.album_name == last_album) continue;
|
if ((info.artist == last_artist ||
|
||||||
|
info.album_artist == last_album_artist) &&
|
||||||
|
info.album_name == last_album)
|
||||||
|
continue;
|
||||||
|
|
||||||
ret << info;
|
ret << info;
|
||||||
|
|
||||||
last_album = info.album_name;
|
last_album = info.album_name;
|
||||||
last_artist = info.artist;
|
last_artist = info.artist;
|
||||||
|
last_album_artist = info.album_artist;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
LibraryBackend::Album LibraryBackend::GetAlbumArt(const QString& artist,
|
LibraryBackend::Album LibraryBackend::GetAlbumArt(const QString& artist,
|
||||||
|
const QString& albumartist,
|
||||||
const QString& album) {
|
const QString& album) {
|
||||||
Album ret;
|
Album ret;
|
||||||
ret.album_name = album;
|
ret.album_name = album;
|
||||||
ret.artist = artist;
|
ret.artist = artist;
|
||||||
|
ret.album_artist = albumartist;
|
||||||
|
|
||||||
LibraryQuery query = LibraryQuery(QueryOptions());
|
LibraryQuery query = LibraryQuery(QueryOptions());
|
||||||
query.SetColumnSpec("art_automatic, art_manual, filename");
|
query.SetColumnSpec("art_automatic, art_manual, filename");
|
||||||
query.AddWhere("artist", artist);
|
if (!albumartist.isEmpty()) {
|
||||||
|
query.AddWhere("albumartist", albumartist);
|
||||||
|
} else if (!artist.isEmpty()) {
|
||||||
|
query.AddWhere("artist", artist);
|
||||||
|
}
|
||||||
query.AddWhere("album", album);
|
query.AddWhere("album", album);
|
||||||
|
|
||||||
QMutexLocker l(db_->Mutex());
|
QMutexLocker l(db_->Mutex());
|
||||||
|
@ -911,14 +932,17 @@ LibraryBackend::Album LibraryBackend::GetAlbumArt(const QString& artist,
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryBackend::UpdateManualAlbumArtAsync(const QString& artist,
|
void LibraryBackend::UpdateManualAlbumArtAsync(const QString& artist,
|
||||||
|
const QString& albumartist,
|
||||||
const QString& album,
|
const QString& album,
|
||||||
const QString& art) {
|
const QString& art) {
|
||||||
metaObject()->invokeMethod(this, "UpdateManualAlbumArt", Qt::QueuedConnection,
|
metaObject()->invokeMethod(this, "UpdateManualAlbumArt", Qt::QueuedConnection,
|
||||||
Q_ARG(QString, artist), Q_ARG(QString, album),
|
Q_ARG(QString, artist),
|
||||||
|
Q_ARG(QString, albumartist), Q_ARG(QString, album),
|
||||||
Q_ARG(QString, art));
|
Q_ARG(QString, art));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryBackend::UpdateManualAlbumArt(const QString& artist,
|
void LibraryBackend::UpdateManualAlbumArt(const QString& artist,
|
||||||
|
const QString& albumartist,
|
||||||
const QString& album,
|
const QString& album,
|
||||||
const QString& art) {
|
const QString& art) {
|
||||||
QMutexLocker l(db_->Mutex());
|
QMutexLocker l(db_->Mutex());
|
||||||
|
@ -928,7 +952,12 @@ void LibraryBackend::UpdateManualAlbumArt(const QString& artist,
|
||||||
LibraryQuery query;
|
LibraryQuery query;
|
||||||
query.SetColumnSpec("ROWID, " + Song::kColumnSpec);
|
query.SetColumnSpec("ROWID, " + Song::kColumnSpec);
|
||||||
query.AddWhere("album", album);
|
query.AddWhere("album", album);
|
||||||
if (!artist.isNull()) query.AddWhere("artist", artist);
|
|
||||||
|
if (!albumartist.isNull()) {
|
||||||
|
query.AddWhere("albumartist", albumartist);
|
||||||
|
} else if (!artist.isNull()) {
|
||||||
|
query.AddWhere("artist", artist);
|
||||||
|
}
|
||||||
|
|
||||||
if (!ExecQuery(&query)) return;
|
if (!ExecQuery(&query)) return;
|
||||||
|
|
||||||
|
@ -944,12 +973,20 @@ void LibraryBackend::UpdateManualAlbumArt(const QString& artist,
|
||||||
QString(
|
QString(
|
||||||
"UPDATE %1 SET art_manual = :art"
|
"UPDATE %1 SET art_manual = :art"
|
||||||
" WHERE album = :album AND unavailable = 0").arg(songs_table_));
|
" WHERE album = :album AND unavailable = 0").arg(songs_table_));
|
||||||
if (!artist.isNull()) sql += " AND artist = :artist";
|
if (!albumartist.isNull()) {
|
||||||
|
sql += " AND albumartist = :albumartist";
|
||||||
|
} else if (!artist.isNull()) {
|
||||||
|
sql += " AND artist = :artist";
|
||||||
|
}
|
||||||
|
|
||||||
QSqlQuery q(sql, db);
|
QSqlQuery q(sql, db);
|
||||||
q.bindValue(":art", art);
|
q.bindValue(":art", art);
|
||||||
q.bindValue(":album", album);
|
q.bindValue(":album", album);
|
||||||
if (!artist.isNull()) q.bindValue(":artist", artist);
|
if (!albumartist.isNull()) {
|
||||||
|
q.bindValue(":albumartist", albumartist);
|
||||||
|
} else if (!artist.isNull()) {
|
||||||
|
q.bindValue(":artist", artist);
|
||||||
|
}
|
||||||
|
|
||||||
q.exec();
|
q.exec();
|
||||||
db_->CheckErrors(q);
|
db_->CheckErrors(q);
|
||||||
|
|
|
@ -41,16 +41,22 @@ class LibraryBackendInterface : public QObject {
|
||||||
|
|
||||||
struct Album {
|
struct Album {
|
||||||
Album() {}
|
Album() {}
|
||||||
Album(const QString& _artist, const QString& _album_name,
|
Album(const QString& _artist, const QString& _album_artist,
|
||||||
const QString& _art_automatic, const QString& _art_manual,
|
const QString& _album_name, const QString& _art_automatic,
|
||||||
const QUrl& _first_url)
|
const QString& _art_manual, const QUrl& _first_url)
|
||||||
: artist(_artist),
|
: artist(_artist),
|
||||||
|
album_artist(_album_artist),
|
||||||
album_name(_album_name),
|
album_name(_album_name),
|
||||||
art_automatic(_art_automatic),
|
art_automatic(_art_automatic),
|
||||||
art_manual(_art_manual),
|
art_manual(_art_manual),
|
||||||
first_url(_first_url) {}
|
first_url(_first_url) {}
|
||||||
|
|
||||||
|
const QString& effective_albumartist() const {
|
||||||
|
return album_artist.isEmpty() ? artist : album_artist;
|
||||||
|
}
|
||||||
|
|
||||||
QString artist;
|
QString artist;
|
||||||
|
QString album_artist;
|
||||||
QString album_name;
|
QString album_name;
|
||||||
|
|
||||||
QString art_automatic;
|
QString art_automatic;
|
||||||
|
@ -92,9 +98,11 @@ class LibraryBackendInterface : public QObject {
|
||||||
const QueryOptions& opt = QueryOptions()) = 0;
|
const QueryOptions& opt = QueryOptions()) = 0;
|
||||||
|
|
||||||
virtual void UpdateManualAlbumArtAsync(const QString& artist,
|
virtual void UpdateManualAlbumArtAsync(const QString& artist,
|
||||||
|
const QString& albumartist,
|
||||||
const QString& album,
|
const QString& album,
|
||||||
const QString& art) = 0;
|
const QString& art) = 0;
|
||||||
virtual Album GetAlbumArt(const QString& artist, const QString& album) = 0;
|
virtual Album GetAlbumArt(const QString& artist, const QString& albumartist,
|
||||||
|
const QString& album) = 0;
|
||||||
|
|
||||||
virtual Song GetSongById(int id) = 0;
|
virtual Song GetSongById(int id) = 0;
|
||||||
|
|
||||||
|
@ -157,11 +165,15 @@ class LibraryBackend : public LibraryBackendInterface {
|
||||||
AlbumList GetAllAlbums(const QueryOptions& opt = QueryOptions());
|
AlbumList GetAllAlbums(const QueryOptions& opt = QueryOptions());
|
||||||
AlbumList GetAlbumsByArtist(const QString& artist,
|
AlbumList GetAlbumsByArtist(const QString& artist,
|
||||||
const QueryOptions& opt = QueryOptions());
|
const QueryOptions& opt = QueryOptions());
|
||||||
|
AlbumList GetAlbumsByAlbumArtist(const QString& albumartist,
|
||||||
|
const QueryOptions& opt = QueryOptions());
|
||||||
AlbumList GetCompilationAlbums(const QueryOptions& opt = QueryOptions());
|
AlbumList GetCompilationAlbums(const QueryOptions& opt = QueryOptions());
|
||||||
|
|
||||||
void UpdateManualAlbumArtAsync(const QString& artist, const QString& album,
|
void UpdateManualAlbumArtAsync(const QString& artist,
|
||||||
const QString& art);
|
const QString& albumartist,
|
||||||
Album GetAlbumArt(const QString& artist, const QString& album);
|
const QString& album, const QString& art);
|
||||||
|
Album GetAlbumArt(const QString& artist, const QString& albumartist,
|
||||||
|
const QString& album);
|
||||||
|
|
||||||
Song GetSongById(int id);
|
Song GetSongById(int id);
|
||||||
SongList GetSongsById(const QList<int>& ids);
|
SongList GetSongsById(const QList<int>& ids);
|
||||||
|
@ -197,8 +209,8 @@ class LibraryBackend : public LibraryBackendInterface {
|
||||||
void MarkSongsUnavailable(const SongList& songs, bool unavailable = true);
|
void MarkSongsUnavailable(const SongList& songs, bool unavailable = true);
|
||||||
void AddOrUpdateSubdirs(const SubdirectoryList& subdirs);
|
void AddOrUpdateSubdirs(const SubdirectoryList& subdirs);
|
||||||
void UpdateCompilations();
|
void UpdateCompilations();
|
||||||
void UpdateManualAlbumArt(const QString& artist, const QString& album,
|
void UpdateManualAlbumArt(const QString& artist, const QString& albumartist,
|
||||||
const QString& art);
|
const QString& album, const QString& art);
|
||||||
void ForceCompilation(const QString& album, const QList<QString>& artists,
|
void ForceCompilation(const QString& album, const QList<QString>& artists,
|
||||||
bool on);
|
bool on);
|
||||||
void IncrementPlayCount(int id);
|
void IncrementPlayCount(int id);
|
||||||
|
@ -236,7 +248,8 @@ signals:
|
||||||
void UpdateCompilations(QSqlQuery& find_songs, QSqlQuery& update,
|
void UpdateCompilations(QSqlQuery& find_songs, QSqlQuery& update,
|
||||||
SongList& deleted_songs, SongList& added_songs,
|
SongList& deleted_songs, SongList& added_songs,
|
||||||
const QString& album, int sampler);
|
const QString& album, int sampler);
|
||||||
AlbumList GetAlbums(const QString& artist, bool compilation = false,
|
AlbumList GetAlbums(const QString& artist, const QString& album_artist,
|
||||||
|
bool compilation = false,
|
||||||
const QueryOptions& opt = QueryOptions());
|
const QueryOptions& opt = QueryOptions());
|
||||||
SubdirectoryList SubdirsInDirectory(int id, QSqlDatabase& db);
|
SubdirectoryList SubdirsInDirectory(int id, QSqlDatabase& db);
|
||||||
|
|
||||||
|
|
|
@ -424,8 +424,8 @@ bool AlbumCoverManager::ShouldHide(const QListWidgetItem& item,
|
||||||
QStringList query = filter.split(' ');
|
QStringList query = filter.split(' ');
|
||||||
for (const QString& s : query) {
|
for (const QString& s : query) {
|
||||||
if (!item.text().contains(s, Qt::CaseInsensitive) &&
|
if (!item.text().contains(s, Qt::CaseInsensitive) &&
|
||||||
!item.data(Role_ArtistName).toString().contains(
|
!item.data(Role_ArtistName).toString().contains(
|
||||||
s, Qt::CaseInsensitive),
|
s, Qt::CaseInsensitive) &&
|
||||||
!item.data(Role_AlbumArtistName).toString().contains(
|
!item.data(Role_AlbumArtistName).toString().contains(
|
||||||
s, Qt::CaseInsensitive)) {
|
s, Qt::CaseInsensitive)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -578,9 +578,8 @@ void AlbumCoverManager::ShowCover() {
|
||||||
|
|
||||||
void AlbumCoverManager::FetchSingleCover() {
|
void AlbumCoverManager::FetchSingleCover() {
|
||||||
for (QListWidgetItem* item : context_menu_items_) {
|
for (QListWidgetItem* item : context_menu_items_) {
|
||||||
QString artist_name = EffectiveAlbumArtistName(item);
|
|
||||||
quint64 id = cover_fetcher_->FetchAlbumCover(
|
quint64 id = cover_fetcher_->FetchAlbumCover(
|
||||||
artist_name, item->data(Role_AlbumName).toString());
|
EffectiveAlbumArtistName(item), item->data(Role_AlbumName).toString());
|
||||||
cover_fetching_tasks_[id] = item;
|
cover_fetching_tasks_[id] = item;
|
||||||
jobs_++;
|
jobs_++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue