[artwork] Use settings to enable online sources

This commit is contained in:
ejurgensen 2020-02-17 22:08:31 +01:00
parent 18cf2dbbbf
commit b73f33f8e9
2 changed files with 38 additions and 3 deletions

View File

@ -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

View File

@ -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) },
};