From 4abd4e8d279168e862fb1a4fb687fbe09da4c01d Mon Sep 17 00:00:00 2001 From: aveyond Date: Thu, 21 Dec 2023 08:24:23 +0800 Subject: [PATCH] playlist: add thumbnail match with filename config (#16022) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the commit [1], a global configuration "thumbnail match with filename" was added which allows thumbnail match with filename. This commit adds playlist level "thumbnail match with filename" for more flexible configuration. [1] 32ed9b604154 ("플레이리스트 롬파일 이름으로 썸네일 이미지를 찾도록 옵션 추가 (#15731)") Signed-off-by: masky2012 --- gfx/gfx_thumbnail_path.c | 3 ++- playlist.c | 52 ++++++++++++++++++++++++++++++---------- playlist.h | 8 +++++++ 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/gfx/gfx_thumbnail_path.c b/gfx/gfx_thumbnail_path.c index 271bc63fc1..29c6ea5e3d 100644 --- a/gfx/gfx_thumbnail_path.c +++ b/gfx/gfx_thumbnail_path.c @@ -444,7 +444,8 @@ bool gfx_thumbnail_set_content_playlist( "", sizeof(path_data->content_label)); /* Determine content image name */ - if (settings->bools.playlist_use_filename) + if (settings->bools.playlist_use_filename || + playlist_thumbnail_match_with_filename(playlist)) { char* content_name_no_ext = NULL; char tmp_buf[PATH_MAX_LENGTH]; diff --git a/playlist.c b/playlist.c index 9704ff2c7e..f3f0e40fb2 100644 --- a/playlist.c +++ b/playlist.c @@ -75,6 +75,7 @@ struct content_playlist enum playlist_label_display_mode label_display_mode; enum playlist_thumbnail_mode right_thumbnail_mode; enum playlist_thumbnail_mode left_thumbnail_mode; + enum playlist_thumbnail_match_mode thumbnail_match_mode; enum playlist_sort_mode sort_mode; bool modified; @@ -90,6 +91,7 @@ typedef struct unsigned *current_entry_uint_val; enum playlist_label_display_mode *current_meta_label_display_mode_val; enum playlist_thumbnail_mode *current_meta_thumbnail_mode_val; + enum playlist_thumbnail_match_mode *current_meta_thumbnail_match_mode_val; enum playlist_sort_mode *current_meta_sort_mode_val; bool *current_meta_bool_val; playlist_t *playlist; @@ -1771,6 +1773,14 @@ void playlist_write_file(playlist_t *playlist) rjsonwriter_raw(writer, ",", 1); rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_add_spaces(writer, 2); + rjsonwriter_add_string(writer, "thumbnail_match_mode"); + rjsonwriter_raw(writer, ":", 1); + rjsonwriter_raw(writer, " ", 1); + rjsonwriter_rawf(writer, "%d", (int)playlist->thumbnail_match_mode); + rjsonwriter_raw(writer, ",", 1); + rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "sort_mode"); rjsonwriter_raw(writer, ":", 1); @@ -2283,19 +2293,22 @@ static bool JSONNumberHandler(void *context, const char *pValue, size_t length) { /* handle any top-level playlist metadata here */ if (pCtx->current_meta_label_display_mode_val) - *pCtx->current_meta_label_display_mode_val = (enum playlist_label_display_mode)strtoul(pValue, NULL, 10); + *pCtx->current_meta_label_display_mode_val = (enum playlist_label_display_mode)strtoul(pValue, NULL, 10); else if (pCtx->current_meta_thumbnail_mode_val) - *pCtx->current_meta_thumbnail_mode_val = (enum playlist_thumbnail_mode)strtoul(pValue, NULL, 10); + *pCtx->current_meta_thumbnail_mode_val = (enum playlist_thumbnail_mode)strtoul(pValue, NULL, 10); + else if (pCtx->current_meta_thumbnail_match_mode_val) + *pCtx->current_meta_thumbnail_match_mode_val = (enum playlist_thumbnail_match_mode)strtoul(pValue, NULL, 10); else if (pCtx->current_meta_sort_mode_val) - *pCtx->current_meta_sort_mode_val = (enum playlist_sort_mode)strtoul(pValue, NULL, 10); + *pCtx->current_meta_sort_mode_val = (enum playlist_sort_mode)strtoul(pValue, NULL, 10); } } } - pCtx->current_entry_uint_val = NULL; - pCtx->current_meta_label_display_mode_val = NULL; - pCtx->current_meta_thumbnail_mode_val = NULL; - pCtx->current_meta_sort_mode_val = NULL; + pCtx->current_entry_uint_val = NULL; + pCtx->current_meta_label_display_mode_val = NULL; + pCtx->current_meta_thumbnail_mode_val = NULL; + pCtx->current_meta_thumbnail_match_mode_val = NULL; + pCtx->current_meta_sort_mode_val = NULL; return true; } @@ -2395,12 +2408,13 @@ static bool JSONObjectMemberHandler(void *context, const char *pValue, size_t le && (pCtx->array_depth == 0) && length) { - pCtx->current_string_val = NULL; - pCtx->current_meta_label_display_mode_val = NULL; - pCtx->current_meta_thumbnail_mode_val = NULL; - pCtx->current_meta_sort_mode_val = NULL; - pCtx->current_meta_bool_val = NULL; - pCtx->in_items = false; + pCtx->current_string_val = NULL; + pCtx->current_meta_label_display_mode_val = NULL; + pCtx->current_meta_thumbnail_mode_val = NULL; + pCtx->current_meta_thumbnail_match_mode_val = NULL; + pCtx->current_meta_sort_mode_val = NULL; + pCtx->current_meta_bool_val = NULL; + pCtx->in_items = false; switch (pValue[0]) { @@ -2446,6 +2460,10 @@ static bool JSONObjectMemberHandler(void *context, const char *pValue, size_t le else if (string_is_equal(pValue, "sort_mode")) pCtx->current_meta_sort_mode_val = &pCtx->playlist->sort_mode; break; + case 't': + if (string_is_equal(pValue, "thumbnail_match_mode")) + pCtx->current_meta_thumbnail_match_mode_val = &pCtx->playlist->thumbnail_match_mode; + break; } } @@ -2818,6 +2836,7 @@ playlist_t *playlist_init(const playlist_config_t *config) playlist->label_display_mode = LABEL_DISPLAY_MODE_DEFAULT; playlist->right_thumbnail_mode = PLAYLIST_THUMBNAIL_MODE_DEFAULT; playlist->left_thumbnail_mode = PLAYLIST_THUMBNAIL_MODE_DEFAULT; + playlist->thumbnail_match_mode = PLAYLIST_THUMBNAIL_MATCH_MODE_DEFAULT; playlist->sort_mode = PLAYLIST_SORT_MODE_DEFAULT; playlist->scan_record.search_recursively = false; @@ -3232,6 +3251,13 @@ enum playlist_thumbnail_mode playlist_get_thumbnail_mode( return PLAYLIST_THUMBNAIL_MODE_DEFAULT; } +bool playlist_thumbnail_match_with_filename(playlist_t *playlist) +{ + if (!playlist) + return false; + return playlist->thumbnail_match_mode == PLAYLIST_THUMBNAIL_MATCH_MODE_WITH_FILENAME; +} + enum playlist_sort_mode playlist_get_sort_mode(playlist_t *playlist) { if (!playlist) diff --git a/playlist.h b/playlist.h index 23705ab7fd..f7dcc5759e 100644 --- a/playlist.h +++ b/playlist.h @@ -64,6 +64,13 @@ enum playlist_thumbnail_mode PLAYLIST_THUMBNAIL_MODE_BOXARTS }; +enum playlist_thumbnail_match_mode +{ + PLAYLIST_THUMBNAIL_MATCH_MODE_DEFAULT = 0, + PLAYLIST_THUMBNAIL_MATCH_MODE_WITH_LABEL = PLAYLIST_THUMBNAIL_MATCH_MODE_DEFAULT, + PLAYLIST_THUMBNAIL_MATCH_MODE_WITH_FILENAME +}; + enum playlist_sort_mode { PLAYLIST_SORT_MODE_DEFAULT = 0, @@ -354,6 +361,7 @@ const char *playlist_get_default_core_name(playlist_t *playlist); enum playlist_label_display_mode playlist_get_label_display_mode(playlist_t *playlist); enum playlist_thumbnail_mode playlist_get_thumbnail_mode( playlist_t *playlist, enum playlist_thumbnail_id thumbnail_id); +bool playlist_thumbnail_match_with_filename(playlist_t *playlist); enum playlist_sort_mode playlist_get_sort_mode(playlist_t *playlist); const char *playlist_get_scan_content_dir(playlist_t *playlist); const char *playlist_get_scan_file_exts(playlist_t *playlist);