[vlc-devel] Re: patch: url handling and frament identifier

Terje Bakken terje at terki.no
Tue Jul 13 20:10:14 CEST 2004


On Mon, 12 Jul 2004, Terje Bakken wrote:

> This patch to current version in svn, enables VLC to handle URLs starting
> with vlc: and to set start and stop time through the use of URL fragment
> [..]

I'm sorry, there were some errors in the patch that prevented it from
working. This updated patch fixes this. See original mail for the details
concerning this patch.

Regards,

Terje Bakken
-------------- next part --------------
Index: src/input/input.c
===================================================================
--- src/input/input.c	(revision 8180)
+++ src/input/input.c	(working copy)
@@ -1868,6 +1868,10 @@
     char *psz_path   = NULL;
     char *psz;
 
+    if( strncasecmp( psz_dup, "vlc:",4 ) == 0 && strrchr( psz_dup, ':' ) > psz_dup + 3 )
+    {
+        psz_dup += 4;
+    }
     psz = strchr( psz_dup, ':' );
 
 #if defined( WIN32 ) || defined( UNDER_CE )
Index: src/input/access.c
===================================================================
--- src/input/access.c	(revision 8180)
+++ src/input/access.c	(working copy)
@@ -22,6 +22,7 @@
  *****************************************************************************/
 
 #include <stdlib.h>
+#include <string.h>
 #include <vlc/vlc.h>
 #include <vlc/input.h>
 
@@ -33,6 +34,10 @@
 access_t *__access2_New( vlc_object_t *p_obj,
                          char *psz_access, char *psz_demux, char *psz_path )
 {
+    vlc_value_t val;
+    char *s;
+    input_thread_t * p_input;    
+    
     access_t *p_access = vlc_object_create( p_obj, VLC_OBJECT_ACCESS );
 
     if( p_access == NULL )
@@ -61,6 +66,82 @@
     p_access->info.i_title  = 0;
     p_access->info.i_seekpoint = 0;
 
+    /* Look for anchor in URL */
+    
+    if( (s=strrchr(p_access->psz_path,'#'))!=NULL ) 
+    {
+        *s='\0'; /* do not send fragment identifier to server */
+        p_input = vlc_object_find( p_access, VLC_OBJECT_INPUT, FIND_ANYWHERE );
+        if( !p_input ) 
+        {
+            msg_Err( p_obj,"p_input not found!\n" );
+        }
+        else 
+        {
+            int res;
+            int hour=0;
+            int minute=0;
+            int second=0;
+            char *endptr;
+            char anchor[20]; /* max: 00:00:00-00:00:00 */
+            char *stoptime;
+            strncpy( anchor,s+1,sizeof(anchor) );
+            anchor[sizeof(anchor)-1] = '\0';
+            if( (stoptime = strchr(anchor,'-'))!=NULL ) 
+            {
+                *stoptime++='\0';
+            }
+            s=anchor;
+            do 
+            {
+                hour = 0;
+                minute = 0;
+                second = 0;
+                res = strtol( s,&endptr,10 );
+                if( endptr>s && *endptr=='\0' ) /* only seconds */
+                {
+                    second=res;
+                }
+                else if( endptr>s && *endptr==':' ) /* we have mm:ss */
+                {
+                    minute = res;
+                    s = endptr+1;
+                    res = strtol(s,&endptr,10);
+                    if( endptr>s && *endptr=='\0' ) 
+                    {
+                        second=res;
+                    }
+                    else if( endptr>s && *endptr==':' ) /* we have hh:mm:ss */
+                    {
+                        hour = minute;
+                        minute = res;
+                        s = endptr+1;
+                        res = strtol( s,&endptr,10 );
+                        if( endptr>s && *endptr=='\0' )
+                        {
+                            second = res;
+                        }
+                    }
+                }
+                val.i_int = hour*60*60+minute*60+second;
+                if( stoptime==NULL || s<stoptime ) /* first iteration = start */
+                {
+                    res = var_Set( p_input, "start-time", val);
+                    msg_Dbg( p_obj,"start-time set %d, result: %d\n",
+                             val.i_int,res );
+                    s = stoptime;
+                }
+                else /* second iteration = end */
+                {
+                    res = var_Set( p_input, "stop-time", val );
+                    msg_Dbg( p_obj, "end-time set %d, result: %d\n",
+                             val.i_int,res );
+                    s = NULL;
+                }
+            } while( stoptime!=NULL && s!=NULL );
+            vlc_object_release( p_input );
+        }
+    }
 
     /* Before module_Need (for var_Create...) */
     vlc_object_attach( p_access, p_obj );


More information about the vlc-devel mailing list