From b73f33f8e9e554dffe0dd9f9be2148c06e7dbf92 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Mon, 17 Feb 2020 22:08:31 +0100 Subject: [PATCH] [artwork] Use settings to enable online sources --- src/artwork.c | 33 ++++++++++++++++++++++++++++++--- src/settings.c | 8 ++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/artwork.c b/src/artwork.c index b8ddf6e1..77b79204 100644 --- a/src/artwork.c +++ b/src/artwork.c @@ -36,6 +36,7 @@ #include "misc_json.h" #include "logger.h" #include "conffile.h" +#include "settings.h" #include "cache.h" #include "http.h" #include "transcode.h" @@ -213,7 +214,7 @@ static struct artwork_source artwork_item_source[] = .data_kinds = (1 << DATA_KIND_FILE) | (1 << DATA_KIND_SPOTIFY), .cache = ON_FAILURE, }, -/* { + { // TODO merge with spotifywebapi_get .name = "Spotify2", .handler = source_item_spotify2_get, @@ -233,7 +234,7 @@ static struct artwork_source artwork_item_source[] = .data_kinds = (1 << DATA_KIND_FILE), .cache = NEVER, }, -*/ { + { .name = "embedded", .handler = source_item_embedded_get, .data_kinds = (1 << DATA_KIND_FILE), @@ -1067,6 +1068,23 @@ online_source_search(struct online_source *src, struct artwork_ctx *ctx) return artwork_url; } +static bool +online_source_is_enabled(const char *setting_name) +{ + struct settings_category *category; + struct settings_option *option; + + category = settings_category_get("artwork"); + if (!category) + return false; + + option = settings_option_get(category, setting_name); + if (!option) + return false; + + return settings_option_getbool(option); +} + /* ---------------------- SOURCE HANDLER IMPLEMENTATION -------------------- */ @@ -1327,6 +1345,9 @@ source_item_discogs_get(struct artwork_ctx *ctx) char *url; int ret; + if (!online_source_is_enabled("enable_discogs")) + return ART_E_NONE; + url = online_source_search(&discogs_source, ctx); if (!url) return ART_E_NONE; @@ -1343,6 +1364,9 @@ source_item_coverartarchive_get(struct artwork_ctx *ctx) char *url; int ret; + if (!online_source_is_enabled("enable_coverartarchive")) + return ART_E_NONE; + // We search Musicbrainz to get the Musicbrainz ID, which we need to get the // artwork from the Cover Art Archive url = online_source_search(&musicbrainz_source, ctx); @@ -1364,6 +1388,9 @@ source_item_spotify2_get(struct artwork_ctx *ctx) char *url; int ret; + if (!online_source_is_enabled("enable_spotify")) + return ART_E_NONE; + spotifywebapi_access_token_get(&info); if (!info.token) return ART_E_ERROR; @@ -1434,7 +1461,7 @@ source_item_spotify2_get(struct artwork_ctx *ctx) // Silence compiler warning about spotify_source being unused (void)spotify_source; - return ART_E_ERROR; + return ART_E_NONE; } static int diff --git a/src/settings.c b/src/settings.c index 3bdb7244..8e2f89d5 100644 --- a/src/settings.c +++ b/src/settings.c @@ -31,9 +31,17 @@ static struct settings_option webinterface_options[] = { "show_composer_for_genre", SETTINGS_TYPE_STR }, }; +static struct settings_option artwork_options[] = + { + { "enable_spotify", SETTINGS_TYPE_BOOL }, + { "enable_discogs", SETTINGS_TYPE_BOOL }, + { "enable_coverartarchive", SETTINGS_TYPE_BOOL }, + }; + static struct settings_category categories[] = { { "webinterface", webinterface_options, ARRAY_SIZE(webinterface_options) }, + { "artwork", artwork_options, ARRAY_SIZE(artwork_options) }, };