]> git.sesse.net Git - vlc/blob - src/libvlc.c
playlist: add playlist-independent functions for meta data handling
[vlc] / src / libvlc.c
1 /*****************************************************************************
2  * libvlc.c: libvlc instances creation and deletion, interfaces handling
3  *****************************************************************************
4  * Copyright (C) 1998-2008 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Vincent Seguin <seguin@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Gildas Bazin <gbazin@videolan.org>
10  *          Derk-Jan Hartman <hartman at videolan dot org>
11  *          RĂ©mi Denis-Courmont <rem # videolan : org>
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation; either version 2.1 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26  *****************************************************************************/
27
28 /** \file
29  * This file contains functions to create and destroy libvlc instances
30  */
31
32 /*****************************************************************************
33  * Preamble
34  *****************************************************************************/
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38
39 #include <vlc_common.h>
40 #include "../lib/libvlc_internal.h"
41 #include <vlc_input.h>
42
43 #include "modules/modules.h"
44 #include "config/configuration.h"
45 #include "playlist/preparser.h"
46
47 #include <stdio.h>                                              /* sprintf() */
48 #include <string.h>
49 #include <stdlib.h>                                                /* free() */
50 #include <errno.h>
51
52 #include "config/vlc_getopt.h"
53
54 #ifdef HAVE_DBUS
55 /* used for one-instance mode */
56 #   include <dbus/dbus.h>
57 #endif
58
59
60 #include <vlc_playlist.h>
61 #include <vlc_interface.h>
62
63 #include <vlc_charset.h>
64 #include <vlc_fs.h>
65 #include <vlc_cpu.h>
66 #include <vlc_url.h>
67 #include <vlc_modules.h>
68
69 #include "libvlc.h"
70 #include "playlist/playlist_internal.h"
71 #include "misc/variables.h"
72
73 #include <vlc_vlm.h>
74
75 #ifdef __APPLE__
76 # include <libkern/OSAtomic.h>
77 #endif
78
79 #include <assert.h>
80
81 /*****************************************************************************
82  * The evil global variables. We handle them with care, don't worry.
83  *****************************************************************************/
84
85 #if !defined(_WIN32) && !defined(__OS2__)
86 static bool b_daemon = false;
87 #endif
88
89 /*****************************************************************************
90  * Local prototypes
91  *****************************************************************************/
92 static void GetFilenames  ( libvlc_int_t *, unsigned, const char *const [] );
93
94 /**
95  * Allocate a libvlc instance, initialize global data if needed
96  * It also initializes the threading system
97  */
98 libvlc_int_t * libvlc_InternalCreate( void )
99 {
100     libvlc_int_t *p_libvlc;
101     libvlc_priv_t *priv;
102
103     /* Now that the thread system is initialized, we don't have much, but
104      * at least we have variables */
105     /* Allocate a libvlc instance object */
106     p_libvlc = vlc_custom_create( (vlc_object_t *)NULL, sizeof (*priv),
107                                   "libvlc" );
108     if( p_libvlc == NULL )
109         return NULL;
110
111     priv = libvlc_priv (p_libvlc);
112     priv->p_playlist = NULL;
113     priv->p_dialog_provider = NULL;
114     priv->p_vlm = NULL;
115
116     vlc_ExitInit( &priv->exit );
117
118     return p_libvlc;
119 }
120
121 /**
122  * Initialize a libvlc instance
123  * This function initializes a previously allocated libvlc instance:
124  *  - CPU detection
125  *  - gettext initialization
126  *  - message queue, module bank and playlist initialization
127  *  - configuration and commandline parsing
128  */
129 int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
130                          const char *ppsz_argv[] )
131 {
132     libvlc_priv_t *priv = libvlc_priv (p_libvlc);
133     char *       psz_modules = NULL;
134     char *       psz_parser = NULL;
135     char *       psz_control = NULL;
136     char        *psz_val;
137
138     /* System specific initialization code */
139     system_Init();
140
141     /* Initialize the module bank and load the configuration of the
142      * core module. We need to do this at this stage to be able to display
143      * a short help if required by the user. (short help == core module
144      * options) */
145     module_InitBank ();
146
147     /* Get command line options that affect module loading. */
148     if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, NULL ) )
149     {
150         module_EndBank (false);
151         return VLC_EGENERIC;
152     }
153
154     vlc_LogInit (p_libvlc);
155     vlc_threads_setup (p_libvlc);
156
157     /* Load the builtins and plugins into the module_bank.
158      * We have to do it before config_Load*() because this also gets the
159      * list of configuration options exported by each module and loads their
160      * default values. */
161     size_t module_count = module_LoadPlugins (p_libvlc);
162
163     /*
164      * Override default configuration with config file settings
165      */
166     if( !var_InheritBool( p_libvlc, "ignore-config" ) )
167     {
168         if( var_InheritBool( p_libvlc, "reset-config" ) )
169             config_SaveConfigFile( p_libvlc ); /* Save default config */
170         else
171             config_LoadConfigFile( p_libvlc );
172     }
173
174     /*
175      * Override configuration with command line settings
176      */
177     int vlc_optind;
178     if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) )
179     {
180         module_EndBank (true);
181         vlc_LogDeinit (p_libvlc);
182         return VLC_EGENERIC;
183     }
184
185     /*
186      * Support for gettext
187      */
188 #if defined( ENABLE_NLS ) \
189      && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
190     vlc_bindtextdomain (PACKAGE_NAME);
191 #endif
192     /*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
193     msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );
194
195     if (config_PrintHelp (VLC_OBJECT(p_libvlc)))
196     {
197         module_EndBank (true);
198         exit(0);
199     }
200
201     if( module_count <= 1 )
202     {
203         msg_Err( p_libvlc, "No plugins found! Check your VLC installation.");
204         module_EndBank (true);
205         vlc_LogDeinit (p_libvlc);
206         return VLC_ENOMOD;
207     }
208
209 #ifdef HAVE_DAEMON
210     /* Check for daemon mode */
211     if( var_InheritBool( p_libvlc, "daemon" ) )
212     {
213         char *psz_pidfile = NULL;
214
215         if( daemon( 1, 0) != 0 )
216         {
217             msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
218             module_EndBank (true);
219             vlc_LogDeinit (p_libvlc);
220             return VLC_ENOMEM;
221         }
222         b_daemon = true;
223
224         /* lets check if we need to write the pidfile */
225         psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
226         if( psz_pidfile != NULL )
227         {
228             FILE *pidfile;
229             pid_t i_pid = getpid ();
230             msg_Dbg( p_libvlc, "PID is %d, writing it to %s",
231                                i_pid, psz_pidfile );
232             pidfile = vlc_fopen( psz_pidfile,"w" );
233             if( pidfile != NULL )
234             {
235                 utf8_fprintf( pidfile, "%d", (int)i_pid );
236                 fclose( pidfile );
237             }
238             else
239             {
240                 msg_Err( p_libvlc, "cannot open pid file %s for writing: %s",
241                          psz_pidfile, vlc_strerror_c(errno) );
242             }
243         }
244         free( psz_pidfile );
245     }
246 #endif
247
248 /* FIXME: could be replaced by using Unix sockets */
249 #ifdef HAVE_DBUS
250
251 #define MPRIS_APPEND "/org/mpris/MediaPlayer2/TrackList/Append"
252 #define MPRIS_BUS_NAME "org.mpris.MediaPlayer2.vlc"
253 #define MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2"
254 #define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList"
255
256     if( var_InheritBool( p_libvlc, "one-instance" )
257     || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" )
258       && var_InheritBool( p_libvlc, "started-from-file" ) ) )
259     {
260         for( int i = vlc_optind; i < i_argc; i++ )
261             if( ppsz_argv[i][0] == ':' )
262             {
263                 msg_Err( p_libvlc, "item option %s incompatible with single instance",
264                          ppsz_argv[i] );
265                 goto dbus_out;
266             }
267
268         /* Initialise D-Bus interface, check for other instances */
269         dbus_threads_init_default();
270
271         DBusError err;
272         dbus_error_init( &err );
273
274         /* connect to the session bus */
275         DBusConnection  *conn = dbus_bus_get( DBUS_BUS_SESSION, &err );
276         if( conn == NULL )
277         {
278             msg_Err( p_libvlc, "Failed to connect to D-Bus session daemon: %s",
279                     err.message );
280             dbus_error_free( &err );
281             goto dbus_out;
282         }
283
284         /* check if VLC is available on the bus
285          * if not: D-Bus control is not enabled on the other
286          * instance and we can't pass MRLs to it */
287         /* FIXME: This check is totally brain-dead and buggy. */
288         if( !dbus_bus_name_has_owner( conn, MPRIS_BUS_NAME, &err ) )
289         {
290             dbus_connection_unref( conn );
291             if( dbus_error_is_set( &err ) )
292             {
293                 msg_Err( p_libvlc, "D-Bus error: %s", err.message );
294             }
295             else
296                 msg_Dbg( p_libvlc, "No media player running. Continuing normally." );
297             dbus_error_free( &err );
298             goto dbus_out;
299         }
300
301         const dbus_bool_t play = !var_InheritBool( p_libvlc, "playlist-enqueue" );
302
303         msg_Warn( p_libvlc, "media player running. Exiting...");
304         for( int i = vlc_optind; i < i_argc; i++ )
305         {
306             DBusMessage *msg = dbus_message_new_method_call(
307                MPRIS_BUS_NAME, MPRIS_OBJECT_PATH, MPRIS_TRACKLIST_INTERFACE, "AddTrack" );
308             if( unlikely(msg == NULL) )
309                 continue;
310
311             /* We need to resolve relative paths in this instance */
312             char *mrl;
313             if( strstr( ppsz_argv[i], "://" ) )
314                 mrl = strdup( ppsz_argv[i] );
315             else
316                 mrl = vlc_path2uri( ppsz_argv[i], NULL );
317             if( mrl == NULL )
318             {
319                 dbus_message_unref( msg );
320                 continue;
321             }
322
323             const char *after_track = MPRIS_APPEND;
324
325             /* append MRLs */
326             if( !dbus_message_append_args( msg, DBUS_TYPE_STRING, &mrl,
327                                                 DBUS_TYPE_OBJECT_PATH, &after_track,
328                                                 DBUS_TYPE_BOOLEAN, &play,
329                                                 DBUS_TYPE_INVALID ) )
330             {
331                  dbus_message_unref( msg );
332                  msg = NULL;
333                  free( mrl );
334                  continue;
335             }
336
337             msg_Dbg( p_libvlc, "Adds %s to the running media player", mrl );
338             free( mrl );
339
340             /* send message and get a handle for a reply */
341             DBusMessage *reply = dbus_connection_send_with_reply_and_block( conn, msg, -1,
342                                                                             &err );
343             dbus_message_unref( msg );
344             if( reply == NULL )
345             {
346                 msg_Err( p_libvlc, "D-Bus error: %s", err.message );
347                 continue;
348             }
349             dbus_message_unref( reply );
350         }
351         /* we unreference the connection when we've finished with it */
352         dbus_connection_unref( conn );
353         exit( 1 );
354     }
355 #undef MPRIS_APPEND
356 #undef MPRIS_BUS_NAME
357 #undef MPRIS_OBJECT_PATH
358 #undef MPRIS_TRACKLIST_INTERFACE
359 dbus_out:
360 #endif // HAVE_DBUS
361
362     vlc_CPU_dump( VLC_OBJECT(p_libvlc) );
363
364     priv->b_stats = var_InheritBool( p_libvlc, "stats" );
365
366     /*
367      * Initialize hotkey handling
368      */
369     priv->actions = vlc_InitActions( p_libvlc );
370
371     /*
372      * Meta data handling
373      */
374     priv->parser = playlist_preparser_New(VLC_OBJECT(p_libvlc));
375
376     /* Create a variable for showing the fullscreen interface */
377     var_Create( p_libvlc, "intf-toggle-fscontrol", VLC_VAR_BOOL );
378     var_SetBool( p_libvlc, "intf-toggle-fscontrol", true );
379
380     /* Create a variable for the Boss Key */
381     var_Create( p_libvlc, "intf-boss", VLC_VAR_VOID );
382
383     /* Create a variable for showing the main interface */
384     var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL );
385
386     /* Create a variable for showing the right click menu */
387     var_Create( p_libvlc, "intf-popupmenu", VLC_VAR_BOOL );
388
389     /* variables for signalling creation of new files */
390     var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING );
391     var_Create( p_libvlc, "record-file", VLC_VAR_STRING );
392
393     /* some default internal settings */
394     var_Create( p_libvlc, "window", VLC_VAR_STRING );
395     /* NOTE: Because the playlist and interfaces start before this function
396      * returns control to the application (DESIGN BUG!), all these variables
397      * must be created (in place of libvlc_new()) and set to VLC defaults
398      * (in place of VLC main()) *here*. */
399     var_Create( p_libvlc, "user-agent", VLC_VAR_STRING );
400     var_SetString( p_libvlc, "user-agent",
401                    "VLC media player (LibVLC "VERSION")" );
402     var_Create( p_libvlc, "http-user-agent", VLC_VAR_STRING );
403     var_SetString( p_libvlc, "http-user-agent",
404                    "VLC/"PACKAGE_VERSION" LibVLC/"PACKAGE_VERSION );
405     var_Create( p_libvlc, "app-icon-name", VLC_VAR_STRING );
406     var_SetString( p_libvlc, "app-icon-name", PACKAGE_NAME );
407     var_Create( p_libvlc, "app-id", VLC_VAR_STRING );
408     var_SetString( p_libvlc, "app-id", "org.VideoLAN.VLC" );
409     var_Create( p_libvlc, "app-version", VLC_VAR_STRING );
410     var_SetString( p_libvlc, "app-version", PACKAGE_VERSION );
411
412     /* System specific configuration */
413     system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
414
415 #ifdef ENABLE_VLM
416     /* Initialize VLM if vlm-conf is specified */
417     psz_parser = var_CreateGetNonEmptyString( p_libvlc, "vlm-conf" );
418     if( psz_parser )
419     {
420         priv->p_vlm = vlm_New( p_libvlc );
421         if( !priv->p_vlm )
422             msg_Err( p_libvlc, "VLM initialization failed" );
423     }
424     free( psz_parser );
425 #endif
426
427     /*
428      * Load background interfaces
429      */
430     psz_modules = var_CreateGetNonEmptyString( p_libvlc, "extraintf" );
431     psz_control = var_CreateGetNonEmptyString( p_libvlc, "control" );
432
433     if( psz_modules && psz_control )
434     {
435         char* psz_tmp;
436         if( asprintf( &psz_tmp, "%s:%s", psz_modules, psz_control ) != -1 )
437         {
438             free( psz_modules );
439             psz_modules = psz_tmp;
440         }
441     }
442     else if( psz_control )
443     {
444         free( psz_modules );
445         psz_modules = strdup( psz_control );
446     }
447
448     psz_parser = psz_modules;
449     while ( psz_parser && *psz_parser )
450     {
451         char *psz_module, *psz_temp;
452         psz_module = psz_parser;
453         psz_parser = strchr( psz_module, ':' );
454         if ( psz_parser )
455         {
456             *psz_parser = '\0';
457             psz_parser++;
458         }
459         if( asprintf( &psz_temp, "%s,none", psz_module ) != -1)
460         {
461             intf_Create( p_libvlc, psz_temp );
462             free( psz_temp );
463         }
464     }
465     free( psz_modules );
466     free( psz_control );
467
468     if( var_InheritBool( p_libvlc, "file-logging" )
469 #ifdef HAVE_SYSLOG_H
470         && !var_InheritBool( p_libvlc, "syslog" )
471 #endif
472         )
473     {
474         intf_Create( p_libvlc, "logger,none" );
475     }
476 #ifdef HAVE_SYSLOG_H
477     if( var_InheritBool( p_libvlc, "syslog" ) )
478     {
479         char *logmode = var_CreateGetNonEmptyString( p_libvlc, "logmode" );
480         var_SetString( p_libvlc, "logmode", "syslog" );
481         intf_Create( p_libvlc, "logger,none" );
482
483         if( logmode )
484         {
485             var_SetString( p_libvlc, "logmode", logmode );
486             free( logmode );
487         }
488         var_Destroy( p_libvlc, "logmode" );
489     }
490 #endif
491
492     if( var_InheritBool( p_libvlc, "network-synchronisation") )
493     {
494         intf_Create( p_libvlc, "netsync,none" );
495     }
496
497 #ifdef __APPLE__
498     var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
499     var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER );
500     var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER );
501     var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER );
502     var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER );
503     var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER );
504     var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
505     var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
506     var_Create( p_libvlc, "drawable-nsobject", VLC_VAR_ADDRESS );
507 #endif
508 #if defined (_WIN32) || defined (__OS2__)
509     var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_INTEGER );
510 #endif
511
512     /*
513      * Get input filenames given as commandline arguments.
514      * We assume that the remaining parameters are filenames
515      * and their input options.
516      */
517     GetFilenames( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
518
519     /*
520      * Get --open argument
521      */
522     psz_val = var_InheritString( p_libvlc, "open" );
523     if ( psz_val != NULL )
524     {
525         playlist_AddExt( pl_Get(p_libvlc), psz_val, NULL, PLAYLIST_INSERT, 0,
526                          -1, 0, NULL, 0, true, pl_Unlocked );
527         free( psz_val );
528     }
529
530     return VLC_SUCCESS;
531 }
532
533 /**
534  * Cleanup a libvlc instance. The instance is not completely deallocated
535  * \param p_libvlc the instance to clean
536  */
537 void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
538 {
539     libvlc_priv_t *priv = libvlc_priv (p_libvlc);
540
541     /* Ask the interfaces to stop and destroy them */
542     msg_Dbg( p_libvlc, "removing all interfaces" );
543     libvlc_Quit( p_libvlc );
544     intf_DestroyAll( p_libvlc );
545
546 #ifdef ENABLE_VLM
547     /* Destroy VLM if created in libvlc_InternalInit */
548     if( priv->p_vlm )
549     {
550         vlm_Delete( priv->p_vlm );
551     }
552 #endif
553
554     /* Free playlist now, all threads are gone */
555     playlist_t *p_playlist = libvlc_priv (p_libvlc)->p_playlist;
556     if( p_playlist != NULL )
557         playlist_Destroy( p_playlist );
558
559 #if !defined( _WIN32 ) && !defined( __OS2__ )
560     char* psz_pidfile = NULL;
561
562     if( b_daemon )
563     {
564         psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
565         if( psz_pidfile != NULL )
566         {
567             msg_Dbg( p_libvlc, "removing pid file %s", psz_pidfile );
568             if( unlink( psz_pidfile ) == -1 )
569             {
570                 msg_Dbg( p_libvlc, "removing pid file %s: %s",
571                         psz_pidfile, vlc_strerror_c(errno) );
572             }
573         }
574         free( psz_pidfile );
575     }
576 #endif
577
578     if (priv->parser != NULL)
579         playlist_preparser_Delete(priv->parser);
580
581     vlc_DeinitActions( p_libvlc, priv->actions );
582
583     /* Save the configuration */
584     if( !var_InheritBool( p_libvlc, "ignore-config" ) )
585         config_AutoSaveConfigFile( VLC_OBJECT(p_libvlc) );
586
587     /* Free module bank. It is refcounted, so we call this each time  */
588     module_EndBank (true);
589     vlc_LogDeinit (p_libvlc);
590 #if defined(_WIN32) || defined(__OS2__)
591     system_End( );
592 #endif
593 }
594
595 /**
596  * Destroy everything.
597  * This function requests the running threads to finish, waits for their
598  * termination, and destroys their structure.
599  * It stops the thread systems: no instance can run after this has run
600  * \param p_libvlc the instance to destroy
601  */
602 void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
603 {
604     libvlc_priv_t *priv = libvlc_priv( p_libvlc );
605
606     vlc_ExitDestroy( &priv->exit );
607
608     assert( atomic_load(&(vlc_internals(p_libvlc)->refs)) == 1 );
609     vlc_object_release( p_libvlc );
610 }
611
612 /**
613  * Add an interface plugin and run it
614  */
615 int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module )
616 {
617     if( !p_libvlc )
618         return VLC_EGENERIC;
619
620     if( !psz_module ) /* requesting the default interface */
621     {
622         char *psz_interface = var_CreateGetNonEmptyString( p_libvlc, "intf" );
623         if( !psz_interface ) /* "intf" has not been set */
624         {
625 #if !defined( _WIN32 ) && !defined( __OS2__ )
626             if( b_daemon )
627                  /* Daemon mode hack.
628                   * We prefer the dummy interface if none is specified. */
629                 psz_module = "dummy";
630             else
631 #endif
632                 msg_Info( p_libvlc, "%s",
633                           _("Running vlc with the default interface. "
634                             "Use 'cvlc' to use vlc without interface.") );
635         }
636         free( psz_interface );
637         var_Destroy( p_libvlc, "intf" );
638     }
639
640     /* Try to create the interface */
641     int ret = intf_Create( p_libvlc, psz_module ? psz_module : "$intf" );
642     if( ret )
643         msg_Err( p_libvlc, "interface \"%s\" initialization failed",
644                  psz_module ? psz_module : "default" );
645     return ret;
646 }
647
648 /*****************************************************************************
649  * GetFilenames: parse command line options which are not flags
650  *****************************************************************************
651  * Parse command line for input files as well as their associated options.
652  * An option always follows its associated input and begins with a ":".
653  *****************************************************************************/
654 static void GetFilenames( libvlc_int_t *p_vlc, unsigned n,
655                           const char *const args[] )
656 {
657     while( n > 0 )
658     {
659         /* Count the input options */
660         unsigned i_options = 0;
661
662         while( args[--n][0] == ':' )
663         {
664             i_options++;
665             if( n == 0 )
666             {
667                 msg_Warn( p_vlc, "options %s without item", args[n] );
668                 return; /* syntax!? */
669             }
670         }
671
672         char *mrl = NULL;
673         if( strstr( args[n], "://" ) == NULL )
674         {
675             mrl = vlc_path2uri( args[n], NULL );
676             if( !mrl )
677                 continue;
678         }
679
680         playlist_AddExt( pl_Get( p_vlc ), (mrl != NULL) ? mrl : args[n], NULL,
681                          PLAYLIST_INSERT, 0, -1, i_options,
682                          ( i_options ? &args[n + 1] : NULL ),
683                          VLC_INPUT_OPTION_TRUSTED, true, pl_Unlocked );
684         free( mrl );
685     }
686 }
687
688 /**
689  * Requests extraction of the meta data for an input item (a.k.a. preparsing).
690  * The actual extraction is asynchronous.
691  */
692 int libvlc_MetaRequest(libvlc_int_t *libvlc, input_item_t *item)
693 {
694     libvlc_priv_t *priv = libvlc_priv(libvlc);
695
696     if (unlikely(priv->parser == NULL))
697         return VLC_ENOMEM;
698
699     playlist_preparser_Push(priv->parser, item);
700     return VLC_SUCCESS;
701 }
702
703 /**
704  * Requests retrieving/downloading art for an input item.
705  * The retrieval is performed asynchronously.
706  */
707 int libvlc_ArtRequest(libvlc_int_t *libvlc, input_item_t *item)
708 {
709     libvlc_priv_t *priv = libvlc_priv(libvlc);
710
711     if (unlikely(priv->parser == NULL))
712         return VLC_ENOMEM;
713
714     playlist_preparser_fetcher_Push(priv->parser, item);
715     return VLC_SUCCESS;
716 }