]> git.sesse.net Git - vlc/blobdiff - modules/demux/playlist/pls.c
A bit of headers cleanup
[vlc] / modules / demux / playlist / pls.c
index fecc7048129c951505b5cf0c98d7dc7e169005ea..bf1b2a4ba0b16e6876b0b1b6dcb76ed2b896b983 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-
 #include <vlc/vlc.h>
-#include <vlc/input.h>
-#include <vlc/intf.h>
+#include <vlc_demux.h>
 
-#include <errno.h>                                                 /* ENOMEM */
 #include "playlist.h"
 
 struct demux_sys_t
@@ -51,34 +47,17 @@ 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;
-    char    *psz_ext;
+    CHECK_PEEK( p_peek, 10 );
 
-    if( stream_Peek( p_demux->s , &p_peek, 7 ) < 7 ) return VLC_EGENERIC;
-    psz_ext = strrchr ( p_demux->psz_path, '.' );
-
-    if( !strncasecmp( (char *)p_peek, "[playlist]", 10 ) )
-    {
-        ;
-    }
-    else if( ( psz_ext && !strcasecmp( psz_ext, ".pls") ) ||
-             ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "pls") ) )
+    if( POKE( p_peek, "[playlist]", 10 ) || POKE( p_peek, "[Reference]", 10 ) ||
+        isExtension( p_demux, ".pls" )   || isDemux( p_demux, "pls" ) )
     {
         ;
     }
     else return VLC_EGENERIC;
 
-    msg_Dbg( p_demux, "found valid PLS playlist file");
-
-    p_demux->pf_control = Control;
-    p_demux->pf_demux = Demux;
-    p_demux->p_sys = malloc( sizeof(demux_sys_t) );
-    if( p_demux->p_sys == NULL )
-    {
-        msg_Err( p_demux, "out of memory" );
-        return VLC_ENOMEM;
-    }
+    STANDARD_DEMUX_INIT_MSG(  "found valid PLS playlist file");
     p_demux->p_sys->psz_prefix = E_(FindPrefix)( p_demux );
 
     return VLC_SUCCESS;
@@ -103,18 +82,20 @@ 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_position;
     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 );
             continue;
@@ -140,15 +121,19 @@ static int Demux( demux_t *p_demux )
         }
         /* find the number part of of file1, title1 or length1 etc */
         i_key_length = strlen( psz_key );
-        if( i_key_length >= 5 ) /* file1 type case */
+        if( i_key_length >= 4 ) /* Ref1 type case */
         {
-            i_new_item = atoi( psz_key + 4 );
-            if( i_new_item == 0 && i_key_length >= 6 ) /* title1 type case */
+            i_new_item = atoi( psz_key + 3 );
+            if( i_new_item == 0 && i_key_length >= 5 ) /* file1 type case */
             {
-                i_new_item = atoi( psz_key + 5 );
-                if( i_new_item == 0 && i_key_length >= 7 ) /* length1 type case */
+                i_new_item = atoi( psz_key + 4 );
+                if( i_new_item == 0 && i_key_length >= 6 ) /* title1 type case */
                 {
-                    i_new_item = atoi( psz_key + 6 );
+                    i_new_item = atoi( psz_key + 5 );
+                    if( i_new_item == 0 && i_key_length >= 7 ) /* length1 type case */
+                    {
+                        i_new_item = atoi( psz_key + 6 );
+                    }
                 }
             }
         }
@@ -169,10 +154,10 @@ 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->p_input, p_input );
+                playlist_BothAddInput( p_playlist, p_input, p_item_in_category,
+                                       PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
+                                       PLAYLIST_END, NULL, NULL );
             }
             else
             {
@@ -187,9 +172,22 @@ static int Demux( demux_t *p_demux )
             i_item = i_new_item;
             i_new_item = 0;
         }
-        if( !strncasecmp( psz_key, "file", sizeof("file") -1 ) )
+        if( !strncasecmp( psz_key, "file", sizeof("file") -1 ) ||
+            !strncasecmp( psz_key, "Ref", sizeof("Ref") -1 ) )
         {
+            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 ) )
         {
@@ -213,11 +211,11 @@ 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->p_input, p_input );
+        playlist_BothAddInput( p_playlist, p_input, p_item_in_category,
+                               PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
+                               PLAYLIST_END, NULL, NULL );
+        free( psz_mrl_orig );
         psz_mrl = NULL;
     }
     else
@@ -231,7 +229,7 @@ static int Demux( demux_t *p_demux )
     }
 
     HANDLE_PLAY_AND_RELEASE;
-    return VLC_SUCCESS;
+    return -1; /* Needed for correct operation of go back */
 }
 
 static int Control( demux_t *p_demux, int i_query, va_list args )