]> git.sesse.net Git - vlc/blobdiff - src/input/subtitles.c
Copyright fixes
[vlc] / src / input / subtitles.c
index caf75ab77159bd28cbb719763976e24ee12e93e5..751562c061f542dad1fc7c05630c70ae68784b5e 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * subtitles.c
  *****************************************************************************
- * Copyright (C) 2003-2004 VideoLAN
+ * Copyright (C) 2003-2004 VideoLAN (Centrale Réseaux) and its contributors
  * $Id$
  *
  * Authors: Derk-Jan Hartman <hartman at videolan.org>
@@ -33,8 +33,6 @@
 
 #ifdef HAVE_DIRENT_H
 #   include <dirent.h>
-#else
-#   include "../extras/dirent.h"
 #endif
 
 #include <ctype.h>
@@ -131,6 +129,7 @@ typedef struct _subfn
 {
     int priority;
     char *psz_fname;
+    char *psz_ext;
 } subfn;
 
 static int compare_sub_priority( const void *a, const void *b )
@@ -239,7 +238,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
     /* variables to be used for derivatives FILE *f */
     char *tmp_fname_noext, *tmp_fname_trim, *tmp_fname_ext, *tmpresult;
     vlc_value_t fuzzy;
-    int len, i, j, i_sub_count;
+    int len, i, j, i_sub_count, i_result2;
     subfn *result; /* unsorted results */
     char **result2; /* sorted results */
     char **tmp_subdirs, **subdirs; /* list of subdirectories to look in */
@@ -367,6 +366,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                             fclose( f );
                             result[i_sub_count].priority = i_prio;
                             result[i_sub_count].psz_fname = strdup(tmpresult);
+                            result[i_sub_count].psz_ext = strdup(tmp_fname_ext);
                             i_sub_count++;
                         }
                     }
@@ -395,12 +395,33 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
 
     result2 = (char**)malloc( sizeof(char*) * ( i_sub_count + 1 ) );
     memset( result2, 0, sizeof(char*) * ( i_sub_count + 1 ) );
+    i_result2 = 0;
 
     for( i = 0; i < i_sub_count; i++ )
     {
-        result2[i] = result[i].psz_fname;
+        if( result[i].psz_ext && !strcasecmp( result[i].psz_ext, "sub" ) )
+        {
+            int j;
+            for( j = 0; j < i_sub_count; j++ )
+            {
+                if( result[j].psz_fname && result[i].psz_fname &&
+                    !strncasecmp( result[i].psz_fname, result[j].psz_fname, sizeof( result[i].psz_fname) - 4 ) && 
+                    !strcasecmp( result[j].psz_ext, "idx" ) )
+                    break;
+                
+            }
+            if( j >= i_sub_count )
+            {
+                result2[i_result2] = result[i].psz_fname;
+                i_result2++;
+            }
+        }
+        else
+        {
+            result2[i_result2] = result[i].psz_fname;
+            i_result2++;
+        }
     }
-    result2[i_sub_count] = NULL;
     free( result );
     return result2;
 }