From ce3e79d8041ff7f9270eccca027a227106f22a68 Mon Sep 17 00:00:00 2001 From: chme Date: Sun, 11 Jul 2021 12:19:49 +0200 Subject: [PATCH] [spotify] Move "has_podcast_support" to spotify_status and expose this flag in the web API --- src/httpd_jsonapi.c | 1 + src/inputs/spotify.c | 11 ----------- src/inputs/spotify.h | 6 +----- src/inputs/spotify_librespotc.c | 3 +-- src/inputs/spotify_libspotify.c | 3 +-- src/library/spotify_webapi.c | 4 +++- 6 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/httpd_jsonapi.c b/src/httpd_jsonapi.c index 84774752..89fdf63f 100644 --- a/src/httpd_jsonapi.c +++ b/src/httpd_jsonapi.c @@ -1232,6 +1232,7 @@ jsonapi_reply_spotify(struct httpd_request *hreq) spotify_status_get(&sp_status); json_object_object_add(jreply, "spotify_installed", json_object_new_boolean(sp_status.installed)); json_object_object_add(jreply, "spotify_logged_in", json_object_new_boolean(sp_status.logged_in)); + json_object_object_add(jreply, "has_podcast_support", json_object_new_boolean(sp_status.has_podcast_support)); safe_json_add_string(jreply, "libspotify_user", sp_status.username); spotifywebapi_status_info_get(&webapi_info); diff --git a/src/inputs/spotify.c b/src/inputs/spotify.c index 389c8547..633c05fe 100644 --- a/src/inputs/spotify.c +++ b/src/inputs/spotify.c @@ -144,14 +144,3 @@ spotify_status_get(struct spotify_status *status) backend->status_get(status); } - -bool -spotify_podcast_support() -{ - struct spotify_backend *backend = backend_set(); - - if (!backend) - return false; - - return backend->has_podcast_support; -} diff --git a/src/inputs/spotify.h b/src/inputs/spotify.h index c970686c..a402588e 100644 --- a/src/inputs/spotify.h +++ b/src/inputs/spotify.h @@ -9,6 +9,7 @@ struct spotify_status bool installed; bool logged_in; char username[128]; + bool has_podcast_support; }; struct spotify_backend @@ -21,8 +22,6 @@ struct spotify_backend int (*relogin)(void); void (*uri_register)(const char *uri); void (*status_get)(struct spotify_status *status); - - bool has_podcast_support; }; int @@ -49,7 +48,4 @@ spotify_uri_register(const char *uri); void spotify_status_get(struct spotify_status *status); -bool -spotify_podcast_support(); - #endif /* !__SPOTIFY_H__ */ diff --git a/src/inputs/spotify_librespotc.c b/src/inputs/spotify_librespotc.c index fceadce1..dd953354 100644 --- a/src/inputs/spotify_librespotc.c +++ b/src/inputs/spotify_librespotc.c @@ -738,6 +738,7 @@ status_get(struct spotify_status *status) memcpy(status->username, ctx->status.username, sizeof(status->username)); status->logged_in = ctx->status.logged_in; status->installed = true; + status->has_podcast_support = true; pthread_mutex_unlock(&ctx->lock); } @@ -749,7 +750,5 @@ struct spotify_backend spotify_librespotc = .logout = logout, .relogin = relogin, .status_get = status_get, - - .has_podcast_support = true, }; diff --git a/src/inputs/spotify_libspotify.c b/src/inputs/spotify_libspotify.c index d29e8575..28ce10b8 100644 --- a/src/inputs/spotify_libspotify.c +++ b/src/inputs/spotify_libspotify.c @@ -116,6 +116,7 @@ status_get(struct spotify_status *status) status->installed = info.libspotify_installed; status->logged_in = info.libspotify_logged_in; + status->has_podcast_support = false; snprintf(status->username, sizeof(status->username), "%s", info.libspotify_user); } @@ -129,7 +130,5 @@ struct spotify_backend spotify_libspotify = .relogin = libspotify_relogin, .uri_register = libspotify_uri_register, .status_get = status_get, - - .has_podcast_support = false, }; diff --git a/src/library/spotify_webapi.c b/src/library/spotify_webapi.c index 4f4b4778..b684c932 100644 --- a/src/library/spotify_webapi.c +++ b/src/library/spotify_webapi.c @@ -1989,6 +1989,7 @@ create_base_playlist(void) static void scan(enum spotify_request_type request_type) { + struct spotify_status sp_status; time_t start; time_t end; @@ -2006,7 +2007,8 @@ scan(enum spotify_request_type request_type) create_saved_tracks_playlist(); scan_saved_albums(request_type); scan_playlists(request_type); - if (spotify_podcast_support()) + spotify_status_get(&sp_status); + if (sp_status.has_podcast_support) scan_saved_shows(request_type); scanning = false;