]> git.sesse.net Git - vlc/blobdiff - modules/demux/playlist/pls.c
fix #1409
[vlc] / modules / demux / playlist / pls.c
index 708bc06ae85b6b8c6ab0e80a9ec3ab0d75acc93b..135c2645150cd7a899dc160f0903ee6e316294fb 100644 (file)
@@ -26,8 +26,7 @@
  * Preamble
  *****************************************************************************/
 #include <vlc/vlc.h>
-#include <vlc/input.h>
-#include <vlc/intf.h>
+#include <vlc_demux.h>
 
 #include "playlist.h"
 
@@ -48,11 +47,11 @@ static int Control( demux_t *p_demux, int i_query, va_list args );
 int E_(Import_PLS)( vlc_object_t *p_this )
 {
     demux_t *p_demux = (demux_t *)p_this;
-    uint8_t *p_peek;
+    const uint8_t *p_peek;
     CHECK_PEEK( p_peek, 10 );
 
     if( POKE( p_peek, "[playlist]", 10 ) || POKE( p_peek, "[Reference]", 10 ) ||
-        isExtension( p_demux, ".pls" )   || isDemux( p_demux, "pls" ) )
+        demux2_IsPathExtension( p_demux, ".pls" )   || demux2_IsForced( p_demux, "pls" ) )
     {
         ;
     }
@@ -83,17 +82,19 @@ static int Demux( demux_t *p_demux )
     char          *psz_name = NULL;
     char          *psz_line;
     char          *psz_mrl = NULL;
+    char          *psz_mrl_orig = NULL;
     char          *psz_key;
     char          *psz_value;
     int            i_item = -1;
     int            i_new_item = 0;
     int            i_key_length;
+    input_item_t *p_input;
 
     INIT_PLAYLIST_STUFF;
 
     while( ( psz_line = stream_ReadLine( p_demux->s ) ) )
     {
-        if( !strncasecmp( psz_line, "[playlist]", sizeof("[playlist]")-1 ) || 
+        if( !strncasecmp( psz_line, "[playlist]", sizeof("[playlist]")-1 ) ||
             !strncasecmp( psz_line, "[Reference]", sizeof("[Reference]")-1 ) )
         {
             free( psz_line );
@@ -118,6 +119,12 @@ static int Demux( demux_t *p_demux )
             free( psz_line );
             continue;
         }
+        if( !strcasecmp( psz_key, "numberofentries" ) )
+        {
+            msg_Dbg( p_demux, "pls should have %d entries", atoi(psz_value) );
+            free( psz_line);
+            continue;
+        }
         /* find the number part of of file1, title1 or length1 etc */
         i_key_length = strlen( psz_key );
         if( i_key_length >= 4 ) /* Ref1 type case */
@@ -153,10 +160,8 @@ static int Demux( demux_t *p_demux )
             {
                 p_input = input_ItemNewExt( p_playlist, psz_mrl, psz_name,
                                             0, NULL, -1 );
-                vlc_input_item_CopyOptions( p_current->p_input, p_input );
-                playlist_AddWhereverNeeded( p_playlist, p_input, p_current,
-                                p_item_in_category, (i_parent_id > 0 ) ?
-                                VLC_TRUE: VLC_FALSE, PLAYLIST_APPEND );
+                input_ItemCopyOptions( p_current_input, p_input );
+                input_ItemAddSubItem( p_current_input, p_input );
             }
             else
             {
@@ -174,10 +179,26 @@ static int Demux( demux_t *p_demux )
         if( !strncasecmp( psz_key, "file", sizeof("file") -1 ) ||
             !strncasecmp( psz_key, "Ref", sizeof("Ref") -1 ) )
         {
+            if( psz_mrl_orig )
+                free( psz_mrl_orig );
+            psz_mrl_orig =
             psz_mrl = E_(ProcessMRL)( psz_value, p_demux->p_sys->psz_prefix );
+
+            if( !strncasecmp( psz_key, "Ref", sizeof("Ref") -1 ) )
+            {
+                if( !strncasecmp( psz_mrl, "http://", sizeof("http://") -1 ) )
+                {
+                    psz_mrl++;
+                    psz_mrl[0] = 'm';
+                    psz_mrl[1] = 'm';
+                    psz_mrl[2] = 's';
+                }
+            }
         }
         else if( !strncasecmp( psz_key, "title", sizeof("title") -1 ) )
         {
+            if( psz_name )
+                free( psz_name );
             psz_name = strdup( psz_value );
         }
         else if( !strncasecmp( psz_key, "length", sizeof("length") -1 ) )
@@ -198,11 +219,9 @@ static int Demux( demux_t *p_demux )
     if( psz_mrl )
     {
         p_input = input_ItemNewExt( p_playlist, psz_mrl, psz_name,0, NULL, -1 );
-        vlc_input_item_CopyOptions( p_current->p_input, p_input );
-        playlist_AddWhereverNeeded( p_playlist, p_input, p_current,
-                                p_item_in_category, (i_parent_id > 0 ) ?
-                                VLC_TRUE: VLC_FALSE, PLAYLIST_APPEND );
-        free( psz_mrl );
+        input_ItemCopyOptions( p_current_input, p_input );
+        input_ItemAddSubItem( p_current_input, p_input );
+        free( psz_mrl_orig );
         psz_mrl = NULL;
     }
     else
@@ -216,7 +235,7 @@ static int Demux( demux_t *p_demux )
     }
 
     HANDLE_PLAY_AND_RELEASE;
-    return VLC_SUCCESS;
+    return 0; /* Needed for correct operation of go back */
 }
 
 static int Control( demux_t *p_demux, int i_query, va_list args )