]> git.sesse.net Git - vlc/commitdiff
demux/playlist/: New "video portals" playlist demux. You feed it a url from a popular...
authorAntoine Cellerier <dionoea@videolan.org>
Fri, 11 May 2007 22:27:33 +0000 (22:27 +0000)
committerAntoine Cellerier <dionoea@videolan.org>
Fri, 11 May 2007 22:27:33 +0000 (22:27 +0000)
modules/demux/playlist/Modules.am
modules/demux/playlist/playlist.c
modules/demux/playlist/playlist.h
modules/demux/playlist/podcast.c
modules/demux/playlist/videoportals.c [new file with mode: 0644]

index e0cea84585faf26a51bcb212ba4a8e4ad895c2e3..c8cb97521af19606832953de8aede429bb0479e7 100644 (file)
@@ -14,6 +14,7 @@ SOURCES_playlist = \
        qtl.c \
        gvp.c \
        ifo.c \
+       videoportals.c \
        $(NULL)
 
 
index 4add6d98c9a24ab4010595f78bca97618bd9e191..46b487ece90fd0e89f0503e09e69595eb03a4403 100644 (file)
@@ -116,6 +116,11 @@ vlc_module_begin();
         set_description( _("Dummy ifo demux") );
         set_capability( "demux2", 12 );
         set_callbacks( E_(Import_IFO), E_(Close_IFO) );
+    add_submodule();
+        set_description( _("Video portal url converter") );
+        add_shortcut( "videoportal" );
+        set_capability( "demux2", 10 );
+        set_callbacks( E_(Import_VideoPortal), E_(Close_VideoPortal) );
 vlc_module_end();
 
 
index 18e6717850c7fbae72938598c7bd22eb6198b3d1..0e71ab2b799cc4c53facfce2a7135b246e813c1b 100644 (file)
@@ -70,6 +70,9 @@ void E_(Close_GVP) ( vlc_object_t * );
 int E_(Import_IFO) ( vlc_object_t * );
 void E_(Close_IFO) ( vlc_object_t * );
 
+int E_(Import_VideoPortal) ( vlc_object_t * );
+void E_(Close_VideoPortal) ( vlc_object_t * );
+
 #define INIT_PLAYLIST_STUFF \
     playlist_t *p_playlist = pl_Yield( p_demux ); \
     vlc_bool_t b_play = var_CreateGetBool( p_demux, "playlist-autostart" ); \
index ca19bf8148feadc0827c9b21f979e376698ed9a0..e63c0ff8599b948f5869dfbd9abd6bccc2bc8350 100644 (file)
@@ -55,7 +55,7 @@ int E_(Import_podcast)( vlc_object_t *p_this )
 
     if( !isDemux( p_demux, "podcast" ) )
         return VLC_EGENERIC;
-    
+
     STANDARD_DEMUX_INIT_MSG( "using podcast reader" );
     p_demux->p_sys->psz_prefix = E_(FindPrefix)( p_demux );
     p_demux->p_sys->p_playlist = NULL;
diff --git a/modules/demux/playlist/videoportals.c b/modules/demux/playlist/videoportals.c
new file mode 100644 (file)
index 0000000..c1918fe
--- /dev/null
@@ -0,0 +1,144 @@
+/*****************************************************************************
+ * videoportals.c: Convert video webportal HTML urls to the appropriate video
+ *                 stream url.
+ *****************************************************************************
+ * Copyright (C) 2007 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Antoine Cellerier <dionoea @t videolan d.t org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include <vlc/vlc.h>
+#include <vlc_demux.h>
+
+#include <errno.h>                                                 /* ENOMEM */
+#include "playlist.h"
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int Demux( demux_t *p_demux);
+static int Control( demux_t *p_demux, int i_query, va_list args );
+
+struct demux_sys_t
+{
+    char *psz_url;
+};
+
+/*****************************************************************************
+ * Import_VideoPortal: main import function
+ *****************************************************************************/
+int E_(Import_VideoPortal)( vlc_object_t *p_this )
+{
+    demux_t *p_demux = (demux_t *)p_this;
+    const char *psz_path = p_demux->psz_path;
+    char *psz_cur;
+    char *psz_url = NULL;
+
+    /* YouTube */
+    if( ( psz_cur = strstr( psz_path, "youtube.com" ) ) )
+    {
+        psz_cur += strlen( "youtube.com" );
+        psz_cur = strchr( psz_cur, '/' );
+        if( psz_cur )
+        {
+            psz_cur++;
+            if( !strncmp( psz_cur, "watch?v=", strlen( "watch?v=" ) ) )
+            {
+                /* This is the webpage's url */
+                psz_cur += strlen( "watch?v=" );
+                asprintf( &psz_url, "http://www.youtube.com/v/%s", psz_cur );
+            }
+            else if( !strncmp( psz_cur, "p.swf", strlen( "p.swf" ) ) )
+            {
+                /* This is the swf flv player url (which we get after a
+                 * redirect from the http://www.youtube.com/v/video_id url */
+                char *video_id = strstr( psz_cur, "video_id=" );
+                char *t = strstr( psz_cur, "t=" );
+                if( video_id && t )
+                {
+                    char *psz_buf;
+                    video_id += strlen( "video_id=" );
+                    t += strlen( "t=" );
+                    psz_buf = strchr( video_id, '&' );
+                    if( psz_buf ) *psz_buf = '\0';
+                    psz_buf = strchr( t, '&' );
+                    if( psz_buf ) *psz_buf = '\0';
+                    asprintf( &psz_url, "http://www.youtube.com/"
+                              "get_video.php?video_id=%s&t=%s",
+                              video_id, t );
+                }
+            }
+        }
+    }
+
+    if( !psz_url )
+    {
+        return VLC_EGENERIC;
+    }
+
+    p_demux->p_sys = (demux_sys_t*)malloc( sizeof( demux_sys_t ) );
+    if( !p_demux->p_sys )
+    {
+        free( psz_url );
+        return VLC_ENOMEM;
+    }
+    p_demux->p_sys->psz_url = psz_url;
+
+    p_demux->pf_control = Control;
+    p_demux->pf_demux = Demux;
+
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Deactivate: frees unused data
+ *****************************************************************************/
+void E_(Close_VideoPortal)( vlc_object_t *p_this )
+{
+    demux_t *p_demux = (demux_t *)p_this;
+    free( p_demux->p_sys->psz_url );
+    free( p_demux->p_sys );
+}
+
+static int Demux( demux_t *p_demux )
+{
+    char *psz_url = p_demux->p_sys->psz_url;
+    input_item_t *p_input;
+
+    msg_Dbg( p_demux, "Redirecting %s to %s", p_demux->psz_path, psz_url );
+
+    INIT_PLAYLIST_STUFF;
+
+    p_input = input_ItemNewExt( p_playlist, psz_url, psz_url, 0, NULL, -1 );
+    playlist_BothAddInput( p_playlist, p_input,
+                           p_item_in_category,
+                           PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
+                           PLAYLIST_END, NULL, NULL, VLC_FALSE );
+
+    HANDLE_PLAY_AND_RELEASE;
+
+    return -1; /* Needed for correct operation of go back */
+}
+
+static int Control( demux_t *p_demux, int i_query, va_list args )
+{
+    return VLC_EGENERIC;
+}