From ecc139641ab3df1401539fda479d2c53e129e7e4 Mon Sep 17 00:00:00 2001 From: chme Date: Mon, 4 Apr 2022 20:51:14 +0200 Subject: [PATCH 1/2] [spotify] Respect `album_override` setting when parsing Spotify tracks --- src/library/spotify_webapi.c | 41 ++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/library/spotify_webapi.c b/src/library/spotify_webapi.c index 84e80c09..726bada0 100644 --- a/src/library/spotify_webapi.c +++ b/src/library/spotify_webapi.c @@ -1561,15 +1561,18 @@ map_track_to_mfi(struct media_file_info *mfi, const struct spotify_track *track, else { mfi->album_artist = safe_strdup(track->album_artist); - if (cfg_getbool(cfg_getsec(cfg, "spotify"), "album_override") && pl_name) - mfi->album = safe_strdup(pl_name); - else - mfi->album = safe_strdup(track->album); + mfi->album = safe_strdup(track->album); + mfi->compilation = track->is_compilation; + } - if (cfg_getbool(cfg_getsec(cfg, "spotify"), "artist_override") && pl_name) - mfi->compilation = true; - else - mfi->compilation = track->is_compilation; + if (cfg_getbool(cfg_getsec(cfg, "spotify"), "album_override") && pl_name) + { + free(mfi->album); + mfi->album = safe_strdup(pl_name); + } + if (cfg_getbool(cfg_getsec(cfg, "spotify"), "artist_override") && pl_name) + { + mfi->compilation = true; } if (mfi->media_kind == MEDIA_KIND_PODCAST) @@ -1815,11 +1818,11 @@ saved_playlist_tracks_add(json_object *item, int index, int total, enum spotify_ struct spotify_album album; json_object *jsontrack; json_object *jsonalbum; - int *plid; + struct playlist_info *pli; int dir_id; int ret; - plid = arg; + pli = arg; if (!(item && json_object_object_get_ex(item, "track", &jsontrack))) { @@ -1837,7 +1840,8 @@ saved_playlist_tracks_add(json_object *item, int index, int total, enum spotify_ return 0; } - if (json_object_object_get_ex(jsontrack, "album", &jsonalbum)) + if (!cfg_getbool(cfg_getsec(cfg, "spotify"), "album_override") + && json_object_object_get_ex(jsontrack, "album", &jsonalbum)) { parse_metadata_album(jsonalbum, &album, 0); } @@ -1847,20 +1851,20 @@ saved_playlist_tracks_add(json_object *item, int index, int total, enum spotify_ } dir_id = prepare_directories(track.album_artist, track.album); - ret = track_add(&track, &album, NULL, dir_id, request_type); + ret = track_add(&track, &album, pli->title, dir_id, request_type); if (ret == 0) - db_pl_add_item_bypath(*plid, track.uri); + db_pl_add_item_bypath(pli->id, track.uri); return 0; } /* Thread: library */ static int -scan_playlist_tracks(const char *playlist_tracks_endpoint_uri, int plid, enum spotify_request_type request_type) +scan_playlist_tracks(const char *playlist_tracks_endpoint_uri, struct playlist_info *pli, enum spotify_request_type request_type) { int ret; - ret = request_pagingobject_endpoint(playlist_tracks_endpoint_uri, saved_playlist_tracks_add, transaction_start, transaction_end, true, request_type, &plid); + ret = request_pagingobject_endpoint(playlist_tracks_endpoint_uri, saved_playlist_tracks_add, transaction_start, transaction_end, true, request_type, pli); return ret; } @@ -1908,14 +1912,15 @@ saved_playlist_add(json_object *item, int index, int total, enum spotify_request map_playlist_to_pli(&pli, &playlist); pl_id = playlist_add_or_update(&pli); - - free_pli(&pli, 1); + pli.id = pl_id; if (pl_id > 0) - scan_playlist_tracks(playlist.tracks_href, pl_id, request_type); + scan_playlist_tracks(playlist.tracks_href, &pli, request_type); else DPRINTF(E_LOG, L_SPOTIFY, "Error adding playlist: '%s' (%s) \n", playlist.name, playlist.uri); + free_pli(&pli, 1); + DPRINTF(E_LOG, L_SPOTIFY, "Scanned %d of %d saved playlists\n", (index + 1), total); return 0; From e5d3c148ea7f11b5c40ab555ef36b3ae552973a0 Mon Sep 17 00:00:00 2001 From: chme Date: Mon, 4 Apr 2022 20:52:48 +0200 Subject: [PATCH 2/2] [db/scan] Force compilation artist if track belongs to a compilation --- src/db.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/db.c b/src/db.c index e2a01598..e890fac2 100644 --- a/src/db.c +++ b/src/db.c @@ -1192,12 +1192,16 @@ fixup_defaults(char **tag, enum fixup_type fixup, struct fixup_ctx *ctx) *tag = strdup(""); } + if (ctx->mfi && ctx->mfi->compilation && (ca = cfg_getstr(cfg_getsec(cfg, "library"), "compilation_artist"))) + { + free(*tag); + *tag = strdup(ca); // If ca is empty string then the artist will not be shown in artist view + } + if (*tag) break; - if (ctx->mfi && ctx->mfi->compilation && (ca = cfg_getstr(cfg_getsec(cfg, "library"), "compilation_artist"))) - *tag = strdup(ca); // If ca is empty string then the artist will not be shown in artist view - else if (ctx->mfi && ctx->mfi->artist) + if (ctx->mfi && ctx->mfi->artist) *tag = strdup(ctx->mfi->artist); else if (ctx->qi && ctx->qi->artist) *tag = strdup(ctx->qi->artist);