[vlc-devel] [PATCH] LUA: add support for category field in SD nodes and items

Gaurav Narula gnarula94 at gmail.com
Fri Jan 13 17:33:19 CET 2012


Improved log messages. Close #3454
---
 modules/lua/libs/sd.c |   31 +++++++++++++++++++++++++------
 share/lua/README.txt  |    4 +++-
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/modules/lua/libs/sd.c b/modules/lua/libs/sd.c
index d88cab2..699ad84 100644
--- a/modules/lua/libs/sd.c
+++ b/modules/lua/libs/sd.c
@@ -128,7 +128,12 @@ static int vlclua_sd_add_node( lua_State *L )
                     input_item_SetArtURL( p_input, psz_value );
                     free( psz_value );
                 }
-                services_discovery_AddItem( p_sd, p_input, NULL );
+                lua_pop( L, 1 );
+                lua_getfield( L, -1, "category" );
+                if( lua_isstring( L, -1 ) )
+                    services_discovery_AddItem( p_sd, p_input, lua_tostring( L, -1 ) );
+                else
+                    services_discovery_AddItem( p_sd, p_input, NULL );
                 input_item_t **udata = (input_item_t **)
                                        lua_newuserdata( L, sizeof( input_item_t * ) );
                 *udata = p_input;
@@ -160,11 +165,20 @@ static int vlclua_sd_add_item( lua_State *L )
             char **ppsz_options = NULL;
             int i_options = 0;
             const char *psz_path = lua_tostring( L, -1 );
+            input_item_t *p_input;
             vlclua_read_options( p_sd, L, &i_options, &ppsz_options );
-            input_item_t *p_input = input_item_NewExt( psz_path, psz_path,
-                                                       i_options,
-                                                       (const char **)ppsz_options,
-                                                       VLC_INPUT_OPTION_TRUSTED, -1 );
+            lua_pop( L, 1 );
+            lua_getfield( L, -1, "title" );
+            if( lua_isstring( L, -1 ) )
+                p_input = input_item_NewExt( psz_path, lua_tostring( L, -1 ),
+                                             i_options,
+                                             (const char **)ppsz_options,
+                                             VLC_INPUT_OPTION_TRUSTED, -1 );
+            else
+                p_input = input_item_NewExt( psz_path, psz_path,
+                                             i_options,
+                                             (const char **)ppsz_options,
+                                             VLC_INPUT_OPTION_TRUSTED, -1 );
             lua_pop( L, 1 );
 
             if( p_input )
@@ -179,7 +193,12 @@ static int vlclua_sd_add_item( lua_State *L )
                 else if( !lua_isnil( L, -1 ) )
                     msg_Warn( p_sd, "Item duration should be a number (in seconds)." );
                 lua_pop( L, 1 );
-                services_discovery_AddItem( p_sd, p_input, NULL );
+                lua_getfield( L, -1, "category" );
+                if( lua_isstring( L, -1 ) )
+                    services_discovery_AddItem( p_sd, p_input, lua_tostring( L, -1 ) );
+                else
+                    services_discovery_AddItem( p_sd, p_input, NULL );
+                lua_pop( L, 1 );
                 input_item_t **udata = (input_item_t **)
                                        lua_newuserdata( L, sizeof( input_item_t * ) );
                 *udata = p_input;
diff --git a/share/lua/README.txt b/share/lua/README.txt
index aae5ed0..91cafae 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -329,8 +329,10 @@ sd.add_node( ... ): Add a node to the service discovery.
   The node object has the following members:
       .title: the node's name
       .arturl: the node's ArtURL (OPTIONAL)
+      .category: the node's category (OPTIONAL)
 sd.add_item( ... ): Add an item to the service discovery.
-  The item object has the same members as the one in playlist.add().
+  The item object has the same members as the one in playlist.add() along with:
+      .category: the item's category (OPTIONAL)
   Returns the input item.
 sd.remove_item( item ): remove the item.
 
-- 
1.7.1




More information about the vlc-devel mailing list