mirror of https://github.com/mpv-player/mpv
cleanups/bugfixes
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@9896 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
88d65344eb
commit
e8ad4a04a7
74
subreader.c
74
subreader.c
|
@ -1574,10 +1574,13 @@ typedef struct _subfn
|
||||||
|
|
||||||
static int compare_sub_priority(const void *a, const void *b)
|
static int compare_sub_priority(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
int ret;
|
if (((subfn*)a)->priority > ((subfn*)b)->priority) {
|
||||||
ret = ((subfn*)a)->priority < ((subfn*)b)->priority;
|
return -1;
|
||||||
if (ret != 0) return ret;
|
} else if (((subfn*)a)->priority < ((subfn*)b)->priority) {
|
||||||
return strcoll(((subfn*)a)->fname, ((subfn*)b)->fname);
|
return 1;
|
||||||
|
} else {
|
||||||
|
return strcoll(((subfn*)a)->fname, ((subfn*)b)->fname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char** sub_filenames(char* path, char *fname)
|
char** sub_filenames(char* path, char *fname)
|
||||||
|
@ -1666,59 +1669,46 @@ char** sub_filenames(char* path, char *fname)
|
||||||
|
|
||||||
// we have a (likely) subtitle file
|
// we have a (likely) subtitle file
|
||||||
if (found) {
|
if (found) {
|
||||||
if (strcmp(tmp_fname_trim, f_fname_trim) == 0) {
|
int prio = 0;
|
||||||
// matches the movie name?
|
sprintf(tmpresult, "%s %s", f_fname_trim, tmp_sub_id);
|
||||||
sprintf(tmpresult, "%s%s", f_dir, de->d_name);
|
if (strcmp(tmp_fname_trim, tmpresult) == 0 && sub_match_fuzziness >= 1) {
|
||||||
if ((f = fopen(tmpresult, "rt"))) {
|
// matches the movie name + lang extension
|
||||||
fclose(f);
|
prio = 5;
|
||||||
result[subcnt].priority = 4;
|
} else if (strcmp(tmp_fname_trim, f_fname_trim) == 0) {
|
||||||
result[subcnt].fname = strdup(tmpresult);
|
// matches the movie name
|
||||||
subcnt++;
|
prio = 4;
|
||||||
}
|
|
||||||
} else if ((tmp = strstr(tmp_fname_trim, f_fname_trim)) && (sub_match_fuzziness >= 1)) {
|
} 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);
|
tmp += strlen(f_fname_trim);
|
||||||
if (tmp_sub_id && strstr(tmp, tmp_sub_id)) {
|
if (tmp_sub_id && strstr(tmp, tmp_sub_id)) {
|
||||||
// with sub_id specified prefer localized subtitles
|
// with sub_id specified prefer localized subtitles
|
||||||
sprintf(tmpresult, "%s%s", f_dir, de->d_name);
|
prio = 3;
|
||||||
if ((f = fopen(tmpresult, "rt"))) {
|
|
||||||
fclose(f);
|
|
||||||
result[subcnt].priority = 3;
|
|
||||||
result[subcnt].fname = strdup(tmpresult);
|
|
||||||
subcnt++;
|
|
||||||
}
|
|
||||||
} else if ((tmp_sub_id == NULL) && whiteonly(tmp)) {
|
} else if ((tmp_sub_id == NULL) && whiteonly(tmp)) {
|
||||||
// without sub_id prefer "plain" name
|
// without sub_id prefer "plain" name
|
||||||
sprintf(tmpresult, "%s%s", f_dir, de->d_name);
|
prio = 3;
|
||||||
if ((f = fopen(tmpresult, "rt"))) {
|
|
||||||
fclose(f);
|
|
||||||
result[subcnt].priority = 3;
|
|
||||||
result[subcnt].fname = strdup(tmpresult);
|
|
||||||
subcnt++;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// with no localized subs found, try any else instead
|
// with no localized subs found, try any else instead
|
||||||
sprintf(tmpresult, "%s%s", f_dir, de->d_name);
|
prio = 2;
|
||||||
if ((f = fopen(tmpresult, "rt"))) {
|
|
||||||
fclose(f);
|
|
||||||
result[subcnt].priority = 2;
|
|
||||||
result[subcnt].fname = strdup(tmpresult);
|
|
||||||
subcnt++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// doesn't contain the movie name
|
// doesn't contain the movie name
|
||||||
// don't try in the mplayer subtitle directory
|
// don't try in the mplayer subtitle directory
|
||||||
if ((j == 0) && (sub_match_fuzziness >= 2)) {
|
if ((j == 0) && (sub_match_fuzziness >= 2)) {
|
||||||
sprintf(tmpresult, "%s%s", f_dir, de->d_name);
|
prio = 1;
|
||||||
if ((f = fopen(tmpresult, "rt"))) {
|
|
||||||
fclose(f);
|
|
||||||
result[subcnt].priority = 1;
|
|
||||||
result[subcnt].fname = strdup(tmpresult);
|
|
||||||
subcnt++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
if (subcnt >= MAX_SUBTITLE_FILES) break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue