mirror of
https://github.com/mpv-player/mpv
synced 2025-04-01 00:07:33 +00:00
command: export profile list as a property
Targeted at scripts, which can do whatever they want with it. This comes with the promise that they could get randomly broken any time. See #977.
This commit is contained in:
parent
a9a55ea7f2
commit
f42e4374d5
@ -2211,6 +2211,14 @@ Property list
|
||||
``property-list``
|
||||
Return the list of top-level properties.
|
||||
|
||||
``profile-list``
|
||||
Return the list of profiles and their contents. This is highly
|
||||
implementation-specific, and may change any time. Currently, it returns
|
||||
an array of options for each profile. Each option has a name and a value,
|
||||
with the value currently always being a string. Note that the options array
|
||||
is not a map, as order matters and duplicate entries are possible. Recursive
|
||||
profiles are not expanded, and show up as special ``profile`` options.
|
||||
|
||||
Property Expansion
|
||||
------------------
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "options/m_option.h"
|
||||
#include "common/msg.h"
|
||||
#include "common/msg_control.h"
|
||||
#include "misc/node.h"
|
||||
|
||||
static const union m_option_value default_value;
|
||||
|
||||
@ -933,6 +934,32 @@ int m_config_set_profile(struct m_config *config, char *name, int flags)
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct mpv_node m_config_get_profiles(struct m_config *config)
|
||||
{
|
||||
struct mpv_node root;
|
||||
node_init(&root, MPV_FORMAT_NODE_ARRAY, NULL);
|
||||
|
||||
for (m_profile_t *profile = config->profiles; profile; profile = profile->next)
|
||||
{
|
||||
struct mpv_node *entry = node_array_add(&root, MPV_FORMAT_NODE_MAP);
|
||||
|
||||
node_map_add_string(entry, "name", profile->name);
|
||||
if (profile->desc)
|
||||
node_map_add_string(entry, "profile-desc", profile->desc);
|
||||
|
||||
struct mpv_node *opts =
|
||||
node_map_add(entry, "options", MPV_FORMAT_NODE_ARRAY);
|
||||
|
||||
for (int n = 0; n < profile->num_opts; n++) {
|
||||
struct mpv_node *opt_entry = node_array_add(opts, MPV_FORMAT_NODE_MAP);
|
||||
node_map_add_string(opt_entry, "key", profile->opts[n * 2 + 0]);
|
||||
node_map_add_string(opt_entry, "value", profile->opts[n * 2 + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
void *m_config_alloc_struct(void *talloc_ctx,
|
||||
const struct m_sub_options *subopts)
|
||||
{
|
||||
|
@ -247,6 +247,8 @@ int m_config_set_profile_option(struct m_config *config, struct m_profile *p,
|
||||
*/
|
||||
int m_config_set_profile(struct m_config *config, char *name, int flags);
|
||||
|
||||
struct mpv_node m_config_get_profiles(struct m_config *config);
|
||||
|
||||
void *m_config_alloc_struct(void *talloc_ctx,
|
||||
const struct m_sub_options *subopts);
|
||||
|
||||
|
@ -3668,6 +3668,22 @@ static int mp_property_list(void *ctx, struct m_property *prop,
|
||||
return M_PROPERTY_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static int mp_profile_list(void *ctx, struct m_property *prop,
|
||||
int action, void *arg)
|
||||
{
|
||||
MPContext *mpctx = ctx;
|
||||
switch (action) {
|
||||
case M_PROPERTY_GET_TYPE:
|
||||
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE};
|
||||
return M_PROPERTY_OK;
|
||||
case M_PROPERTY_GET: {
|
||||
*(struct mpv_node *)arg = m_config_get_profiles(mpctx->mconfig);
|
||||
return M_PROPERTY_OK;
|
||||
}
|
||||
}
|
||||
return M_PROPERTY_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// Redirect a property name to another
|
||||
#define M_PROPERTY_ALIAS(name, real_property) \
|
||||
{(name), mp_property_alias, .priv = (real_property)}
|
||||
@ -3911,6 +3927,7 @@ static const struct m_property mp_properties[] = {
|
||||
{"file-local-options", mp_property_local_options},
|
||||
{"option-info", mp_property_option_info},
|
||||
{"property-list", mp_property_list},
|
||||
{"profile-list", mp_profile_list},
|
||||
|
||||
// compatibility
|
||||
M_PROPERTY_ALIAS("video", "vid"),
|
||||
|
Loading…
Reference in New Issue
Block a user