Commit add15152 authored by Antoine Cellerier's avatar Antoine Cellerier

* luaplaylist.c, README.txt: add support for VLC options.

* *.lua: misc fixes.
parent 93d0208e
...@@ -472,34 +472,70 @@ static int Demux( demux_t *p_demux ) ...@@ -472,34 +472,70 @@ static int Demux( demux_t *p_demux )
{ {
if( lua_istable( p_state, t+2 ) ) if( lua_istable( p_state, t+2 ) )
{ {
const char *psz_url = NULL;
const char *psz_title = NULL;
lua_getfield( p_state, t+2, "path" ); lua_getfield( p_state, t+2, "path" );
if( lua_isstring( p_state, t+3 ) ) if( lua_isstring( p_state, t+3 ) )
{ {
psz_url = lua_tostring( p_state, t+3 ); const char *psz_path = NULL;
msg_Dbg( p_demux, "Path: %s", psz_url ); const char *psz_name = NULL;
char **ppsz_options = NULL;
int i_options = 0;
/* Read path and name */
psz_path = lua_tostring( p_state, t+3 );
msg_Dbg( p_demux, "Path: %s", psz_path );
lua_getfield( p_state, t+2, "name" ); lua_getfield( p_state, t+2, "name" );
if( lua_isstring( p_state, t+4 ) ) if( lua_isstring( p_state, t+4 ) )
{ {
psz_title = lua_tostring( p_state, t+4 ); psz_name = lua_tostring( p_state, t+4 );
msg_Dbg( p_demux, "Name: %s", psz_title ); msg_Dbg( p_demux, "Name: %s", psz_name );
} }
else else
{ {
psz_title = psz_url; psz_name = psz_path;
} }
p_input = input_ItemNewExt( p_playlist, psz_url,
psz_title, 0, NULL, -1 );
p_input->p_meta = vlc_meta_New();
/* Read options */
lua_getfield( p_state, t+2, "options" );
if( lua_istable( p_state, t+5 ) )
{
lua_pushnil( p_state );
while( lua_next( p_state, t+5 ) )
{
if( lua_isstring( p_state, t+7 ) )
{
char *psz_option = strdup(
lua_tostring( p_state, t+7 ) );
msg_Dbg( p_demux, "Option: %s",
psz_option );
INSERT_ELEM( ppsz_options, i_options,
i_options, psz_option );
}
else
{
msg_Warn( p_demux,
"Option should be a string" );
}
lua_pop( p_state, 1 ); /* pop option */
}
}
lua_pop( p_state, 1 ); /* pop "options" */
/* Create input item */
p_input = input_ItemNewExt( p_playlist, psz_path,
psz_name, i_options,
(const char **)ppsz_options,
-1 );
lua_pop( p_state, 1 ); /* pop "name" */
/* Read meta data */
p_input->p_meta = vlc_meta_New();
#define TRY_META( a, b ) \ #define TRY_META( a, b ) \
lua_getfield( p_state, t+2, a ); \ lua_getfield( p_state, t+2, a ); \
if( lua_isstring( p_state, t+5 ) ) \ if( lua_isstring( p_state, t+4 ) ) \
{ \ { \
psz_title = lua_tostring( p_state, t+5 ); \ psz_name = lua_tostring( p_state, t+4 ); \
msg_Dbg( p_demux, #b ": %s", psz_title ); \ msg_Dbg( p_demux, #b ": %s", psz_name ); \
vlc_meta_Set ## b ( p_input->p_meta, psz_title ); \ vlc_meta_Set ## b ( p_input->p_meta, psz_name ); \
} \ } \
lua_pop( p_state, 1 ); /* pop a */ lua_pop( p_state, 1 ); /* pop a */
TRY_META( "title", Title ); TRY_META( "title", Title );
...@@ -520,12 +556,16 @@ static int Demux( demux_t *p_demux ) ...@@ -520,12 +556,16 @@ static int Demux( demux_t *p_demux )
TRY_META( "arturl", ArtURL ); TRY_META( "arturl", ArtURL );
TRY_META( "trackid", TrackID ); TRY_META( "trackid", TrackID );
/* Append item to playlist */
playlist_BothAddInput( playlist_BothAddInput(
p_playlist, p_input, p_playlist, p_input,
p_item_in_category, p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
PLAYLIST_END, NULL, NULL, VLC_FALSE ); PLAYLIST_END, NULL, NULL, VLC_FALSE );
lua_pop( p_state, 1 ); /* pop "name" */
while( i_options > 0 )
free( ppsz_options[--i_options] );
free( ppsz_options );
} }
else else
{ {
...@@ -541,7 +581,6 @@ static int Demux( demux_t *p_demux ) ...@@ -541,7 +581,6 @@ static int Demux( demux_t *p_demux )
lua_pop( p_state, 1 ); /* pop the value, keep the key for lua_pop( p_state, 1 ); /* pop the value, keep the key for
* the next lua_next() call */ * the next lua_next() call */
} }
lua_pop( p_state, 1 ); /* pop the last key */
} }
else else
{ {
......
Instructions to code your own VLC Lua playlist script. Instructions to code your own VLC Lua playlist script.
$Id$ $Id$
Examples: See dailymotion.lua, googlevideo.lua, metacafe.lua and youbtube.lua. Examples: See dailymotion.lua, googlevideo.lua, metacafe.lua, youbtube.lua
and youtube_homepage.lua .
VLC Lua playlist modules should define two functions: VLC Lua playlist modules should define two functions:
* probe(): returns true if we want to handle the playlist in this script * probe(): returns true if we want to handle the playlist in this script
...@@ -27,6 +28,8 @@ VLC Lua playlist modules should define two functions: ...@@ -27,6 +28,8 @@ VLC Lua playlist modules should define two functions:
.encodedby: the item's EncodedBy (OPTIONAL, meta data) .encodedby: the item's EncodedBy (OPTIONAL, meta data)
.arturl: the item's ArtURL (OPTIONAL, meta data) .arturl: the item's ArtURL (OPTIONAL, meta data)
.trackid: the item's TrackID (OPTIONAL, meta data) .trackid: the item's TrackID (OPTIONAL, meta data)
.options: a list of VLC options (OPTIONAL)
example: .options = { "fullscreen" }
Invalid playlist items will be discarded by VLC. Invalid playlist items will be discarded by VLC.
VLC defines a global vlc object with the following members: VLC defines a global vlc object with the following members:
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
function probe() function probe()
return vlc.access == "http" return vlc.access == "http"
and string.match( vlc.path, "dailymotion.com" ) and string.match( vlc.path, "dailymotion.com" )
and vlc.peek( 9 ) == "<!DOCTYPE" and string.match( vlc.peek( 256 ), "<!DOCTYPE.*<title>Video " )
end end
-- Parse function. -- Parse function.
......
function probe() function probe()
return vlc.access == "http" and ( string.match( vlc.path, "youtube.com/$" ) or string.match( vlc.path, "youtube.com/browse" ) ) return vlc.access == "http" and ( string.match( vlc.path, "youtube.com/?$" ) or string.match( vlc.path, "youtube.com/browse" ) )
end end
function parse() function parse()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment