struct demux_sys_t
{
lua_State *p_state;
+ char *psz_filename;
};
+/*****************************************************************************
+ *
+ *****************************************************************************/
static demux_t *vlclua_get_demux( lua_State *p_state )
{
demux_t *p_demux;
return 1;
}
+static int vlclua_msg_dbg( lua_State *p_state )
+{
+ demux_t *p_demux = vlclua_get_demux( p_state );
+ int i = lua_gettop( p_state );
+ if( !i ) return 0;
+ const char *psz_cstring = lua_tostring( p_state, 1 );
+ if( !psz_cstring ) return 0;
+ msg_Dbg( p_demux, "%s: %s", p_demux->p_sys->psz_filename, psz_cstring );
+ return 0;
+}
+static int vlclua_msg_warn( lua_State *p_state )
+{
+ demux_t *p_demux = vlclua_get_demux( p_state );
+ int i = lua_gettop( p_state );
+ if( !i ) return 0;
+ const char *psz_cstring = lua_tostring( p_state, 1 );
+ if( !psz_cstring ) return 0;
+ msg_Warn( p_demux, "%s: %s", p_demux->p_sys->psz_filename, psz_cstring );
+ return 0;
+}
+static int vlclua_msg_err( lua_State *p_state )
+{
+ demux_t *p_demux = vlclua_get_demux( p_state );
+ int i = lua_gettop( p_state );
+ if( !i ) return 0;
+ const char *psz_cstring = lua_tostring( p_state, 1 );
+ if( !psz_cstring ) return 0;
+ msg_Err( p_demux, "%s: %s", p_demux->p_sys->psz_filename, psz_cstring );
+ return 0;
+}
+static int vlclua_msg_info( lua_State *p_state )
+{
+ demux_t *p_demux = vlclua_get_demux( p_state );
+ int i = lua_gettop( p_state );
+ if( !i ) return 0;
+ const char *psz_cstring = lua_tostring( p_state, 1 );
+ if( !psz_cstring ) return 0;
+ msg_Info( p_demux, "%s: %s", p_demux->p_sys->psz_filename, psz_cstring );
+ return 0;
+}
+
+/* Functions to register */
+static luaL_Reg p_reg[] =
+{
+ { "peek", vlclua_peek },
+ { "decode_uri", vlclua_decode_uri },
+ { "resolve_xml_special_chars", vlclua_resolve_xml_special_chars },
+ { "msg_dbg", vlclua_msg_dbg },
+ { "msg_warn", vlclua_msg_warn },
+ { "msg_err", vlclua_msg_err },
+ { "msg_info", vlclua_msg_info },
+ { NULL, NULL }
+};
+
+/* Functions to register for parse() function call only */
+static luaL_Reg p_reg_parse[] =
+{
+ { "read", vlclua_read },
+ { "readline", vlclua_readline },
+ { NULL, NULL }
+};
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
static int file_select( const char *file )
{
int i = strlen( file );
}
# endif
- static luaL_Reg p_reg[] =
- {
- { "peek", vlclua_peek },
- { "read", vlclua_read },
- { "readline", vlclua_readline },
- { "decode_uri", vlclua_decode_uri },
- { "resolve_xml_special_chars", vlclua_resolve_xml_special_chars }
- };
-
p_demux->p_sys = (demux_sys_t*)malloc( sizeof( demux_sys_t ) );
if( !p_demux->p_sys )
{
free( psz_filename ); psz_filename = NULL;
asprintf( &psz_filename, "%s/%s", psz_dir, *ppsz_file );
msg_Dbg( p_demux, "Trying Lua playlist script %s", psz_filename );
+ p_demux->p_sys->psz_filename = psz_filename;
/* Ugly hack to delete previous versions of the probe() and parse()
* functions. */
}
error:
- free( psz_filename );
-
if( ppsz_filelist )
{
for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;
{
demux_t *p_demux = (demux_t *)p_this;
lua_close( p_demux->p_sys->p_state );
+ free( p_demux->p_sys->psz_filename );
free( p_demux->p_sys );
}
{
input_item_t *p_input;
lua_State *p_state = p_demux->p_sys->p_state;
- char psz_filename[] = "FIXME";
+ char *psz_filename = p_demux->p_sys->psz_filename;
INIT_PLAYLIST_STUFF;
+ luaL_register( p_state, "vlc", p_reg_parse );
+
lua_getglobal( p_state, "parse" );
if( !lua_isfunction( p_state, lua_gettop( p_state ) ) )
-See "youtube.lua" for instructions to code your own Lua playlist script.
+Instructions to code your own VLC Lua playlist script.
+$Id: $
+
+Examples: See dailymotion.lua, googlevideo.lua, metacafe.lua and youbtube.lua.
+
+VLC Lua playlist modules should define two functions:
+ * probe(): returns true if we want to handle the playlist in this script
+ * parse(): read the incoming data and return playlist item(s)
+ The playlist is a table of playlist objects.
+ A playlist object has the following members:
+ .path: the item's full path / URL
+ .name: the item's name in playlist (OPTIONAL)
+ .title: the item's Title (OPTIONAL, meta data)
+ .artist: the item's Artist (OPTIONAL, meta data)
+ .genre: the item's Genre (OPTIONAL, meta data)
+ .copyright: the item's Copyright (OPTIONAL, meta data)
+ .album: the item's Album (OPTIONAL, meta data)
+ .tracknum: the item's Tracknum (OPTIONAL, meta data)
+ .description: the item's Description (OPTIONAL, meta data)
+ .rating: the item's Rating (OPTIONAL, meta data)
+ .date: the item's Date (OPTIONAL, meta data)
+ .setting: the item's Setting (OPTIONAL, meta data)
+ .url: the item's URL (OPTIONAL, meta data)
+ .language: the item's Language (OPTIONAL, meta data)
+ .nowplaying: the item's NowPlaying (OPTIONAL, meta data)
+ .publisher: the item's Publisher (OPTIONAL, meta data)
+ .encodedby: the item's EncodedBy (OPTIONAL, meta data)
+ .arturl: the item's ArtURL (OPTIONAL, meta data)
+ .trackid: the item's TrackID (OPTIONAL, meta data)
+ Invalid playlist items will be discarded by VLC.
+
+VLC defines a global vlc object with the following members:
+ * vlc.path: the URL string (without the leading http:// or file:// element)
+ * vlc.access: the access used ("http" for http://, "file" for file://, etc.)
+ * vlc.peek( <int> ): return the first <int> characters from the playlist file.
+ * vlc.read( <int> ): read <int> characters from the playlist file.
+ THIS FUNCTION CANNOT BE USED IN peek().
+ * vlc.readline(): return a new line of playlist data on each call.
+ THIS FUNCTION CANNOT BE USED IN peek().
+ * vlc.decode_uri( <string> ): decode %xy characters in a string.
+ * vlc.resolve_xml_special_chars( <string> ): decode &abc; characters in a
+ string.
+ * vlc.msg_dbg( <string> ): print a debug message.
+ * vlc.msg_warn( <string> ): print a warning message.
+ * vlc.msg_err( <string> ): print an error message.
+ * vlc.msg_info( <string> ): print an info message.
+
+Lua scripts are tried in alphabetical order in the luaplaylist/ directory.
+
+Lua documentation is available on http://www.lua.org .
+VLC uses Lua 5.1
+All the Lua standard libraries are available.
-- $Id$
---[[
-VLC Lua playlist modules should define two functions:
- * probe(): returns true if we want to handle the playlist in this script
- * parse(): read the incoming data and return playlist item(s)
- The playlist is a table of playlist objects.
- A playlist object has the following members:
- .path: the item's full path / URL
- .name: the item's name in playlist (OPTIONAL)
- .title: the item's Title (OPTIONAL, meta data)
- .artist: the item's Artist (OPTIONAL, meta data)
- .genre: the item's Genre (OPTIONAL, meta data)
- .copyright: the item's Copyright (OPTIONAL, meta data)
- .album: the item's Album (OPTIONAL, meta data)
- .tracknum: the item's Tracknum (OPTIONAL, meta data)
- .description: the item's Description (OPTIONAL, meta data)
- .rating: the item's Rating (OPTIONAL, meta data)
- .date: the item's Date (OPTIONAL, meta data)
- .setting: the item's Setting (OPTIONAL, meta data)
- .url: the item's URL (OPTIONAL, meta data)
- .language: the item's Language (OPTIONAL, meta data)
- .nowplaying: the item's NowPlaying (OPTIONAL, meta data)
- .publisher: the item's Publisher (OPTIONAL, meta data)
- .encodedby: the item's EncodedBy (OPTIONAL, meta data)
- .arturl: the item's ArtURL (OPTIONAL, meta data)
- .trackid: the item's TrackID (OPTIONAL, meta data)
- Invalid playlist items will be discarded by VLC.
-
-VLC defines a global vlc object with the following members:
- * vlc.path: the URL string (without the leading http:// or file:// element)
- * vlc.access: the access used ("http" for http://, "file" for file://, etc.)
- * vlc.peek( <int> ): return the first <int> characters from the playlist file.
- * vlc.read( <int> ): read <int> characters from the playlist file.
- THIS FUNCTION SHOULD NOT BE USED IN peek().
- * vlc.readline(): return a new line of playlist data on each call.
- THIS FUNCTION SHOULD NOT BE USED IN peek().
- * vlc.decode_uri( <string> ): decode %xy characters in a string.
- * vlc.resolve_xml_special_chars( <string> ): decode &abc; characters in a string.
-
-Lua scripts are tried in alphabetical order in the luaplaylist/ directory.
-
-Lua documentation is available on http://www.lua.org .
-VLC uses Lua 5.1
-All the Lua standard libraries are available.
---]]
-
-- Helper function to get a parameter's value in a URL
function get_url_param( url, name )
return string.gsub( vlc.path, "^.*"..name.."=([^&]*).*$", "%1" )