Mercurial > mplayer.hg
comparison subreader.c @ 9895:fd2dbce1ba3b
cleanups/bugfixes
author | henry |
---|---|
date | Wed, 09 Apr 2003 20:49:12 +0000 |
parents | eb274fd5e84e |
children | 5f0d4b36db5a |
comparison
equal
deleted
inserted
replaced
9894:3933e0ef000c | 9895:fd2dbce1ba3b |
---|---|
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 int ret; | 1577 if (((subfn*)a)->priority > ((subfn*)b)->priority) { |
1578 ret = ((subfn*)a)->priority < ((subfn*)b)->priority; | 1578 return -1; |
1579 if (ret != 0) return ret; | 1579 } else if (((subfn*)a)->priority < ((subfn*)b)->priority) { |
1580 return strcoll(((subfn*)a)->fname, ((subfn*)b)->fname); | 1580 return 1; |
1581 } else { | |
1582 return strcoll(((subfn*)a)->fname, ((subfn*)b)->fname); | |
1583 } | |
1581 } | 1584 } |
1582 | 1585 |
1583 char** sub_filenames(char* path, char *fname) | 1586 char** sub_filenames(char* path, char *fname) |
1584 { | 1587 { |
1585 char *f_dir, *f_fname, *f_fname_noext, *f_fname_trim, *tmp, *tmp_sub_id; | 1588 char *f_dir, *f_fname, *f_fname_noext, *f_fname_trim, *tmp, *tmp_sub_id; |
1664 } | 1667 } |
1665 } | 1668 } |
1666 | 1669 |
1667 // we have a (likely) subtitle file | 1670 // we have a (likely) subtitle file |
1668 if (found) { | 1671 if (found) { |
1669 if (strcmp(tmp_fname_trim, f_fname_trim) == 0) { | 1672 int prio = 0; |
1670 // matches the movie name? | 1673 sprintf(tmpresult, "%s %s", f_fname_trim, tmp_sub_id); |
1671 sprintf(tmpresult, "%s%s", f_dir, de->d_name); | 1674 if (strcmp(tmp_fname_trim, tmpresult) == 0 && sub_match_fuzziness >= 1) { |
1672 if ((f = fopen(tmpresult, "rt"))) { | 1675 // matches the movie name + lang extension |
1673 fclose(f); | 1676 prio = 5; |
1674 result[subcnt].priority = 4; | 1677 } else if (strcmp(tmp_fname_trim, f_fname_trim) == 0) { |
1675 result[subcnt].fname = strdup(tmpresult); | 1678 // matches the movie name |
1676 subcnt++; | 1679 prio = 4; |
1677 } | |
1678 } else if ((tmp = strstr(tmp_fname_trim, f_fname_trim)) && (sub_match_fuzziness >= 1)) { | 1680 } else if ((tmp = strstr(tmp_fname_trim, f_fname_trim)) && (sub_match_fuzziness >= 1)) { |
1679 // does it contain the movie name? | 1681 // contains the movie name |
1680 tmp += strlen(f_fname_trim); | 1682 tmp += strlen(f_fname_trim); |
1681 if (tmp_sub_id && strstr(tmp, tmp_sub_id)) { | 1683 if (tmp_sub_id && strstr(tmp, tmp_sub_id)) { |
1682 // with sub_id specified prefer localized subtitles | 1684 // with sub_id specified prefer localized subtitles |
1683 sprintf(tmpresult, "%s%s", f_dir, de->d_name); | 1685 prio = 3; |
1684 if ((f = fopen(tmpresult, "rt"))) { | |
1685 fclose(f); | |
1686 result[subcnt].priority = 3; | |
1687 result[subcnt].fname = strdup(tmpresult); | |
1688 subcnt++; | |
1689 } | |
1690 } else if ((tmp_sub_id == NULL) && whiteonly(tmp)) { | 1686 } else if ((tmp_sub_id == NULL) && whiteonly(tmp)) { |
1691 // without sub_id prefer "plain" name | 1687 // without sub_id prefer "plain" name |
1692 sprintf(tmpresult, "%s%s", f_dir, de->d_name); | 1688 prio = 3; |
1693 if ((f = fopen(tmpresult, "rt"))) { | |
1694 fclose(f); | |
1695 result[subcnt].priority = 3; | |
1696 result[subcnt].fname = strdup(tmpresult); | |
1697 subcnt++; | |
1698 } | |
1699 } else { | 1689 } else { |
1700 // with no localized subs found, try any else instead | 1690 // with no localized subs found, try any else instead |
1701 sprintf(tmpresult, "%s%s", f_dir, de->d_name); | 1691 prio = 2; |
1702 if ((f = fopen(tmpresult, "rt"))) { | |
1703 fclose(f); | |
1704 result[subcnt].priority = 2; | |
1705 result[subcnt].fname = strdup(tmpresult); | |
1706 subcnt++; | |
1707 } | |
1708 } | 1692 } |
1709 } else { | 1693 } else { |
1710 // doesn't contain the movie name | 1694 // doesn't contain the movie name |
1711 // don't try in the mplayer subtitle directory | 1695 // don't try in the mplayer subtitle directory |
1712 if ((j == 0) && (sub_match_fuzziness >= 2)) { | 1696 if ((j == 0) && (sub_match_fuzziness >= 2)) { |
1713 sprintf(tmpresult, "%s%s", f_dir, de->d_name); | 1697 prio = 1; |
1714 if ((f = fopen(tmpresult, "rt"))) { | |
1715 fclose(f); | |
1716 result[subcnt].priority = 1; | |
1717 result[subcnt].fname = strdup(tmpresult); | |
1718 subcnt++; | |
1719 } | |
1720 } | 1698 } |
1721 } | 1699 } |
1700 | |
1701 if (prio) { | |
1702 sprintf(tmpresult, "%s%s", f_dir, de->d_name); | |
1703 // fprintf(stderr, "%s priority %d\n", tmpresult, prio); | |
1704 if ((f = fopen(tmpresult, "rt"))) { | |
1705 fclose(f); | |
1706 result[subcnt].priority = prio; | |
1707 result[subcnt].fname = strdup(tmpresult); | |
1708 subcnt++; | |
1709 } | |
1710 } | |
1711 | |
1722 } | 1712 } |
1723 if (subcnt >= MAX_SUBTITLE_FILES) break; | 1713 if (subcnt >= MAX_SUBTITLE_FILES) break; |
1724 } | 1714 } |
1725 closedir(d); | 1715 closedir(d); |
1726 } | 1716 } |