From 7a3a6d64ad8a70e6e7526fd6bd5697e4450664ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Duraffort?= Date: Sat, 18 Jun 2011 16:55:03 +0200 Subject: [PATCH] lua playlist: add custom metadata to extra metadata instead of input item information. Fix #4822 and #4823. --- modules/lua/vlc.c | 68 ++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 48 deletions(-) diff --git a/modules/lua/vlc.c b/modules/lua/vlc.c index aeb7c86413..5bdbe28b82 100644 --- a/modules/lua/vlc.c +++ b/modules/lua/vlc.c @@ -404,6 +404,12 @@ void __vlclua_read_meta_data( vlc_object_t *p_this, lua_State *L, void __vlclua_read_custom_meta_data( vlc_object_t *p_this, lua_State *L, input_item_t *p_input ) { + /* Lock the input item and create the meta table if needed */ + vlc_mutex_lock( &p_input->lock ); + + if( !p_input->p_meta ) + p_input->p_meta = vlc_meta_New(); + /* ... item */ lua_getfield( L, -1, "meta" ); /* ... item meta */ @@ -414,60 +420,26 @@ void __vlclua_read_custom_meta_data( vlc_object_t *p_this, lua_State *L, while( lua_next( L, -2 ) ) { /* ... item meta key value */ - if( !lua_isstring( L, -2 ) ) - { - msg_Warn( p_this, "Custom meta data category name must be " - "a string" ); - } - else if( !lua_istable( L, -1 ) ) - { - msg_Warn( p_this, "Custom meta data category contents " - "must be a table" ); - } - else + printf("%s => %s\n", lua_typename(L, lua_type(L, -2)), + lua_typename(L, lua_type(L, -1))); + if( !lua_isstring( L, -2 ) || !lua_isstring( L, -1 ) ) { - const char *psz_meta_category = lua_tostring( L, -2 ); - msg_Dbg( p_this, "Found custom meta data category: %s", - psz_meta_category ); - lua_pushnil( L ); - /* ... item meta key value nil */ - while( lua_next( L, -2 ) ) - { - /* ... item meta key value key2 value2 */ - if( !lua_isstring( L, -2 ) ) - { - msg_Warn( p_this, "Custom meta category item name " - "must be a string." ); - } - else if( !lua_isstring( L, -1 ) ) - { - msg_Warn( p_this, "Custom meta category item value " - "must be a string." ); - } - else - { - const char *psz_meta_name = - lua_tostring( L, -2 ); - const char *psz_meta_value = - lua_tostring( L, -1 ); - msg_Dbg( p_this, "Custom meta %s, %s: %s", - psz_meta_category, psz_meta_name, - psz_meta_value ); - input_item_AddInfo( p_input, psz_meta_category, - psz_meta_name, "%s", psz_meta_value ); - } - lua_pop( L, 1 ); /* pop item */ - /* ... item meta key value key2 */ - } - /* ... item meta key value */ + msg_Err( p_this, "'meta' keys and values must be strings"); + lua_pop( L, 1 ); /* pop "value" */ + continue; } - lua_pop( L, 1 ); /* pop category */ - /* ... item meta key */ + const char *psz_key = lua_tostring( L, -2 ); + const char *psz_value = lua_tostring( L, -1 ); + + vlc_meta_AddExtra( p_input->p_meta, psz_key, psz_value ); + + lua_pop( L, 1 ); /* pop "value" */ } - /* ... item meta */ } lua_pop( L, 1 ); /* pop "meta" */ /* ... item -> back to original stack */ + + vlc_mutex_unlock( &p_input->lock ); } /***************************************************************************** -- 2.39.2