[vlc-devel] [PATCH] Lua SD: add methods to item object to change metadata

Edward Wang edward.c.wang at compdigitec.com
Thu Jan 12 21:54:39 CET 2012


Close #3474
---
 modules/lua/libs/sd.c |   64 +++++++++++++++++++++++++++++++++++++++++++++++++
 share/lua/README.txt  |   20 +++++++++++++++
 2 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/modules/lua/libs/sd.c b/modules/lua/libs/sd.c
index 67e1eb1..30fd0ef 100644
--- a/modules/lua/libs/sd.c
+++ b/modules/lua/libs/sd.c
@@ -54,6 +54,64 @@ static const luaL_Reg vlclua_node_reg[] = {
     { NULL, NULL }
 };
 
+#define vlclua_item_luareg( a ) \
+{ "set_" # a, vlclua_item_set_ ## a },
+
+#define vlclua_item_meta( lowercase, normal ) \
+static int vlclua_item_set_ ## lowercase ( lua_State *L )\
+{\
+    services_discovery_t *p_sd = (services_discovery_t *)vlclua_get_this( L );\
+    input_item_t **pp_node = (input_item_t **)luaL_checkudata( L, 1, "input_item_t" );\
+    if( *pp_node )\
+    {\
+        if( lua_isstring( L, -1 ) )\
+        {\
+            input_item_Set ## normal ( *pp_node, lua_tostring( L, -1 ) );\
+        } else\
+            msg_Err( p_sd, "Error parsing set_ " # lowercase " arguments" );\
+    }\
+    return 1;\
+}
+
+vlclua_item_meta(title, Title)
+vlclua_item_meta(artist, Artist)
+vlclua_item_meta(genre, Genre)
+vlclua_item_meta(copyright, Copyright)
+vlclua_item_meta(album, Album)
+vlclua_item_meta(tracknum, TrackNum)
+vlclua_item_meta(description, Description)
+vlclua_item_meta(rating, Rating)
+vlclua_item_meta(date, Date)
+vlclua_item_meta(setting, Setting)
+vlclua_item_meta(url, URL)
+vlclua_item_meta(language, Language)
+vlclua_item_meta(nowplaying, NowPlaying)
+vlclua_item_meta(publisher, Publisher)
+vlclua_item_meta(encodedby, EncodedBy)
+vlclua_item_meta(arturl, ArtworkURL)
+vlclua_item_meta(trackid, TrackID)
+
+static const luaL_Reg vlclua_item_reg[] = {
+    vlclua_item_luareg(title)
+    vlclua_item_luareg(artist)
+    vlclua_item_luareg(genre)
+    vlclua_item_luareg(copyright)
+    vlclua_item_luareg(album)
+    vlclua_item_luareg(tracknum)
+    vlclua_item_luareg(description)
+    vlclua_item_luareg(rating)
+    vlclua_item_luareg(date)
+    vlclua_item_luareg(setting)
+    vlclua_item_luareg(url)
+    vlclua_item_luareg(language)
+    vlclua_item_luareg(nowplaying)
+    vlclua_item_luareg(publisher)
+    vlclua_item_luareg(encodedby)
+    vlclua_item_luareg(arturl)
+    vlclua_item_luareg(trackid)
+    { NULL, NULL }
+};
+
 static int vlclua_sd_get_services_names( lua_State *L )
 {
     playlist_t *p_playlist = vlclua_get_playlist_internal( L );
@@ -185,6 +243,9 @@ static int vlclua_sd_add_item( lua_State *L )
                 *udata = p_input;
                 if( luaL_newmetatable( L, "input_item_t" ) )
                 {
+                    lua_newtable( L );
+                    luaL_register( L, NULL, vlclua_item_reg );
+                    lua_setfield( L, -2, "__index" );
                     lua_pushliteral( L, "none of your business" );
                     lua_setfield( L, -2, "__metatable" );
                 }
@@ -264,6 +325,9 @@ static int vlclua_node_add_subitem( lua_State *L )
                     *udata = p_input;
                     if( luaL_newmetatable( L, "input_item_t" ) )
                     {
+                        lua_newtable( L );
+                        luaL_register( L, NULL, vlclua_item_reg );
+                        lua_setfield( L, -2, "__index" );
                         lua_pushliteral( L, "none of your business" );
                         lua_setfield( L, -2, "__metatable" );
                     }
diff --git a/share/lua/README.txt b/share/lua/README.txt
index 747d8e4..b22fbd0 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -338,6 +338,26 @@ n = vlc.sd.add_node( {title="Node"} )
 n:add_subitem( ... ): Same as sd.add_item(), but as a subitem of n.
 n:add_subnode( ... ): Same as sd.add_node(), but as a subnode of n.
 
+d = vlc.sd.add_item( ... ) Get an item object to perform following set operations on it:
+d:set_name(): the item's name in playlist
+d:set_title(): the item's Title (OPTIONAL, meta data)
+d:set_artist(): the item's Artist (OPTIONAL, meta data)
+d:set_genre(): the item's Genre (OPTIONAL, meta data)
+d:set_copyright(): the item's Copyright (OPTIONAL, meta data)
+d:set_album(): the item's Album (OPTIONAL, meta data)
+d:set_tracknum(): the item's Tracknum (OPTIONAL, meta data)
+d:set_description(): the item's Description (OPTIONAL, meta data)
+d:set_rating(): the item's Rating (OPTIONAL, meta data)
+d:set_date(): the item's Date (OPTIONAL, meta data)
+d:set_setting(): the item's Setting (OPTIONAL, meta data)
+d:set_url(): the item's URL (OPTIONAL, meta data)
+d:set_language(): the item's Language (OPTIONAL, meta data)
+d:set_nowplaying(): the item's NowPlaying (OPTIONAL, meta data)
+d:set_publisher(): the item's Publisher (OPTIONAL, meta data)
+d:set_encodedby(): the item's EncodedBy (OPTIONAL, meta data)
+d:set_arturl(): the item's ArtURL (OPTIONAL, meta data)
+d:set_trackid(): the item's TrackID (OPTIONAL, meta data)
+
 Stream
 ------
 stream( url ): Instantiate a stream object for specific url.
-- 
1.7.5.4




More information about the vlc-devel mailing list