Skip to content

Commit

Permalink
fix menu item count check
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Dec 18, 2023
1 parent a37d6b3 commit 995eb94
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 40 deletions.
20 changes: 16 additions & 4 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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;
Expand Down
52 changes: 16 additions & 36 deletions src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 995eb94

Please sign in to comment.