]> git.sesse.net Git - vlc/blob - modules/demux/playlist/luaplaylist.c
Remove redumdant parameter to vlc_global
[vlc] / modules / demux / playlist / luaplaylist.c
1 /*****************************************************************************
2  * luaplaylist.c :  Lua playlist demux module
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea at videolan tod org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28 #include <vlc_demux.h>
29 #include <vlc_url.h>
30 #include <vlc_strings.h>
31 #include <vlc_charset.h>
32
33 #include <errno.h>                                                 /* ENOMEM */
34 #include "playlist.h"
35
36 #ifdef HAVE_SYS_STAT_H
37 #   include <sys/stat.h>
38 #endif
39
40 #include <lua.h>        /* Low level lua C API */
41 #include <lauxlib.h>    /* Higher level C API */
42 #include <lualib.h>     /* Lua libs */
43
44 /*****************************************************************************
45  * Local prototypes
46  *****************************************************************************/
47 static int E_(Import_LuaPlaylist)( vlc_object_t *p_this );
48 static void E_(Close_LuaPlaylist)( vlc_object_t *p_this );
49
50 static int Demux( demux_t *p_demux );
51 static int Control( demux_t *p_demux, int i_query, va_list args );
52
53 /*****************************************************************************
54  * Module descriptor
55  *****************************************************************************/
56 vlc_module_begin();
57     add_shortcut( "lua" );
58     set_category( CAT_INPUT );
59     set_subcategory( SUBCAT_INPUT_DEMUX );
60
61     set_shortname( _("Lua Playlist") );
62     set_description( _("Lua Playlist Parser Interface") );
63     set_capability( "demux2", 9 );
64     set_callbacks( E_(Import_LuaPlaylist), E_(Close_LuaPlaylist) );
65 vlc_module_end();
66
67 /*****************************************************************************
68  *
69  *****************************************************************************/
70 struct demux_sys_t
71 {
72     lua_State *p_state;
73     char *psz_filename;
74 };
75
76 /*****************************************************************************
77  *
78  *****************************************************************************/
79 static demux_t *vlclua_get_demux( lua_State *p_state )
80 {
81     demux_t *p_demux;
82     lua_getglobal( p_state, "vlc" );
83     lua_getfield( p_state, lua_gettop( p_state ), "private" );
84     p_demux = (demux_t*)lua_topointer( p_state, lua_gettop( p_state ) );
85     lua_pop( p_state, 2 );
86     return p_demux;
87 }
88
89 static int vlclua_peek( lua_State *p_state )
90 {
91     demux_t *p_demux = vlclua_get_demux( p_state );
92     int i = lua_gettop( p_state );
93     int n;
94     byte_t *p_peek;
95     int i_peek;
96     if( !i ) return 0;
97     n = lua_tonumber( p_state, 1 );
98     lua_pop( p_state, i );
99     i_peek = stream_Peek( p_demux->s, &p_peek, n );
100     lua_pushlstring( p_state, (const char *)p_peek, i_peek );
101     return 1;
102 }
103
104 static int vlclua_read( lua_State *p_state )
105 {
106     demux_t *p_demux = vlclua_get_demux( p_state );
107     int i = lua_gettop( p_state );
108     int n;
109     byte_t *p_read;
110     int i_read;
111     if( !i ) return 0;
112     n = lua_tonumber( p_state, 1 );
113     lua_pop( p_state, i );
114     i_read = stream_Read( p_demux->s, &p_read, n );
115     lua_pushlstring( p_state, (const char *)p_read, i_read );
116     return 1;
117 }
118
119 static int vlclua_readline( lua_State *p_state )
120 {
121     demux_t *p_demux = vlclua_get_demux( p_state );
122     char *psz_line = stream_ReadLine( p_demux->s );
123     if( psz_line )
124     {
125         lua_pushstring( p_state, psz_line );
126         free( psz_line );
127     }
128     else
129     {
130         lua_pushnil( p_state );
131     }
132     return 1;
133 }
134
135 static int vlclua_decode_uri( lua_State *p_state )
136 {
137     int i = lua_gettop( p_state );
138     if( !i ) return 0;
139     const char *psz_cstring = lua_tostring( p_state, 1 );
140     if( !psz_cstring ) return 0;
141     char *psz_string = strdup( psz_cstring );
142     lua_pop( p_state, i );
143     decode_URI( psz_string );
144     lua_pushstring( p_state, psz_string );
145     free( psz_string );
146     return 1;
147 }
148
149 static int vlclua_resolve_xml_special_chars( lua_State *p_state )
150 {
151     int i = lua_gettop( p_state );
152     if( !i ) return 0;
153     const char *psz_cstring = lua_tostring( p_state, 1 );
154     if( !psz_cstring ) return 0;
155     char *psz_string = strdup( psz_cstring );
156     lua_pop( p_state, i );
157     resolve_xml_special_chars( psz_string );
158     lua_pushstring( p_state, psz_string );
159     free( psz_string );
160     return 1;
161 }
162
163 static int vlclua_msg_dbg( lua_State *p_state )
164 {
165     demux_t *p_demux = vlclua_get_demux( p_state );
166     int i = lua_gettop( p_state );
167     if( !i ) return 0;
168     const char *psz_cstring = lua_tostring( p_state, 1 );
169     if( !psz_cstring ) return 0;
170     msg_Dbg( p_demux, "%s: %s", p_demux->p_sys->psz_filename, psz_cstring );
171     return 0;
172 }
173 static int vlclua_msg_warn( lua_State *p_state )
174 {
175     demux_t *p_demux = vlclua_get_demux( p_state );
176     int i = lua_gettop( p_state );
177     if( !i ) return 0;
178     const char *psz_cstring = lua_tostring( p_state, 1 );
179     if( !psz_cstring ) return 0;
180     msg_Warn( p_demux, "%s: %s", p_demux->p_sys->psz_filename, psz_cstring );
181     return 0;
182 }
183 static int vlclua_msg_err( lua_State *p_state )
184 {
185     demux_t *p_demux = vlclua_get_demux( p_state );
186     int i = lua_gettop( p_state );
187     if( !i ) return 0;
188     const char *psz_cstring = lua_tostring( p_state, 1 );
189     if( !psz_cstring ) return 0;
190     msg_Err( p_demux, "%s: %s", p_demux->p_sys->psz_filename, psz_cstring );
191     return 0;
192 }
193 static int vlclua_msg_info( lua_State *p_state )
194 {
195     demux_t *p_demux = vlclua_get_demux( p_state );
196     int i = lua_gettop( p_state );
197     if( !i ) return 0;
198     const char *psz_cstring = lua_tostring( p_state, 1 );
199     if( !psz_cstring ) return 0;
200     msg_Info( p_demux, "%s: %s", p_demux->p_sys->psz_filename, psz_cstring );
201     return 0;
202 }
203
204 /* Functions to register */
205 static luaL_Reg p_reg[] =
206 {
207     { "peek", vlclua_peek },
208     { "decode_uri", vlclua_decode_uri },
209     { "resolve_xml_special_chars", vlclua_resolve_xml_special_chars },
210     { "msg_dbg", vlclua_msg_dbg },
211     { "msg_warn", vlclua_msg_warn },
212     { "msg_err", vlclua_msg_err },
213     { "msg_info", vlclua_msg_info },
214     { NULL, NULL }
215 };
216
217 /* Functions to register for parse() function call only */
218 static luaL_Reg p_reg_parse[] =
219 {
220     { "read", vlclua_read },
221     { "readline", vlclua_readline },
222     { NULL, NULL }
223 };
224
225 /*****************************************************************************
226  *
227  *****************************************************************************/
228 static int file_select( const char *file )
229 {
230     int i = strlen( file );
231     return i > 4 && !strcmp( file+i-4, ".lua" );
232 }
233
234 static int file_compare( const char **a, const char **b )
235 {
236     return strcmp( *a, *b );
237 }
238
239 /*****************************************************************************
240  * Import_LuaPlaylist: main import function
241  *****************************************************************************/
242 int E_(Import_LuaPlaylist)( vlc_object_t *p_this )
243 {
244     demux_t *p_demux = (demux_t *)p_this;
245     lua_State *p_state;
246     int i_ret = VLC_EGENERIC;
247
248     char  *psz_filename  = NULL;
249
250     DIR   *dir           = NULL;
251     char **ppsz_filelist = NULL;
252     char **ppsz_fileend  = NULL;
253     char **ppsz_file;
254
255     char  *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
256     char **ppsz_dir;
257
258     p_demux->p_sys = (demux_sys_t*)malloc( sizeof( demux_sys_t ) );
259     if( !p_demux->p_sys )
260     {
261         return VLC_ENOMEM;
262     }
263
264     p_demux->p_sys->psz_filename = NULL;
265
266     p_demux->pf_control = Control;
267     p_demux->pf_demux = Demux;
268
269     /* Initialise Lua state structure */
270     p_state = luaL_newstate();
271     if( !p_state )
272     {
273         msg_Err( p_demux, "Could not create new Lua State" );
274         free( p_demux->p_sys );
275         return VLC_EGENERIC;
276     }
277     p_demux->p_sys->p_state = p_state;
278
279     /* Load Lua libraries */
280     luaL_openlibs( p_state ); /* FIXME: Don't open all the libs? */
281
282     luaL_register( p_state, "vlc", p_reg );
283     lua_pushlightuserdata( p_state, p_demux );
284     lua_setfield( p_state, lua_gettop( p_state ) - 1, "private" );
285     lua_pushstring( p_state, p_demux->psz_path );
286     lua_setfield( p_state, lua_gettop( p_state ) - 1, "path" );
287     lua_pushstring( p_state, p_demux->psz_access );
288     lua_setfield( p_state, lua_gettop( p_state ) - 1, "access" );
289
290     lua_pop( p_state, 1 );
291
292     if( asprintf( &ppsz_dir_list[0], "%s" DIR_SEP CONFIG_DIR DIR_SEP "luaplaylist",
293              p_demux->p_libvlc->psz_homedir ) < -1 )
294         return VLC_ENOMEM;
295
296 #   if defined(__APPLE__) || defined(SYS_BEOS) || defined(WIN32)
297     {
298         const char *psz_vlcpath = config_GetDataDir();
299         if( asprintf( &ppsz_dir_list[1], "%s" DIR_SEP "luaplaylist", psz_vlcpath ) < 0 )
300             return VLC_ENOMEM;
301         if( asprintf( &ppsz_dir_list[2], "%s" DIR_SEP "share" DIR_SEP "luaplaylist", psz_vlcpath ) < 0 )
302             return VLC_ENOMEM;
303     }
304 #   else
305     {
306 #   ifdef HAVE_SYS_STAT_H
307         struct stat stat_info;
308         if( ( utf8_stat( "share/luaplaylist", &stat_info ) == -1 )
309             || !S_ISDIR( stat_info.st_mode ) )
310         {
311             ppsz_dir_list[1] = strdup( DATA_PATH "/luaplaylist" );
312         }
313         else
314 #   endif
315         {
316             ppsz_dir_list[1] = strdup( "share/luaplaylist" );
317         }
318     }
319 #   endif
320
321     for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
322     {
323         int i_files;
324
325         if( ppsz_filelist )
326         {
327             for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;
328                  ppsz_file++ )
329                 free( *ppsz_file );
330             free( ppsz_filelist );
331             ppsz_filelist = NULL;
332         }
333
334         if( dir )
335         {
336             closedir( dir );
337         }
338
339         msg_Dbg( p_demux, "Trying Lua scripts in %s", *ppsz_dir );
340         dir = utf8_opendir( *ppsz_dir );
341
342         if( !dir ) continue;
343         i_files = utf8_loaddir( dir, &ppsz_filelist, file_select, file_compare );
344         if( i_files < 1 ) continue;
345         ppsz_fileend = ppsz_filelist + i_files;
346
347         for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend; ppsz_file++ )
348         {
349             free( psz_filename ); psz_filename = NULL;
350             asprintf( &psz_filename, "%s" DIR_SEP "%s", *ppsz_dir, *ppsz_file );
351             msg_Dbg( p_demux, "Trying Lua playlist script %s", psz_filename );
352             p_demux->p_sys->psz_filename = psz_filename;
353
354             /* Ugly hack to delete previous versions of the probe() and parse()
355              * functions. */
356             lua_pushnil( p_state );
357             lua_pushnil( p_state );
358             lua_setglobal( p_state, "probe" );
359             lua_setglobal( p_state, "parse" );
360
361             /* Load and run the script(s) */
362             if( luaL_dofile( p_state, psz_filename ) )
363             {
364                 msg_Warn( p_demux, "Error loading script %s: %s", psz_filename,
365                           lua_tostring( p_state, lua_gettop( p_state ) ) );
366                 lua_pop( p_state, 1 );
367                 continue;
368             }
369
370             lua_getglobal( p_state, "probe" );
371
372             if( !lua_isfunction( p_state, lua_gettop( p_state ) ) )
373             {
374                 msg_Warn( p_demux, "Error while runing script %s, "
375                           "function probe() not found", psz_filename );
376                 lua_pop( p_state, 1 );
377                 continue;
378             }
379
380             if( lua_pcall( p_state, 0, 1, 0 ) )
381             {
382                 msg_Warn( p_demux, "Error while runing script %s, "
383                           "function probe(): %s", psz_filename,
384                           lua_tostring( p_state, lua_gettop( p_state ) ) );
385                 lua_pop( p_state, 1 );
386                 continue;
387             }
388
389             if( lua_gettop( p_state ) )
390             {
391                 if( lua_toboolean( p_state, 1 ) )
392                 {
393                     msg_Dbg( p_demux, "Lua playlist script %s's "
394                              "probe() function was successful", psz_filename );
395                     i_ret = VLC_SUCCESS;
396                 }
397                 lua_pop( p_state, 1 );
398
399                 if( i_ret == VLC_SUCCESS ) break;
400             }
401         }
402         if( i_ret == VLC_SUCCESS ) break;
403     }
404
405     if( ppsz_filelist )
406     {
407         for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;
408              ppsz_file++ )
409             free( *ppsz_file );
410         free( ppsz_filelist );
411     }
412     for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
413         free( *ppsz_dir );
414
415     if( dir ) closedir( dir );
416     if( i_ret != VLC_SUCCESS )
417         E_(Close_LuaPlaylist)( p_this );
418     return i_ret;
419 }
420
421 /*****************************************************************************
422  * Deactivate: frees unused data
423  *****************************************************************************/
424 void E_(Close_LuaPlaylist)( vlc_object_t *p_this )
425 {
426     demux_t *p_demux = (demux_t *)p_this;
427     lua_close( p_demux->p_sys->p_state );
428     free( p_demux->p_sys->psz_filename );
429     free( p_demux->p_sys );
430 }
431
432 static inline void read_options( demux_t *p_demux, lua_State *p_state,
433                                  int o, int t, int *pi_options,
434                                  char ***pppsz_options )
435 {
436     lua_getfield( p_state, o, "options" );
437     if( lua_istable( p_state, t ) )
438     {
439         lua_pushnil( p_state );
440         while( lua_next( p_state, t ) )
441         {
442             if( lua_isstring( p_state, t+2 ) )
443             {
444                 char *psz_option = strdup( lua_tostring( p_state, t+2 ) );
445                 msg_Dbg( p_demux, "Option: %s", psz_option );
446                 INSERT_ELEM( *pppsz_options, *pi_options, *pi_options,
447                              psz_option );
448             }
449             else
450             {
451                 msg_Warn( p_demux, "Option should be a string" );
452             }
453             lua_pop( p_state, 1 ); /* pop option */
454         }
455     }
456     lua_pop( p_state, 1 ); /* pop "options" */
457 }
458
459 static inline void read_meta_data( demux_t *p_demux,
460                                    lua_State *p_state, int o, int t,
461                                    input_item_t *p_input )
462 {
463     const char *psz_value;
464 #define TRY_META( a, b )                                    \
465     lua_getfield( p_state, o, a );                          \
466     if( lua_isstring( p_state, t ) )                        \
467     {                                                       \
468         psz_value = lua_tostring( p_state, t );             \
469         msg_Dbg( p_demux, #b ": %s", psz_value );           \
470         input_item_Set ## b ( p_input, psz_value );   \
471     }                                                       \
472     lua_pop( p_state, 1 ); /* pop a */
473     TRY_META( "title", Title );
474     TRY_META( "artist", Artist );
475     TRY_META( "genre", Genre );
476     TRY_META( "copyright", Copyright );
477     TRY_META( "album", Album );
478     TRY_META( "tracknum", TrackNum );
479     TRY_META( "description", Description );
480     TRY_META( "rating", Rating );
481     TRY_META( "date", Date );
482     TRY_META( "setting", Setting );
483     TRY_META( "url", URL );
484     TRY_META( "language", Language );
485     TRY_META( "nowplaying", NowPlaying );
486     TRY_META( "publisher", Publisher );
487     TRY_META( "encodedby", EncodedBy );
488     TRY_META( "arturl", ArtURL );
489     TRY_META( "trackid", TrackID );
490 }
491
492 static inline void read_custom_meta_data( demux_t *p_demux,
493                                           lua_State *p_state, int o, int t,
494                                           input_item_t *p_input )
495 {
496     lua_getfield( p_state, o, "meta" );
497     if( lua_istable( p_state, t ) )
498     {
499         lua_pushnil( p_state );
500         while( lua_next( p_state, t ) )
501         {
502             if( !lua_isstring( p_state, t+1 ) )
503             {
504                 msg_Warn( p_demux, "Custom meta data category name must be "
505                                    "a string" );
506             }
507             else if( !lua_istable( p_state, t+2 ) )
508             {
509                 msg_Warn( p_demux, "Custom meta data category contents "
510                                    "must be a table" );
511             }
512             else
513             {
514                 const char *psz_meta_category = lua_tostring( p_state, t+1 );
515                 msg_Dbg( p_demux, "Found custom meta data category: %s",
516                          psz_meta_category );
517                 lua_pushnil( p_state );
518                 while( lua_next( p_state, t+2 ) )
519                 {
520                     if( !lua_isstring( p_state, t+3 ) )
521                     {
522                         msg_Warn( p_demux, "Custom meta category item name "
523                                            "must be a string." );
524                     }
525                     else if( !lua_isstring( p_state, t+4 ) )
526                     {
527                         msg_Warn( p_demux, "Custom meta category item value "
528                                            "must be a string." );
529                     }
530                     else
531                     {
532                         const char *psz_meta_name =
533                             lua_tostring( p_state, t+3 );
534                         const char *psz_meta_value =
535                             lua_tostring( p_state, t+4 );
536                         msg_Dbg( p_demux, "Custom meta %s, %s: %s",
537                                  psz_meta_category, psz_meta_name,
538                                  psz_meta_value );
539                         input_ItemAddInfo( p_input, psz_meta_category,
540                                            psz_meta_name, psz_meta_value );
541                     }
542                     lua_pop( p_state, 1 ); /* pop item */
543                 }
544             }
545             lua_pop( p_state, 1 ); /* pop category */
546         }
547     }
548     lua_pop( p_state, 1 ); /* pop "meta" */
549 }
550
551 static int Demux( demux_t *p_demux )
552 {
553     input_item_t *p_input;
554     lua_State *p_state = p_demux->p_sys->p_state;
555     char *psz_filename = p_demux->p_sys->psz_filename;
556     int t;
557
558     INIT_PLAYLIST_STUFF;
559
560     luaL_register( p_state, "vlc", p_reg_parse );
561
562     lua_getglobal( p_state, "parse" );
563
564     if( !lua_isfunction( p_state, lua_gettop( p_state ) ) )
565     {
566         msg_Warn( p_demux, "Error while runing script %s, "
567                   "function parse() not found", psz_filename );
568         E_(Close_LuaPlaylist)( VLC_OBJECT( p_demux ) );
569         return VLC_EGENERIC;
570     }
571
572     if( lua_pcall( p_state, 0, 1, 0 ) )
573     {
574         msg_Warn( p_demux, "Error while runing script %s, "
575                   "function parse(): %s", psz_filename,
576                   lua_tostring( p_state, lua_gettop( p_state ) ) );
577         E_(Close_LuaPlaylist)( VLC_OBJECT( p_demux ) );
578         return VLC_EGENERIC;
579     }
580
581     /* Check that the Lua stack is big enough and grow it if needed.
582      * Should be ok since LUA_MINSTACK is 20 but we never know. */
583     lua_checkstack( p_state, 8 );
584
585     if( ( t = lua_gettop( p_state ) ) )
586     {
587
588         if( lua_istable( p_state, t ) )
589         {
590             lua_pushnil( p_state );
591             while( lua_next( p_state, t ) )
592             {
593                 if( lua_istable( p_state, t+2 ) )
594                 {
595                     lua_getfield( p_state, t+2, "path" );
596                     if( lua_isstring( p_state, t+3 ) )
597                     {
598                         const char  *psz_path     = NULL;
599                         const char  *psz_name     = NULL;
600                         char       **ppsz_options = NULL;
601                         int          i_options    = 0;
602                         mtime_t      i_duration   = -1;
603
604                         /* Read path and name */
605                         psz_path = lua_tostring( p_state, t+3 );
606                         msg_Dbg( p_demux, "Path: %s", psz_path );
607                         lua_getfield( p_state, t+2, "name" );
608                         if( lua_isstring( p_state, t+4 ) )
609                         {
610                             psz_name = lua_tostring( p_state, t+4 );
611                             msg_Dbg( p_demux, "Name: %s", psz_name );
612                         }
613                         else
614                         {
615                             psz_name = psz_path;
616                         }
617
618                         /* Read duration */
619                         lua_getfield( p_state, t+2, "duration" );
620                         if( lua_isnumber( p_state, t+5 ) )
621                         {
622                             i_duration = (mtime_t)lua_tointeger( p_state, t+5 );
623                             i_duration *= 1000000;
624                         }
625                         lua_pop( p_state, 1 ); /* pop "duration" */
626
627                         /* Read options */
628                         read_options( p_demux, p_state, t+2, t+5,
629                                       &i_options, &ppsz_options );
630
631                         /* Create input item */
632                         p_input = input_ItemNewExt( p_playlist, psz_path,
633                                                     psz_name, i_options,
634                                                     (const char **)ppsz_options,
635                                                     i_duration );
636                         lua_pop( p_state, 1 ); /* pop "name" */
637
638                         /* Read meta data */
639                         read_meta_data( p_demux, p_state, t+2, t+4, p_input );
640
641                         /* Read custom meta data */
642                         read_custom_meta_data( p_demux, p_state, t+2, t+4,
643                                                p_input );
644
645                         /* Append item to playlist */
646                         playlist_BothAddInput(
647                             p_playlist, p_input,
648                             p_item_in_category,
649                             PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
650                             PLAYLIST_END, NULL, NULL, VLC_FALSE );
651
652                         while( i_options > 0 )
653                             free( ppsz_options[--i_options] );
654                         free( ppsz_options );
655                     }
656                     else
657                     {
658                         msg_Warn( p_demux,
659                                  "Playlist item's path should be a string" );
660                     }
661                     lua_pop( p_state, 1 ); /* pop "path" */
662                 }
663                 else
664                 {
665                     msg_Warn( p_demux, "Playlist item should be a table" );
666                 }
667                 lua_pop( p_state, 1 ); /* pop the value, keep the key for
668                                         * the next lua_next() call */
669             }
670         }
671         else
672         {
673             msg_Warn( p_demux, "Script didn't return a table" );
674         }
675     }
676     else
677     {
678         msg_Err( p_demux, "Script went completely foobar" );
679     }
680
681     HANDLE_PLAY_AND_RELEASE;
682
683     return -1; /* Needed for correct operation of go back */
684 }
685
686 static int Control( demux_t *p_demux, int i_query, va_list args )
687 {
688     return VLC_EGENERIC;
689 }