]> git.sesse.net Git - vlc/blobdiff - src/input/subtitles.c
input_DecoderCreate: missing const
[vlc] / src / input / subtitles.c
index 1e1a6eabbb18494b84b2d897c9ce6f5952cf266e..35b5f4c9154cc78ccb5b8ab69b3a237ed278fff9 100644 (file)
@@ -32,9 +32,7 @@
 #endif
 
 #include <ctype.h> /* isalnum() */
-#ifdef HAVE_UNISTD_H
-#   include <unistd.h>
-#endif
+#include <unistd.h>
 #include <sys/stat.h>
 
 #include <vlc_common.h>
@@ -51,7 +49,7 @@
 /**
  * The possible extensions for subtitle files we support
  */
-static const char const sub_exts[][6] = {
+static const char sub_exts[][6] = {
     "idx", "sub",  "srt",
     "ssa", "ass",  "smi",
     "utf", "utf8", "utf-8",
@@ -59,7 +57,7 @@ static const char const sub_exts[][6] = {
     "usf", "jss",  "cdg",
     "psb", "mpsub","mpl2",
     "pjs", "dks", "stl",
-    ""
+    "vtt",""
 };
 
 static void strcpy_trim( char *d, const char *s )
@@ -247,7 +245,9 @@ static char **paths_to_list( const char *psz_dir, char *psz_path )
 char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                          const char *psz_name_org )
 {
-    int i_fuzzy;
+    int i_fuzzy = var_GetInteger( p_this, "sub-autodetect-fuzzy" );
+    if ( i_fuzzy == 0 )
+        return NULL;
     int j, i_result2, i_sub_count, i_fname_len;
     char *f_fname_noext = NULL, *f_fname_trim = NULL;
 
@@ -297,8 +297,6 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
     strcpy_strip_ext( f_fname_noext, f_fname );
     strcpy_trim( f_fname_trim, f_fname_noext );
 
-    i_fuzzy = var_GetInteger( p_this, "sub-autodetect-fuzzy" );
-
     result = calloc( MAX_SUBTITLE_FILES+1, sizeof(vlc_subfn_t) ); /* We check it later (simplify code) */
     subdirs = paths_to_list( f_dir, psz_path );
     for( j = -1, i_sub_count = 0; (j == -1) || ( j >= 0 && subdirs != NULL && subdirs[j] != NULL ); j++ )
@@ -314,28 +312,23 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
 
         msg_Dbg( p_this, "looking for a subtitle file in %s", psz_dir );
 
-        char *psz_name;
+        const char *psz_name;
         while( (psz_name = vlc_readdir( dir )) && i_sub_count < MAX_SUBTITLE_FILES )
         {
             if( psz_name[0] == '.' || !subtitles_Filter( psz_name ) )
-            {
-                free( psz_name );
                 continue;
-            }
 
             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;
+            const char *tmp;
+            int i_prio = SUB_PRIORITY_NONE;
 
             /* retrieve various parts of the filename */
             strcpy_strip_ext( tmp_fname_noext, psz_name );
             strcpy_get_ext( tmp_fname_ext, psz_name );
             strcpy_trim( tmp_fname_trim, tmp_fname_noext );
 
-            i_prio = SUB_PRIORITY_NONE;
             if( !strcmp( tmp_fname_trim, f_fname_trim ) )
             {
                 /* matches the movie name exactly */
@@ -364,33 +357,27 @@ 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 ) + 2];
                 struct stat st;
+                char *path;
 
-                sprintf( psz_path, "%s"DIR_SEP"%s", psz_dir, psz_name );
-                if( !strcmp( psz_path, psz_fname ) )
-                {
-                    free( psz_name );
+                if( asprintf( &path, "%s"DIR_SEP"%s", psz_dir, psz_name ) < 0 )
                     continue;
-                }
 
-                if( !vlc_stat( psz_path, &st ) && S_ISREG( st.st_mode ) && result )
+                if( strcmp( path, psz_fname )
+                 && vlc_stat( path, &st ) == 0
+                 && S_ISREG( st.st_mode ) && result )
                 {
                     msg_Dbg( p_this,
                             "autodetected subtitle: %s with priority %d",
-                            psz_path, i_prio );
+                            path, i_prio );
                     result[i_sub_count].priority = i_prio;
-                    result[i_sub_count].psz_fname = strdup( psz_path );
+                    result[i_sub_count].psz_fname = path;
+                    path = NULL;
                     result[i_sub_count].psz_ext = strdup(tmp_fname_ext);
                     i_sub_count++;
                 }
-                else
-                {
-                    msg_Dbg( p_this, "stat failed (autodetecting subtitle: %s with priority %d)",
-                             psz_path, i_prio );
-                }
+                free( path );
             }
-            free( psz_name );
         }
         closedir( dir );
     }