playlist: add thumbnail match with filename config (#16022)

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] 32ed9b6041 ("플레이리스트 롬파일 이름으로 썸네일 이미지를 찾도록 옵션 추가 (#15731)")

Signed-off-by: masky2012 <msuanming@163.com>
This commit is contained in:
aveyond 2023-12-21 08:24:23 +08:00 committed by GitHub
parent e796716f57
commit 4abd4e8d27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 14 deletions

View File

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

View File

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

View File

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