Skip to content

Commit

Permalink
playlist: add thumbnail match with filename config (#16022)
Browse files Browse the repository at this point in the history
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] 32ed9b6 ("플레이리스트 롬파일 이름으로 썸네일 이미지를 찾도록 옵션 추가 (#15731)")

Signed-off-by: masky2012 <msuanming@163.com>
  • Loading branch information
AveyondFly authored Dec 21, 2023
1 parent e796716 commit 4abd4e8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
3 changes: 2 additions & 1 deletion gfx/gfx_thumbnail_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
52 changes: 39 additions & 13 deletions playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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])
{
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4abd4e8

Please sign in to comment.