]> git.sesse.net Git - vlc/blobdiff - modules/demux/playlist/m3u.c
Fix opening of some podcasts.
[vlc] / modules / demux / playlist / m3u.c
index 1a054a29f05d74b2ba202b6fed54520dc0924bc6..b5369ef7126bbcb5dd6891f24bc16493efdcb8bb 100644 (file)
@@ -47,6 +47,7 @@ struct demux_sys_t
 static int Demux( demux_t *p_demux);
 static int Control( demux_t *p_demux, int i_query, va_list args );
 static void parseEXTINF( char *psz_string, char **ppsz_artist, char **ppsz_name, int *pi_duration );
+static bool ContainsURL( demux_t *p_demux );
 
 /*****************************************************************************
  * Import_M3U: main import function
@@ -61,7 +62,7 @@ int Import_M3U( vlc_object_t *p_this )
            demux_IsPathExtension( p_demux, ".m3u" ) || demux_IsPathExtension( p_demux, ".vlc" ) ||
            /* A .ram file can contain a single rtsp link */
            demux_IsPathExtension( p_demux, ".ram" ) || demux_IsPathExtension( p_demux, ".rm" ) ||
-           demux_IsForced( p_demux,  "m3u" ) ) )
+           demux_IsForced( p_demux,  "m3u" ) || ContainsURL( p_demux ) ) )
         return VLC_EGENERIC;
 
     STANDARD_DEMUX_INIT_MSG( "found valid M3U playlist" );
@@ -70,6 +71,40 @@ int Import_M3U( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
+static bool ContainsURL( demux_t *p_demux )
+{
+    const uint8_t *p_peek, *p_peek_end;
+    int i_peek;
+
+    i_peek = stream_Peek( p_demux->s, &p_peek, 1024 );
+    if( i_peek <= 0 ) return false;
+    p_peek_end = p_peek + i_peek;
+
+    while( p_peek + sizeof( "https://" ) < p_peek_end )
+    {
+        /* One line starting with an URL is enough */
+        if( !strncasecmp( (const char *)p_peek, "http://", 7 ) ||
+            !strncasecmp( (const char *)p_peek, "mms://", 6 ) ||
+            !strncasecmp( (const char *)p_peek, "rtsp://", 7 ) ||
+            !strncasecmp( (const char *)p_peek, "https://", 8 ) ||
+            !strncasecmp( (const char *)p_peek, "ftp://", 6 ) )
+        {
+            return true;
+        }
+        /* Comments and blank lines are ignored */
+        else if( *p_peek != '#' && *p_peek != '\n' && *p_peek != '\r')
+        {
+            return false;
+        }
+
+        while( p_peek < p_peek_end && *p_peek != '\n' )
+            p_peek++;
+        if ( *p_peek == '\n' )
+            p_peek++;
+    }
+    return false;
+}
+
 /*****************************************************************************
  * Deactivate: frees unused data
  *****************************************************************************/
@@ -182,15 +217,15 @@ static int Demux( demux_t *p_demux )
             b_cleanup = true;
             if( !psz_mrl ) goto error;
 
-            p_input = input_ItemNewExt( p_demux, psz_mrl, psz_name,
+            p_input = input_item_NewExt( p_demux, psz_mrl, psz_name,
                                         0, NULL, i_duration );
 
             if ( psz_artist && *psz_artist )
                 input_item_SetArtist( p_input, psz_artist );
 
-            input_ItemAddSubItem( p_current_input, p_input );
+            input_item_AddSubItem( p_current_input, p_input );
             for( int i = 0; i < i_options; i++ )
-                input_ItemAddOpt( p_input, ppsz_options[i], 0 );
+                input_item_AddOpt( p_input, ppsz_options[i], 0 );
             vlc_gc_decref( p_input );
             free( psz_mrl );
         }