changeset 10340:2eaabacd1429

prefer UTF-8 encoding subs and automatically recognize them by suffix
author atlka
date Fri, 27 Jun 2003 09:25:05 +0000
parents 7074d8b6f585
children eee7cab79089
files subreader.c
diffstat 1 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/subreader.c	Thu Jun 26 13:21:59 2003 +0000
+++ b/subreader.c	Fri Jun 27 09:25:05 2003 +0000
@@ -1166,7 +1166,18 @@
     
     if(filename==NULL) return NULL; //qnx segfault
     fd=fopen (filename, "r"); if (!fd) return NULL;
-
+    {
+	    int l;
+	    if ((l=strlen(filename))>4){
+		    int k;
+		    char *exts[] = {".utf", ".utf8", ".utf-8" };
+		    for (k=3;--k>=0;)
+			if (!strcasecmp(filename+(l - strlen(exts[k])), exts[k])){
+			    sub_utf8 = 1;
+			    break;
+			}
+	    }
+    }
     sub_format=sub_autodetect (fd, &uses_time);
     mpsub_multiplier = (uses_time ? 100.0 : 1.0);
     if (sub_format==SUB_INVALID) {mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: Could not determine file format\n");return NULL;}
@@ -1589,7 +1600,7 @@
     char *tmp_fname_noext, *tmp_fname_trim, *tmp_fname_ext, *tmpresult;
  
     int len, pos, found, i, j;
-    char * sub_exts[] = { "utf", "sub", "srt", "smi", "rt", "txt", "ssa", "aqt", "jss", NULL};
+    char * sub_exts[] = {  "utf", "utf8", "utf-8", "sub", "srt", "smi", "rt", "txt", "ssa", "aqt", "jss", NULL};
     subfn *result;
     char **result2;
     
@@ -1657,7 +1668,7 @@
 		// does it end with a subtitle extension?
 		found = 0;
 #ifdef USE_ICONV
-		for (i = (sub_cp ? 1 : 0); sub_exts[i]; i++) {
+		for (i = (sub_cp ? 3 : 0); sub_exts[i]; i++) {
 #else
 		for (i = 0; sub_exts[i]; i++) {
 #endif
@@ -1699,6 +1710,9 @@
 		    }
 
 		    if (prio) {
+			prio += prio;
+			if (i<3) // prefer UTF-8 coded
+			    prio++;
 			sprintf(tmpresult, "%s%s", j == 0 ? f_dir : path, de->d_name);
 //			fprintf(stderr, "%s priority %d\n", tmpresult, prio);
 			if ((f = fopen(tmpresult, "rt"))) {