]> git.sesse.net Git - vlc/blobdiff - src/input/subtitles.c
Do not scan for subtitles files in the current dir for TS files
[vlc] / src / input / subtitles.c
index fadc067d45affdd8dec6dfbeb3f1998a3f79aa22..9976bac1b19e2f2eeaf9ec67d5cadc6a7e0d1949 100644 (file)
@@ -218,11 +218,9 @@ static char **paths_to_list( const char *psz_dir, char *psz_path )
         if( *psz_subdir == '\0' )
             continue;
 
-        if( asprintf( &subdirs[i++], "%s%s%c",
+        if( asprintf( &subdirs[i++], "%s%s",
                   psz_subdir[0] == '.' ? psz_dir : "",
-                  psz_subdir,
-                  psz_subdir[strlen(psz_subdir) - 1] == DIR_SEP_CHAR ?
-                                           '\0' : DIR_SEP_CHAR ) == -1 )
+                  psz_subdir ) == -1 )
             break;
     }
     subdirs[i] = NULL;
@@ -251,8 +249,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
 {
     int i_fuzzy;
     int j, i_result2, i_sub_count, i_fname_len;
-    char *f_dir = NULL, *f_fname = NULL, *f_fname_noext = NULL, *f_fname_trim = NULL;
-    char *tmp = NULL;
+    char *f_fname_noext = NULL, *f_fname_trim = NULL;
 
     char **subdirs; /* list of subdirectories to look in */
 
@@ -262,67 +259,42 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
     if( !psz_name_org )
         return NULL;
 
-    if( !strncmp( psz_name_org, "file://", 7 ) )
-    {
-        psz_name_org += 7;
-#if defined( WIN32 )
-        psz_name_org ++ ;
-#endif
-        if( !strncmp( psz_name_org, "localhost", 9 ) )
-            psz_name_org += 9;
-    }
-
-#if (DIR_SEP_CHAR != '/')
-        /* Turn slashes into anti-slashes */
-        for( char *s = strchr( psz_name_org, '/' ); s; s = strchr( s + 1, '/' ) )
-            *s = DIR_SEP_CHAR;
-#endif
-    char *psz_fname = decode_URI_duplicate( psz_name_org );
+    char *psz_fname = make_path( psz_name_org );
     if( !psz_fname )
         return NULL;
 
     /* extract filename & dirname from psz_fname */
-    tmp = strrchr( psz_fname, DIR_SEP_CHAR );
-    if( tmp )
+    char *f_dir = strdup( psz_fname );
+    if( f_dir == NULL )
     {
-        const int i_dirlen = strlen(psz_fname)-strlen(tmp)+1; /* include the separator */
-        f_fname = strdup( &tmp[1] );    /* skip the separator */
-        f_dir = strndup( psz_fname, i_dirlen );
+        free( psz_fname );
+        return NULL;
     }
-    else
-    {
-#if defined (HAVE_UNISTD_H) && !defined (UNDER_CE)
-        /* Get the current working directory */
-        char *psz_cwd = getcwd( NULL, 0 );
-#else
-        char *psz_cwd = NULL;
-#endif
-        if( !psz_cwd )
-        {
-            free( psz_fname );
-            return NULL;
-        }
 
-        f_fname = strdup( psz_fname );
-        if( asprintf( &f_dir, "%s%c", psz_cwd, DIR_SEP_CHAR ) == -1 )
-            f_dir = NULL; /* Assure that function will return in next test */
-        free( psz_cwd );
-    }
-    if( !f_fname || !f_dir )
+    char *f_fname = strrchr( f_dir, DIR_SEP_CHAR );
+    if( !f_fname )
     {
-        free( f_fname );
         free( f_dir );
         free( psz_fname );
         return NULL;
     }
+    *(f_fname++) = 0; /* skip dir separator */
 
     i_fname_len = strlen( f_fname );
 
+    /* HACK: do not look for subtitles for Transport Streams */
+    /* This breaks the clock synchronization */
+    if( i_fname_len > 3 && !strcasecmp( f_fname + i_fname_len - 3, ".ts" ) )
+    {
+        free( f_dir );
+        free( psz_fname );
+        return NULL;
+    }
+
     f_fname_noext = malloc(i_fname_len + 1);
     f_fname_trim = malloc(i_fname_len + 1 );
     if( !f_fname_noext || !f_fname_trim )
     {
-        free( f_fname );
         free( f_dir );
         free( f_fname_noext );
         free( f_fname_trim );
@@ -347,7 +319,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
             continue;
 
         /* parse psz_src dir */
-        i_dir_content = utf8_scandir( psz_dir, &ppsz_dir_content,
+        i_dir_content = vlc_scandir( psz_dir, &ppsz_dir_content,
                                       subtitles_Filter, NULL );
         if( i_dir_content < 0 )
             continue;
@@ -359,6 +331,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
             char tmp_fname_noext[strlen( psz_name ) + 1];
             char tmp_fname_trim[strlen( psz_name ) + 1];
             char tmp_fname_ext[strlen( psz_name ) + 1];
+            char *tmp;
 
             int i_prio;
 
@@ -401,14 +374,14 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
             }
             if( i_prio >= i_fuzzy )
             {
-                char psz_path[strlen( psz_dir ) + strlen( psz_name ) + 1];
+                char psz_path[strlen( psz_dir ) + strlen( psz_name ) + 2];
                 struct stat st;
 
-                sprintf( psz_path, "%s%s", psz_dir, psz_name );
+                sprintf( psz_path, "%s"DIR_SEP"%s", psz_dir, psz_name );
                 if( !strcmp( psz_path, psz_fname ) )
                     continue;
 
-                if( !utf8_stat( psz_path, &st ) && S_ISREG( st.st_mode ) && result )
+                if( !vlc_stat( psz_path, &st ) && S_ISREG( st.st_mode ) && result )
                 {
                     msg_Dbg( p_this,
                             "autodetected subtitle: %s with priority %d",
@@ -438,7 +411,6 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
             free( subdirs[j] );
         free( subdirs );
     }
-    free( f_fname );
     free( f_dir );
     free( f_fname_trim );
     free( f_fname_noext );