]> git.sesse.net Git - vlc/blobdiff - modules/demux/playlist/playlist.c
Make Zorglub less unhappy
[vlc] / modules / demux / playlist / playlist.c
index ddfaa44d8c271ab918671a9dbc6570f0899247f7..d30ce8528de07a0c27dede23fad4a10ee7435958 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * playlist.c :  Playlist import module
  *****************************************************************************
- * Copyright (C) 2004 VideoLAN
- * $Id: playlist.c,v 1.2 2004/01/11 17:46:58 sigmunau Exp $
+ * Copyright (C) 2004 the VideoLAN team
+ * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
  *
  * Preamble
  *****************************************************************************/
 #include <vlc/vlc.h>
-#include "ninput.h"
+#include <vlc/input.h>
+#include <vlc_playlist.h>
 
 #include "playlist.h"
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-vlc_module_begin();
+#define AUTOSTART_TEXT N_( "Auto start" )
+#define AUTOSTART_LONGTEXT N_( "Automatically start the playlist when " \
+    "it's loaded.\n" )
 
+vlc_module_begin();
     add_shortcut( "playlist" );
+    set_category( CAT_INPUT );
+    set_subcategory( SUBCAT_INPUT_DEMUX );
+
+    add_bool( "playlist-autostart", 1, NULL, AUTOSTART_TEXT, AUTOSTART_LONGTEXT,
+              VLC_FALSE );
 
+    set_shortname( _("Playlist") );
     set_description( _("Old playlist open") );
     add_shortcut( "old-open" );
-    set_capability( "demux2" , 10 );
-    set_callbacks( Import_Old , NULL );
-
+    set_capability( "demux2", 10 );
+    set_callbacks( E_(Import_Old), NULL );
+#if 0
+    add_submodule();
+        set_description( _("Native playlist import") );
+        add_shortcut( "playlist" );
+        add_shortcut( "native-open" );
+        set_capability( "demux2", 10 );
+        set_callbacks( E_(Import_Native), E_(Close_Native) );
+#endif
     add_submodule();
         set_description( _("M3U playlist import") );
         add_shortcut( "m3u-open" );
-        set_capability( "demux2" , 10 );
-        set_callbacks( Import_M3U , Close_M3U );
+        set_capability( "demux2", 10 );
+        set_callbacks( E_(Import_M3U), E_(Close_M3U) );
     add_submodule();
         set_description( _("PLS playlist import") );
         add_shortcut( "pls-open" );
-        set_capability( "demux2" , 10 );
-        set_callbacks( Import_PLS , Close_PLS );
+        set_capability( "demux2", 10 );
+        set_callbacks( E_(Import_PLS), E_(Close_PLS) );
+    add_submodule();
+        set_description( _("B4S playlist import") );
+        add_shortcut( "b4s-open" );
+        add_shortcut( "shout-b4s" );
+        set_capability( "demux2", 10 );
+        set_callbacks( E_(Import_B4S), E_(Close_B4S) );
 vlc_module_end();
 
 
@@ -58,7 +81,7 @@ vlc_module_end();
  * Find directory part of the path to the playlist file, in case of
  * relative paths inside
  */
-char *FindPrefix( demux_t *p_demux )
+char *E_(FindPrefix)( demux_t *p_demux )
 {
     char *psz_name;
     char *psz_path = strdup( p_demux->psz_path );
@@ -67,10 +90,11 @@ char *FindPrefix( demux_t *p_demux )
     psz_name = strrchr( psz_path, '/' );
 #else
     psz_name = strrchr( psz_path, '\\' );
-    if ( ! psz_name ) psz_name = strrchr( psz_path, '/' );
+    if( !psz_name ) psz_name = strrchr( psz_path, '/' );
 #endif
-    if( psz_name ) *psz_name = '\0';
+    if( psz_name ) psz_name[1] = '\0';
     else *psz_path = '\0';
+
     return psz_path;
 }
 
@@ -78,65 +102,54 @@ char *FindPrefix( demux_t *p_demux )
  * Add the directory part of the playlist file to the start of the
  * mrl, if the mrl is a relative file path
  */
-char *ProcessMRL( char *psz_mrl, char *psz_prefix )
+char *E_(ProcessMRL)( char *psz_mrl, char *psz_prefix )
 {
-    char *psz_name;
-    /* check for a protocol name */
-    /* for URL, we should look for "://"
+    /* Check for a protocol name.
+     * for URL, we should look for "://"
      * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
-     * we should look for ":"
-     * so we end up looking simply for ":"*/
-    /* PB: on some file systems, ':' are valid characters though*/
-    psz_name = psz_mrl;
-    while( *psz_name && *psz_name!=':' )
-    {
-        psz_name++;
-    }
-#ifdef WIN32
-    if ( *psz_name && ( psz_name == psz_mrl + 1 ) )
-    {
-        /* if it is not an URL,
-         * as it is unlikely to be an MRL (PB: if it is ?)
-         * it should be an absolute file name with the drive letter */
-        if ( *(psz_name+1) == '/' )/* "*:/" */
-        {
-            if ( *(psz_name+2) != '/' )/* not "*://" */
-                while ( *psz_name ) *psz_name++;/* so now (*psz_name==0) */
-        }
-        else while ( *psz_name ) *psz_name++;/* "*:*"*/
-    }
-#endif
+     * we should look for ":", so we end up looking simply for ":"
+     * PB: on some file systems, ':' are valid characters though */
 
-    /* if the line doesn't specify a protocol name,
-     * check if the line has an absolute or relative path */
-#ifndef WIN32
-    if( !*psz_name && *psz_mrl != '/' )
-         /* If this line doesn't begin with a '/' */
-#else
-    if( !*psz_name
-            && *psz_mrl!='/'
-            && *psz_mrl!='\\'
-            && *(psz_mrl+1)!=':' )
-         /* if this line doesn't begin with
-          *  "/" or "\" or "*:" or "*:\" or "*:/" or "\\" */
-#endif
-    {
-#ifndef WIN32
-        psz_name = malloc( strlen(psz_prefix) + strlen(psz_mrl) + 2 );
-        sprintf( psz_name, "%s/%s", psz_prefix, psz_mrl );
-#else
-        if ( *p_m3u->psz_prefix != '\0' )
-        {
-            psz_name = malloc( strlen(psz_prefix) + strlen(psz_mrl) + 2 );
-            sprintf( psz_name, "%s\\%s", psz_prefix, psz_mrl );
-        }
-        else psz_name = strdup( psz_mrl );
-#endif
-    }
-    else
-    {
-        psz_name = strdup( psz_mrl );
-    }
-    return psz_name;
+    /* Simple cases first */
+    if( !psz_mrl || !*psz_mrl ) return NULL;
+    if( !psz_prefix || !*psz_prefix ) return strdup( psz_mrl );
+
+    /* Check if the line specifies an absolute path */
+    if( *psz_mrl == '/' || *psz_mrl == '\\' ) return strdup( psz_mrl );
+
+    /* Check if the line specifies an mrl/url
+     * (and on win32, contains a drive letter) */
+    if( strchr( psz_mrl, ':' ) ) return strdup( psz_mrl );
+
+    /* This a relative path, prepend the prefix */
+    asprintf( &psz_mrl, "%s%s", psz_prefix, psz_mrl );
+    return psz_mrl;
 }
 
+vlc_bool_t E_(FindItem)( demux_t *p_demux, playlist_t *p_playlist,
+                     playlist_item_t **pp_item )
+{
+     vlc_bool_t b_play = var_CreateGetBool( p_demux, "playlist-autostart" );
+
+     if( b_play && p_playlist->status.p_item &&
+             &p_playlist->status.p_item->input ==
+                ((input_thread_t *)p_demux->p_parent)->input.p_item )
+     {
+         msg_Dbg( p_playlist, "starting playlist playback" );
+         *pp_item = p_playlist->status.p_item;
+         b_play = VLC_TRUE;
+     }
+     else
+     {
+         input_item_t *p_current = ( (input_thread_t*)p_demux->p_parent)->
+                                                        input.p_item;
+         *pp_item = playlist_LockItemGetByInput( p_playlist, p_current );
+         if( !*pp_item )
+         {
+             msg_Dbg( p_playlist, "unable to find item in playlist");
+         }
+         msg_Dbg( p_playlist, "not starting playlist playback");
+         b_play = VLC_FALSE;
+     }
+     return b_play;
+}