[Mplayer-cvslog] CVS: main subreader.c,1.104,1.105

Jindrich Makovicka CVS henry at mplayerhq.hu
Wed Apr 9 22:49:37 CEST 2003


Update of /cvsroot/mplayer/main
In directory mail:/var/tmp.root/cvs-serv14610

Modified Files:
	subreader.c 
Log Message:
cleanups/bugfixes

Index: subreader.c
===================================================================
RCS file: /cvsroot/mplayer/main/subreader.c,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -r1.104 -r1.105
--- subreader.c	9 Apr 2003 18:04:04 -0000	1.104
+++ subreader.c	9 Apr 2003 20:49:12 -0000	1.105
@@ -1574,10 +1574,13 @@
 
 static int compare_sub_priority(const void *a, const void *b)
 {
-    int ret;
-    ret = ((subfn*)a)->priority < ((subfn*)b)->priority;
-    if (ret != 0) return ret;
-    return strcoll(((subfn*)a)->fname, ((subfn*)b)->fname);
+    if (((subfn*)a)->priority > ((subfn*)b)->priority) {
+	return -1;
+    } else if (((subfn*)a)->priority < ((subfn*)b)->priority) {
+	return 1;
+    } else {
+	return strcoll(((subfn*)a)->fname, ((subfn*)b)->fname);
+    }
 }
 
 char** sub_filenames(char* path, char *fname)
@@ -1666,59 +1669,46 @@
  
 		// we have a (likely) subtitle file
 		if (found) {
-		    if (strcmp(tmp_fname_trim, f_fname_trim) == 0) {
-			// matches the movie name?
-			sprintf(tmpresult, "%s%s", f_dir, de->d_name);
-			if ((f = fopen(tmpresult, "rt"))) {
-			    fclose(f);
-			    result[subcnt].priority = 4;
-			    result[subcnt].fname = strdup(tmpresult);
-			    subcnt++;
-			}
+		    int prio = 0;
+		    sprintf(tmpresult, "%s %s", f_fname_trim, tmp_sub_id);
+		    if (strcmp(tmp_fname_trim, tmpresult) == 0 && sub_match_fuzziness >= 1) {
+			// matches the movie name + lang extension
+			prio = 5;
+		    } else if (strcmp(tmp_fname_trim, f_fname_trim) == 0) {
+			// matches the movie name
+			prio = 4;
 		    } else if ((tmp = strstr(tmp_fname_trim, f_fname_trim)) && (sub_match_fuzziness >= 1)) {
-			// does it contain the movie name?
+			// contains the movie name
 			tmp += strlen(f_fname_trim);
 			if (tmp_sub_id && strstr(tmp, tmp_sub_id)) {
 			    // with sub_id specified prefer localized subtitles
-			    sprintf(tmpresult, "%s%s", f_dir, de->d_name);
-			    if ((f = fopen(tmpresult, "rt"))) {
-				fclose(f);
-				result[subcnt].priority = 3;
-				result[subcnt].fname = strdup(tmpresult);
-				subcnt++;
-			    }
+			    prio = 3;
 			} else if ((tmp_sub_id == NULL) && whiteonly(tmp)) {
 			    // without sub_id prefer "plain" name
-			    sprintf(tmpresult, "%s%s", f_dir, de->d_name);
-			    if ((f = fopen(tmpresult, "rt"))) {
-				fclose(f);
-				result[subcnt].priority = 3;
-				result[subcnt].fname = strdup(tmpresult);
-				subcnt++;
-			    }
+			    prio = 3;
 			} else {
 			    // with no localized subs found, try any else instead
-			    sprintf(tmpresult, "%s%s", f_dir, de->d_name);
-			    if ((f = fopen(tmpresult, "rt"))) {
-				fclose(f);
-				result[subcnt].priority = 2;
-				result[subcnt].fname = strdup(tmpresult);
-				subcnt++;
-			    }
+			    prio = 2;
 			}
 		    } else {
 			// doesn't contain the movie name
 			// don't try in the mplayer subtitle directory
 			if ((j == 0) && (sub_match_fuzziness >= 2)) {
-			    sprintf(tmpresult, "%s%s", f_dir, de->d_name);
-			    if ((f = fopen(tmpresult, "rt"))) {
-				fclose(f);
-				result[subcnt].priority = 1;
-				result[subcnt].fname = strdup(tmpresult);
-				subcnt++;
-			    }
+			    prio = 1;
 			}
 		    }
+
+		    if (prio) {
+			sprintf(tmpresult, "%s%s", f_dir, de->d_name);
+//			fprintf(stderr, "%s priority %d\n", tmpresult, prio);
+			if ((f = fopen(tmpresult, "rt"))) {
+			    fclose(f);
+			    result[subcnt].priority = prio;
+			    result[subcnt].fname = strdup(tmpresult);
+			    subcnt++;
+			}
+		    }
+
 		}
 		if (subcnt >= MAX_SUBTITLE_FILES) break;
 	    }



More information about the MPlayer-cvslog mailing list