comparison subreader.c @ 9893:eb274fd5e84e

option for sub match fuzziness level
author henry
date Wed, 09 Apr 2003 18:04:29 +0000
parents 9f3e8c42a7cb
children fd2dbce1ba3b
comparison
equal deleted inserted replaced
9892:f6d1df877e89 9893:eb274fd5e84e
38 static int sub_slacktime = 20000; //20 sec 38 static int sub_slacktime = 20000; //20 sec
39 39
40 int sub_no_text_pp=0; // 1 => do not apply text post-processing 40 int sub_no_text_pp=0; // 1 => do not apply text post-processing
41 // like {\...} elimination in SSA format. 41 // like {\...} elimination in SSA format.
42 42
43 int subfuzzy_enabled=0; // be _really_ fuzzy when looking for subtitles 43 int sub_match_fuzziness=0; // level of sub name matching fuzziness
44 44
45 /* Use the SUB_* constant defined in the header file */ 45 /* Use the SUB_* constant defined in the header file */
46 int sub_format=SUB_INVALID; 46 int sub_format=SUB_INVALID;
47 #ifdef USE_SORTSUB 47 #ifdef USE_SORTSUB
48 /* 48 /*
1572 char *fname; 1572 char *fname;
1573 } subfn; 1573 } subfn;
1574 1574
1575 static int compare_sub_priority(const void *a, const void *b) 1575 static int compare_sub_priority(const void *a, const void *b)
1576 { 1576 {
1577 return ((subfn*)a)->priority < ((subfn*)b)->priority; 1577 int ret;
1578 ret = ((subfn*)a)->priority < ((subfn*)b)->priority;
1579 if (ret != 0) return ret;
1580 return strcoll(((subfn*)a)->fname, ((subfn*)b)->fname);
1578 } 1581 }
1579 1582
1580 char** sub_filenames(char* path, char *fname) 1583 char** sub_filenames(char* path, char *fname)
1581 { 1584 {
1582 char *f_dir, *f_fname, *f_fname_noext, *f_fname_trim, *tmp, *tmp_sub_id; 1585 char *f_dir, *f_fname, *f_fname_noext, *f_fname_trim, *tmp, *tmp_sub_id;
1661 } 1664 }
1662 } 1665 }
1663 1666
1664 // we have a (likely) subtitle file 1667 // we have a (likely) subtitle file
1665 if (found) { 1668 if (found) {
1666 // does it contain the movie name? 1669 if (strcmp(tmp_fname_trim, f_fname_trim) == 0) {
1667 tmp = strstr(tmp_fname_trim, f_fname_trim); 1670 // matches the movie name?
1668 if (tmp) { 1671 sprintf(tmpresult, "%s%s", f_dir, de->d_name);
1672 if ((f = fopen(tmpresult, "rt"))) {
1673 fclose(f);
1674 result[subcnt].priority = 4;
1675 result[subcnt].fname = strdup(tmpresult);
1676 subcnt++;
1677 }
1678 } else if ((tmp = strstr(tmp_fname_trim, f_fname_trim)) && (sub_match_fuzziness >= 1)) {
1679 // does it contain the movie name?
1669 tmp += strlen(f_fname_trim); 1680 tmp += strlen(f_fname_trim);
1670 if (tmp_sub_id && strstr(tmp, tmp_sub_id)) { 1681 if (tmp_sub_id && strstr(tmp, tmp_sub_id)) {
1671 // with sub_id specified prefer localized subtitles 1682 // with sub_id specified prefer localized subtitles
1672 sprintf(tmpresult, "%s%s", f_dir, de->d_name); 1683 sprintf(tmpresult, "%s%s", f_dir, de->d_name);
1673 if ((f = fopen(tmpresult, "rt"))) { 1684 if ((f = fopen(tmpresult, "rt"))) {
1696 } 1707 }
1697 } 1708 }
1698 } else { 1709 } else {
1699 // doesn't contain the movie name 1710 // doesn't contain the movie name
1700 // don't try in the mplayer subtitle directory 1711 // don't try in the mplayer subtitle directory
1701 if ((j == 0) && subfuzzy_enabled) { 1712 if ((j == 0) && (sub_match_fuzziness >= 2)) {
1702 sprintf(tmpresult, "%s%s", f_dir, de->d_name); 1713 sprintf(tmpresult, "%s%s", f_dir, de->d_name);
1703 if ((f = fopen(tmpresult, "rt"))) { 1714 if ((f = fopen(tmpresult, "rt"))) {
1704 fclose(f); 1715 fclose(f);
1705 result[subcnt].priority = 1; 1716 result[subcnt].priority = 1;
1706 result[subcnt].fname = strdup(tmpresult); 1717 result[subcnt].fname = strdup(tmpresult);