[vlc-devel] [PATCH] http lua: allow request for extra information on playlist and request for specific playlist node

Rafaël Carré funman at videolan.org
Wed Mar 14 10:44:24 CET 2012


Hello,

Le 04/03/2012 13:22, Tristan Lanfrey a écrit :
> On Sun, Mar 4, 2012 at 5:24 PM, Rob Jonson <rob at hobbyistsoftware.com> wrote:
>> > please bump the API number to s.apiversion=3 to indicate these changes
>> >
>> > the readme should also indicate that the new commands are available
>> > from apiversion 3
>> >
> Attached with api version 3 and renamed metas to meta.
> 
> Thanks for reviewing.
> 
> -- Tristan LANFREY
> 
> 
> 0001-http-lua-allow-request-for-extra-information-on-play.patch
> 
> 
> From fc8fc0e0329adb146b10d987160dd2ee85f61ec8 Mon Sep 17 00:00:00 2001
> From: Tristan Lanfrey <tristan.lanfrey at gmail.com>
> Date: Sat, 3 Dec 2011 19:21:59 +0000
> Subject: [PATCH] http lua: allow request for extra information on playlist
>  and request for specific playlist node.
> 
> ---
>  modules/lua/libs/playlist.c             |   81 +++++++++++++++++++++++++++++--
>  share/lua/http/requests/README.txt      |    9 ++++
>  share/lua/intf/modules/httprequests.lua |   10 +++-
>  3 files changed, 93 insertions(+), 7 deletions(-)
> 
> diff --git a/modules/lua/libs/playlist.c b/modules/lua/libs/playlist.c
> index 7b1f697..0c14157 100644
> --- a/modules/lua/libs/playlist.c
> +++ b/modules/lua/libs/playlist.c
> @@ -35,6 +35,7 @@
>  #include <vlc_common.h>
>  
>  #include <vlc_interface.h>
> +#include <vlc_input.h>
>  #include <vlc_playlist.h>
>  
>  #include "../vlc.h"
> @@ -45,6 +46,43 @@
>  /*****************************************************************************
>   * Internal lua<->vlc utils
>   *****************************************************************************/
> +/* The following enum + static (name->enum) dictionary define the

english: defines

> + * possible extra info options we can ask to be pushed onto the lua
> + * stack when getting the playlist.
> + */
> +typedef enum
> +{
> +    LUA_PL_EXTRA_INVLID   = 0x0000,  /**< No/unknown/invalid option */

s/INVLID/INVALID/ ?

> +    LUA_PL_EXTRA_META     = 0x0001,  /**< Do we want meta data? */
> +} lua_pl_extra_flags_e;
> +
> +typedef struct pl_extra_options_entry_t
> +{
> +    const char                    *psz_key;
> +    const lua_pl_extra_flags_e    flag;
> +} pl_extra_options_entry_t;
> +
> +/* static dictionary to match an option name to an option flag */
> +static const pl_extra_options_entry_t pl_extra_options[] =
> +{
> +    { "meta",     LUA_PL_EXTRA_META },
> +    { NULL,       LUA_PL_EXTRA_INVLID }
> +};
> +
> +/* find the option flag associated to the given option name */
> +static lua_pl_extra_flags_e vlclua_playlist_get_extra_option(const char *psz_option)
> +{
> +    for (int i = 0; pl_extra_options[i].psz_key != NULL; ++i)
> +    {
> +        if (!strncmp(pl_extra_options[i].psz_key, psz_option,
> +                     strlen(pl_extra_options[i].psz_key) + 1))

Why not strcmp ?

> +        {
> +            return pl_extra_options[i].flag;
> +        }
> +    }
> +    return LUA_PL_EXTRA_INVLID;
> +}
> +
>  playlist_t *vlclua_get_playlist_internal( lua_State *L )
>  {
>      vlc_object_t *p_this = vlclua_get_this( L );
> @@ -167,7 +205,7 @@ static int vlclua_playlist_enqueue( lua_State *L )
>      return 1;
>  }
>  
> -static void push_playlist_item( lua_State *L, playlist_item_t *p_item )
> +static void push_playlist_item( lua_State *L, playlist_item_t *p_item, int i_extra)

I think i_extra should be renamed to i_flags, it makes it more obvious
that it is a bitfield IMO.

>  {
>      input_item_t *p_input = p_item->p_input;
>      int i_flags = 0;
> @@ -205,7 +243,22 @@ static void push_playlist_item( lua_State *L, playlist_item_t *p_item )
>          lua_setfield( L, -2, "duration" );
>          lua_pushinteger( L, p_input->i_nb_played );
>          lua_setfield( L, -2, "nb_played" );
> -        /* TODO: add (optional) info categories, meta, options, es */
> +        /* TODO: add (optional) info categories, options, es */
> +        if (i_extra & LUA_PL_EXTRA_META)
> +        {
> +            /* push a new table for meta data */
> +            lua_newtable( L );
> +            for (size_t meta_type = 0; meta_type < VLC_META_TYPE_COUNT; ++meta_type)

Why ++meta and not meta++ ?

> +            {
> +                const char * meta = input_item_GetMeta( p_input, meta_type );
> +                if (meta != NULL && strlen(meta))
> +                {
> +                    lua_pushstring( L, input_item_GetMeta( p_input, meta_type ) );
> +                    lua_setfield( L, -2, vlc_meta_TypeToLocalizedString( meta_type ) );

I am not sure if localized meta field is a good idea, especially since
this interface is made for parsers and not humans:

    "URL de la jaquette":"attachment://0",

Would be better as "URL cover" or whatever the english string is, so a
parser doesn't need to reverse the translation.

> +                }
> +            }
> +            lua_setfield( L, -2, "meta" );
> +        }
>      }
>      if( p_item->i_children >= 0 )
>      {
> @@ -213,7 +266,7 @@ static void push_playlist_item( lua_State *L, playlist_item_t *p_item )
>          lua_createtable( L, p_item->i_children, 0 );
>          for( i = 0; i < p_item->i_children; i++ )
>          {
> -            push_playlist_item( L, p_item->pp_children[i] );
> +            push_playlist_item( L, p_item->pp_children[i], i_extra );
>              lua_rawseti( L, -2, i+1 );
>          }
>          lua_setfield( L, -2, "children" );
> @@ -263,7 +316,25 @@ static int vlclua_playlist_get( lua_State *L )
>      {
>          p_item = p_playlist->p_root;
>      }
> -    push_playlist_item( L, p_item );
> +    int i_extra = 0;
> +    if (lua_istable( L, 2 ))
> +    {
> +        /* second element is a lua array (table) of strings telling us
> +           what extra info we want. We turn each string into an enum and
> +           'or' them together to have a C-style options int. */
> +        lua_pushnil(L);
> +        while (lua_next(L, 2) != 0)
> +        {
> +            /* find the option name in our name->enum dictionary and
> +               bitwise or with what we've already parsed so far */
> +            i_extra |= vlclua_playlist_get_extra_option(lua_tostring( L, -1 ));
> +            /* removes 'value'; keeps 'key' for next iteration */
> +            lua_pop(L, 1);
> +        }
> +        /* pop so we don't interfere with push_playlist_item */
> +        lua_pop(L, 1);
> +    }
> +    push_playlist_item( L, p_item, i_extra);
>      PL_UNLOCK;
>      return 1;
>  }
> @@ -275,7 +346,7 @@ static int vlclua_playlist_search( lua_State *L )
>      PL_LOCK;
>      playlist_LiveSearchUpdate( p_playlist, p_playlist->p_root, psz_string, true );
>      PL_UNLOCK;
> -    push_playlist_item( L, p_playlist->p_root );
> +    push_playlist_item( L, p_playlist->p_root, 0 );
>      return 1;
>  }
>  
> diff --git a/share/lua/http/requests/README.txt b/share/lua/http/requests/README.txt
> index 95d1f4e..24e098f 100644
> --- a/share/lua/http/requests/README.txt
> +++ b/share/lua/http/requests/README.txt
> @@ -175,6 +175,15 @@ playlist.xml or playlist.json:
>  NB: playlist_jstree.xml is used for the internal web client. It should not be relied upon by external remotes.
>  It may be removed without notice.
>  
> +< get a specific node of the playlist (from http api version 3)
> +  ?what=<node>
> +
> +< get extra information for playlist items (from http api version 3)
> +  ?extra=<extra>
> +  <extra> is a pipe separated list of extra info labels required (e.g: 'meta' or 'meta|...')
> +  supported extra infos:
> +            - meta
> +
>  browse.xml or browse.json:
>  ===========
>  
> diff --git a/share/lua/intf/modules/httprequests.lua b/share/lua/intf/modules/httprequests.lua
> index 52f3531..b46a2bd 100644
> --- a/share/lua/intf/modules/httprequests.lua
> +++ b/share/lua/intf/modules/httprequests.lua
> @@ -289,7 +289,12 @@ getplaylist = function ()
>        local key = vlc.strings.decode_uri(_GET["search"])
>        p = vlc.playlist.search(key)
>      else
> -      p = vlc.playlist.get()
> +      local what = vlc.strings.decode_uri(_GET['what']) or 'root'
> +      local extraTable = nil
> +      if _GET['extra'] then
> +         extraTable = strsplit(_GET['extra'], '|')
> +      end
> +      p = vlc.playlist.get(what, extraTable)
>      end
>  
>      --logTable(p) --Uncomment to debug
> @@ -339,6 +344,7 @@ parseplaylist = function (item)
>          result.name=name
>          result.ro=item.flags.ro and "ro" or "rw"
>          result.duration=math.floor(item.duration)
> +        result.meta=item.meta
>  
>          return result
>      end
> @@ -437,7 +443,7 @@ local aout = vlc.object.aout()
>      local s ={}
>  
>      --update api version when new data/commands added
> -    s.apiversion=2
> +    s.apiversion=3
>      s.version=vlc.misc.version()
>      s.volume=vlc.volume.get()



More information about the vlc-devel mailing list