From 4331b389219f5e64400dcee3732a9565c34bbabc Mon Sep 17 00:00:00 2001 From: zoltanvb <101990835+zoltanvb@users.noreply.github.com> Date: Tue, 2 Jan 2024 02:23:18 +0100 Subject: [PATCH] Thumbnail fixes (#16062) * Minor thumbnail improvements - set standard name if only one entry is in the playlist - use first database name for thumbnails if core has multiple * Fix playlist thumbnail downloader Playlist thumbnail downloader function was missed from the flexible thumbnail name update, now it is added. --- gfx/gfx_thumbnail_path.c | 17 +++++++++++++---- playlist.c | 5 +++++ tasks/task_pl_thumbnail_download.c | 28 ++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/gfx/gfx_thumbnail_path.c b/gfx/gfx_thumbnail_path.c index 3cdf829ad47..19a6ac14d4d 100644 --- a/gfx/gfx_thumbnail_path.c +++ b/gfx/gfx_thumbnail_path.c @@ -500,10 +500,19 @@ bool gfx_thumbnail_set_content_playlist( { char *db_name_no_ext = NULL; char tmp_buf[PATH_MAX_LENGTH]; - /* Remove .lpl extension - * > path_remove_extension() requires a char * (not const) - * so have to use a temporary buffer... */ - strlcpy(tmp_buf, db_name, sizeof(tmp_buf)); + const char* pos = strchr(db_name, '|'); + + if (pos && (size_t) (pos - db_name)+1 < sizeof(tmp_buf)) { + /* If db_name comes from core info, and there are multiple + * databases mentioned separated by |, use only first one */ + strlcpy(tmp_buf, db_name, (size_t) (pos - db_name)+1); + } + else { + /* Remove .lpl extension + * > path_remove_extension() requires a char * (not const) + * so have to use a temporary buffer... */ + strlcpy(tmp_buf, db_name, sizeof(tmp_buf)); + } db_name_no_ext = path_remove_extension(tmp_buf); if (!string_is_empty(db_name_no_ext)) diff --git a/playlist.c b/playlist.c index 0ac5160add6..9e3a4cc3a51 100644 --- a/playlist.c +++ b/playlist.c @@ -1097,6 +1097,11 @@ enum playlist_thumbnail_name_flags playlist_get_next_thumbnail_name_flag(playlis return PLAYLIST_THUMBNAIL_FLAG_SHORT_NAME; if (entry->thumbnail_flags & PLAYLIST_THUMBNAIL_FLAG_FULL_NAME) return PLAYLIST_THUMBNAIL_FLAG_STD_NAME; + /* Special case: only one entry in playlist, only one query is possible + * as flag swapping relies on going back and forth among entries + * so just use the most likely version here */ + if (idx == 0 && RBUF_LEN(playlist->entries) == 1) + return PLAYLIST_THUMBNAIL_FLAG_STD_NAME; return PLAYLIST_THUMBNAIL_FLAG_FULL_NAME; } diff --git a/tasks/task_pl_thumbnail_download.c b/tasks/task_pl_thumbnail_download.c index 36b88dbde78..1c217e52e44 100644 --- a/tasks/task_pl_thumbnail_download.c +++ b/tasks/task_pl_thumbnail_download.c @@ -366,7 +366,8 @@ static void free_pl_thumb_handle(pl_thumb_handle_t *pl_thumb) static void task_pl_thumbnail_download_handler(retro_task_t *task) { pl_thumb_handle_t *pl_thumb = NULL; - + enum playlist_thumbnail_name_flags next_flag = PLAYLIST_THUMBNAIL_FLAG_INVALID; + if (!task) goto task_finished; @@ -421,6 +422,8 @@ static void task_pl_thumbnail_download_handler(retro_task_t *task) /* Start iterating over thumbnail type */ pl_thumb->type_idx = 1; pl_thumb->status = PL_THUMB_ITERATE_TYPE; + playlist_update_thumbnail_name_flag(pl_thumb->playlist, pl_thumb->list_index, PLAYLIST_THUMBNAIL_FLAG_FULL_NAME); + pl_thumb->name_flags = PLAYLIST_THUMBNAIL_FLAG_FULL_NAME; } else { @@ -450,13 +453,22 @@ static void task_pl_thumbnail_download_handler(retro_task_t *task) /* Check whether all thumbnail types have been processed */ if (pl_thumb->type_idx > 3) { - /* Time to move on to the next entry */ - pl_thumb->list_index++; - if (pl_thumb->list_index < pl_thumb->list_size) - pl_thumb->status = PL_THUMB_ITERATE_ENTRY; - else - pl_thumb->status = PL_THUMB_END; - break; + next_flag = playlist_get_next_thumbnail_name_flag(pl_thumb->playlist,pl_thumb->list_index); + if (next_flag == PLAYLIST_THUMBNAIL_FLAG_NONE) { + if (pl_thumb->playlist ) + /* Time to move on to the next entry */ + pl_thumb->list_index++; + if (pl_thumb->list_index < pl_thumb->list_size) + pl_thumb->status = PL_THUMB_ITERATE_ENTRY; + else + pl_thumb->status = PL_THUMB_END; + break; + } else { + /* Increment the name flag to cover the 3 supported naming conventions. */ + pl_thumb->type_idx = 1; + playlist_update_thumbnail_name_flag(pl_thumb->playlist, pl_thumb->list_index, next_flag); + pl_thumb->name_flags = next_flag; + } } /* Download current thumbnail */