diff --git a/src/menu.c b/src/menu.c index 99dfeae..ddf3451 100644 --- a/src/menu.c +++ b/src/menu.c @@ -165,7 +165,10 @@ static bool update_track_menu(plugin_ctx *ctx, dyn_menu *item, const char *type, const char *prop) { void *tmp = talloc_new(NULL); mp_track_list *list = mp_get_track_list(tmp, type); - if (list == NULL) return false; + if (list->num_entries == 0) { + talloc_free(tmp); + return false; + } bool is_sub = strcmp(type, "sub") == 0; int64_t pos = mp_get_prop_int(prop); @@ -213,7 +216,10 @@ static bool update_second_sub_track_menu(plugin_ctx *ctx, dyn_menu *item) { static bool update_chapter_menu(plugin_ctx *ctx, dyn_menu *item) { void *tmp = talloc_new(NULL); mp_chapter_list *list = mp_get_chapter_list(tmp); - if (list == NULL) return false; + if (list->num_entries == 0) { + talloc_free(tmp); + return false; + } for (int i = 0; i < list->num_entries; i++) { chapter_item *entry = &list->entries[i]; @@ -238,7 +244,10 @@ static bool update_chapter_menu(plugin_ctx *ctx, dyn_menu *item) { static bool update_edition_menu(plugin_ctx *ctx, dyn_menu *item) { void *tmp = talloc_new(NULL); mp_edition_list *list = mp_get_edition_list(tmp); - if (list == NULL) return false; + if (list->num_entries == 0) { + talloc_free(tmp); + return false; + } for (int i = 0; i < list->num_entries; i++) { edition_item *entry = &list->entries[i]; @@ -259,7 +268,10 @@ static bool update_edition_menu(plugin_ctx *ctx, dyn_menu *item) { static bool update_audio_device_menu(plugin_ctx *ctx, dyn_menu *item) { void *tmp = talloc_new(NULL); mp_audio_device_list *list = mp_get_audio_device_list(tmp); - if (list == NULL) return false; + if (list->num_entries == 0) { + talloc_free(tmp); + return false; + } char *name = mp_get_prop_string(tmp, "audio-device"); int pos = -1; diff --git a/src/plugin.c b/src/plugin.c index cdb8048..bb13992 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -144,18 +144,13 @@ int64_t mp_get_prop_int(const char *prop) { } mp_track_list *mp_get_track_list(void *talloc_ctx, const char *type) { - mpv_node node; - - if (mpv_get_property(ctx->mpv, "track-list", MPV_FORMAT_NODE, &node) < 0) - return NULL; - if (node.format != MPV_FORMAT_NODE_ARRAY || node.u.list->num == 0) { - mpv_free_node_contents(&node); - return NULL; - } - mp_track_list *list = talloc_ptrtype(talloc_ctx, list); memset(list, 0, sizeof(*list)); + mpv_node node; + if (mpv_get_property(ctx->mpv, "track-list", MPV_FORMAT_NODE, &node) < 0) + return list; + for (int i = 0; i < node.u.list->num; i++) { mpv_node track = node.u.list->values[i]; @@ -200,18 +195,13 @@ mp_track_list *mp_get_track_list(void *talloc_ctx, const char *type) { } mp_chapter_list *mp_get_chapter_list(void *talloc_ctx) { - mpv_node node; - - if (mpv_get_property(ctx->mpv, "chapter-list", MPV_FORMAT_NODE, &node) < 0) - return NULL; - if (node.format != MPV_FORMAT_NODE_ARRAY || node.u.list->num == 0) { - mpv_free_node_contents(&node); - return NULL; - } - mp_chapter_list *list = talloc_ptrtype(talloc_ctx, list); memset(list, 0, sizeof(*list)); + mpv_node node; + if (mpv_get_property(ctx->mpv, "chapter-list", MPV_FORMAT_NODE, &node) < 0) + return list; + for (int i = 0; i < node.u.list->num; i++) { mpv_node chapter = node.u.list->values[i]; @@ -241,18 +231,13 @@ mp_chapter_list *mp_get_chapter_list(void *talloc_ctx) { } mp_edition_list *mp_get_edition_list(void *talloc_ctx) { - mpv_node node; - - if (mpv_get_property(ctx->mpv, "edition-list", MPV_FORMAT_NODE, &node) < 0) - return NULL; - if (node.format != MPV_FORMAT_NODE_ARRAY || node.u.list->num == 0) { - mpv_free_node_contents(&node); - return NULL; - } - mp_edition_list *list = talloc_ptrtype(talloc_ctx, list); memset(list, 0, sizeof(*list)); + mpv_node node; + if (mpv_get_property(ctx->mpv, "edition-list", MPV_FORMAT_NODE, &node) < 0) + return list; + for (int i = 0; i < node.u.list->num; i++) { mpv_node edition = node.u.list->values[i]; @@ -282,18 +267,13 @@ mp_edition_list *mp_get_edition_list(void *talloc_ctx) { } mp_audio_device_list *mp_get_audio_device_list(void *talloc_ctx) { - mpv_node node; + mp_audio_device_list *list = talloc_ptrtype(talloc_ctx, list); + memset(list, 0, sizeof(*list)); + mpv_node node; if (mpv_get_property(ctx->mpv, "audio-device-list", MPV_FORMAT_NODE, &node) < 0) - return NULL; - if (node.format != MPV_FORMAT_NODE_ARRAY || node.u.list->num == 0) { - mpv_free_node_contents(&node); - return NULL; - } - - mp_audio_device_list *list = talloc_ptrtype(talloc_ctx, list); - memset(list, 0, sizeof(*list)); + return list; for (int i = 0; i < node.u.list->num; i++) { mpv_node device = node.u.list->values[i];