From 9d1f15d3c288c72b55835850aa3907b35c634f0a Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Thu, 16 Apr 2020 23:39:40 +0200 Subject: [PATCH 1/3] [db] Define MEDIA_KIND_ALL --- src/db.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/db.h b/src/db.h index ba6a77bc..58f0e5f7 100644 --- a/src/db.h +++ b/src/db.h @@ -121,6 +121,8 @@ enum media_kind { MEDIA_KIND_TVSHOW = 64, }; +#define MEDIA_KIND_ALL (1 | 2 | 4 | 8 | 32 | 64) + const char * db_media_kind_label(enum media_kind media_kind); From 37b4188c3c01b4ed8ec74bdeac0a1a2b785368ce Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Thu, 16 Apr 2020 23:40:15 +0200 Subject: [PATCH 2/3] [artwork] Generalize handler configuration of supported media_kinds --- src/artwork.c | 58 +++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/src/artwork.c b/src/artwork.c index ac2001f9..4ef656d7 100644 --- a/src/artwork.c +++ b/src/artwork.c @@ -103,6 +103,7 @@ struct artwork_ctx { struct db_media_file_info *dbmfi; int id; uint32_t data_kind; + uint32_t media_kind; // Input data for group handlers int64_t persistentid; @@ -121,8 +122,11 @@ struct artwork_source { // The handler int (*handler)(struct artwork_ctx *ctx); - // What data_kinds the handler can work with, combined with (1 << A) | (1 << B) - int data_kinds; + // data_kinds the handler can work with, combined with (1 << A) | (1 << B) + uint32_t data_kinds; + + // media_kinds the handler supports, combined with A | B + uint32_t media_kinds; // When should results from the source be cached? enum artwork_cache cache; @@ -231,66 +235,77 @@ static struct artwork_source artwork_item_source[] = .name = "cache", .handler = source_item_cache_get, .data_kinds = (1 << DATA_KIND_FILE) | (1 << DATA_KIND_SPOTIFY), + .media_kinds = MEDIA_KIND_ALL, .cache = ON_FAILURE, }, { .name = "embedded", .handler = source_item_embedded_get, .data_kinds = (1 << DATA_KIND_FILE) | (1 << DATA_KIND_HTTP), + .media_kinds = MEDIA_KIND_ALL, .cache = ON_SUCCESS | ON_FAILURE, }, { .name = "own", .handler = source_item_own_get, .data_kinds = (1 << DATA_KIND_FILE), + .media_kinds = MEDIA_KIND_ALL, .cache = ON_SUCCESS | ON_FAILURE, }, { .name = "stream", .handler = source_item_stream_get, .data_kinds = (1 << DATA_KIND_HTTP), + .media_kinds = MEDIA_KIND_MUSIC, .cache = STASH, }, { .name = "pipe", .handler = source_item_pipe_get, .data_kinds = (1 << DATA_KIND_PIPE), + .media_kinds = MEDIA_KIND_ALL, .cache = NEVER, }, { .name = "Spotify track web api", .handler = source_item_spotifywebapi_track_get, .data_kinds = (1 << DATA_KIND_SPOTIFY), + .media_kinds = MEDIA_KIND_ALL, .cache = ON_SUCCESS | ON_FAILURE, }, { .name = "playlist own", .handler = source_item_ownpl_get, .data_kinds = (1 << DATA_KIND_HTTP), + .media_kinds = MEDIA_KIND_ALL, .cache = ON_SUCCESS | ON_FAILURE, }, { .name = "Spotify search web api (files)", .handler = source_item_spotifywebapi_search_get, .data_kinds = (1 << DATA_KIND_FILE), + .media_kinds = MEDIA_KIND_MUSIC, .cache = ON_SUCCESS | ON_FAILURE, }, { .name = "Spotify search web api (streams)", .handler = source_item_spotifywebapi_search_get, .data_kinds = (1 << DATA_KIND_HTTP) | (1 << DATA_KIND_PIPE), + .media_kinds = MEDIA_KIND_MUSIC, .cache = STASH, }, { .name = "Discogs (files)", .handler = source_item_discogs_get, .data_kinds = (1 << DATA_KIND_FILE), + .media_kinds = MEDIA_KIND_MUSIC, .cache = ON_SUCCESS | ON_FAILURE, }, { .name = "Discogs (streams)", .handler = source_item_discogs_get, .data_kinds = (1 << DATA_KIND_HTTP) | (1 << DATA_KIND_PIPE), + .media_kinds = MEDIA_KIND_MUSIC, .cache = STASH, }, { @@ -298,6 +313,7 @@ static struct artwork_source artwork_item_source[] = .name = "Cover Art Archive (files)", .handler = source_item_coverartarchive_get, .data_kinds = (1 << DATA_KIND_FILE), + .media_kinds = MEDIA_KIND_MUSIC, .cache = ON_SUCCESS | ON_FAILURE, }, { @@ -305,6 +321,7 @@ static struct artwork_source artwork_item_source[] = .name = "Cover Art Archive (streams)", .handler = source_item_coverartarchive_get, .data_kinds = (1 << DATA_KIND_HTTP) | (1 << DATA_KIND_PIPE), + .media_kinds = MEDIA_KIND_MUSIC, .cache = STASH, }, { @@ -1500,15 +1517,8 @@ source_item_stream_get(struct artwork_ctx *ctx) char *url; char *ext; int len; - int media_kind; int ret; - ret = safe_atoi32(ctx->dbmfi->media_kind, &media_kind); - if (ret != 0 || media_kind != MEDIA_KIND_MUSIC) - { - DPRINTF(E_SPAM, L_ART, "Ignoring internet stream artwork request for media_kind != music: %s\n", ctx->dbmfi->path); - return ART_E_NONE; - } DPRINTF(E_SPAM, L_ART, "Trying internet stream artwork in %s\n", ctx->dbmfi->path); @@ -1574,19 +1584,11 @@ static int source_item_discogs_get(struct artwork_ctx *ctx) { char *url; - int media_kind; int ret; if (!online_source_is_enabled(&discogs_source)) return ART_E_NONE; - ret = safe_atoi32(ctx->dbmfi->media_kind, &media_kind); - if (ret != 0 || media_kind != MEDIA_KIND_MUSIC) - { - DPRINTF(E_SPAM, L_ART, "Ignoring internet stream artwork request for media_kind != music: %s\n", ctx->dbmfi->path); - return ART_E_NONE; - } - url = online_source_search(&discogs_source, ctx); if (!url) return ART_E_NONE; @@ -1603,19 +1605,11 @@ static int source_item_coverartarchive_get(struct artwork_ctx *ctx) { char *url; - int media_kind; int ret; if (!online_source_is_enabled(&musicbrainz_source)) return ART_E_NONE; - ret = safe_atoi32(ctx->dbmfi->media_kind, &media_kind); - if (ret != 0 || media_kind != MEDIA_KIND_MUSIC) - { - DPRINTF(E_SPAM, L_ART, "Ignoring internet stream artwork request for media_kind != music: %s\n", ctx->dbmfi->path); - 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); @@ -1655,19 +1649,11 @@ source_item_spotifywebapi_search_get(struct artwork_ctx *ctx) { struct spotifywebapi_access_token info; char *url; - int media_kind; int ret; if (!online_source_is_enabled(&spotify_source)) return ART_E_NONE; - ret = safe_atoi32(ctx->dbmfi->media_kind, &media_kind); - if (ret != 0 || media_kind != MEDIA_KIND_MUSIC) - { - DPRINTF(E_SPAM, L_ART, "Ignoring internet stream artwork request for media_kind != music: %s\n", ctx->dbmfi->path); - return ART_E_NONE; - } - spotifywebapi_access_token_get(&info); if (!info.token) return ART_E_ERROR; @@ -1797,10 +1783,11 @@ process_items(struct artwork_ctx *ctx, int item_mode) ret = (safe_atoi32(dbmfi.id, &ctx->id) < 0) || (safe_atou32(dbmfi.data_kind, &ctx->data_kind) < 0) || + (safe_atou32(dbmfi.media_kind, &ctx->media_kind) < 0) || (ctx->data_kind > 30); if (ret) { - DPRINTF(E_LOG, L_ART, "Error converting dbmfi id or data_kind to number\n"); + DPRINTF(E_LOG, L_ART, "Error converting dbmfi id, data_kind or media_kind to number for '%s'\n", dbmfi.path); continue; } @@ -1809,6 +1796,9 @@ process_items(struct artwork_ctx *ctx, int item_mode) if ((artwork_item_source[i].data_kinds & (1 << ctx->data_kind)) == 0) continue; + if ((artwork_item_source[i].media_kinds & ctx->media_kind) == 0) + continue; + // If just one handler says we should not cache a negative result then we obey that if ((artwork_item_source[i].cache & ON_FAILURE) == 0) ctx->cache = NEVER; From 0e19102efd2f0abadca9bec30436fa51813b4ec4 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Sat, 18 Apr 2020 21:55:06 +0200 Subject: [PATCH 3/3] [artwork] Define MEDIA_KIND_ALL as USHRT_MAX instead of individual num values --- src/db.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/db.h b/src/db.h index 58f0e5f7..76b0850f 100644 --- a/src/db.h +++ b/src/db.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "outputs.h" @@ -121,7 +122,7 @@ enum media_kind { MEDIA_KIND_TVSHOW = 64, }; -#define MEDIA_KIND_ALL (1 | 2 | 4 | 8 | 32 | 64) +#define MEDIA_KIND_ALL USHRT_MAX const char * db_media_kind_label(enum media_kind media_kind);