From 8afae4a41be8648a587ef598c34777d0341907a3 Mon Sep 17 00:00:00 2001 From: chme Date: Sat, 22 Aug 2020 12:59:36 +0200 Subject: [PATCH] [db] Fetch additional metadata for artist and album in group query --- src/db.c | 8 ++++++-- src/db.h | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/db.c b/src/db.c index 8635d010..918e4c5c 100644 --- a/src/db.c +++ b/src/db.c @@ -398,6 +398,10 @@ static const ssize_t dbgri_cols_map[] = dbgri_offsetof(songalbumartist), dbgri_offsetof(songartistid), dbgri_offsetof(song_length), + dbgri_offsetof(data_kind), + dbgri_offsetof(media_kind), + dbgri_offsetof(year), + dbgri_offsetof(date_released), }; /* This list must be kept in sync with @@ -1903,7 +1907,7 @@ db_build_query_group_albums(struct query_params *qp, struct query_clause *qc) char *query; count = sqlite3_mprintf("SELECT COUNT(DISTINCT f.songalbumid) FROM files f %s;", qc->where); - query = sqlite3_mprintf("SELECT g.id, g.persistentid, f.album, f.album_sort, COUNT(f.id) as track_count, 1 as album_count, f.album_artist, f.songartistid, SUM(f.song_length) FROM files f JOIN groups g ON f.songalbumid = g.persistentid %s GROUP BY f.songalbumid %s %s %s;", qc->where, qc->having, qc->order, qc->index); + query = sqlite3_mprintf("SELECT g.id, g.persistentid, f.album, f.album_sort, COUNT(f.id) as track_count, 1 as album_count, f.album_artist, f.songartistid, SUM(f.song_length), MIN(f.data_kind), MIN(f.media_kind), MAX(f.year), MAX(f.date_released) FROM files f JOIN groups g ON f.songalbumid = g.persistentid %s GROUP BY f.songalbumid %s %s %s;", qc->where, qc->having, qc->order, qc->index); return db_build_query_check(qp, count, query); } @@ -1915,7 +1919,7 @@ db_build_query_group_artists(struct query_params *qp, struct query_clause *qc) char *query; count = sqlite3_mprintf("SELECT COUNT(DISTINCT f.songartistid) FROM files f %s;", qc->where); - query = sqlite3_mprintf("SELECT g.id, g.persistentid, f.album_artist, f.album_artist_sort, COUNT(f.id) as track_count, COUNT(DISTINCT f.songalbumid) as album_count, f.album_artist, f.songartistid, SUM(f.song_length) FROM files f JOIN groups g ON f.songartistid = g.persistentid %s GROUP BY f.songartistid %s %s %s;", qc->where, qc->having, qc->order, qc->index); + query = sqlite3_mprintf("SELECT g.id, g.persistentid, f.album_artist, f.album_artist_sort, COUNT(f.id) as track_count, COUNT(DISTINCT f.songalbumid) as album_count, f.album_artist, f.songartistid, SUM(f.song_length), MIN(f.data_kind), MIN(f.media_kind), MAX(f.year), MAX(f.date_released) FROM files f JOIN groups g ON f.songartistid = g.persistentid %s GROUP BY f.songartistid %s %s %s;", qc->where, qc->having, qc->order, qc->index); return db_build_query_check(qp, count, query); } diff --git a/src/db.h b/src/db.h index 50f6dd97..4dec849c 100644 --- a/src/db.h +++ b/src/db.h @@ -297,6 +297,10 @@ struct group_info { char *songalbumartist; /* song album artist (asaa) */ uint64_t songartistid; /* song artist id (asri) */ uint32_t song_length; + uint32_t data_kind; + uint32_t media_kind; + uint32_t year; + uint32_t date_released; }; #define gri_offsetof(field) offsetof(struct group_info, field) @@ -311,6 +315,10 @@ struct db_group_info { char *songalbumartist; char *songartistid; char *song_length; + char *data_kind; + char *media_kind; + char *year; + char *date_released; }; #define dbgri_offsetof(field) offsetof(struct db_group_info, field)