Mercurial > mplayer.hg
changeset 624:44b764d348a0
added support for SAMI subtitle support (.smi)
author | laaz |
---|---|
date | Tue, 24 Apr 2001 21:39:18 +0000 |
parents | 950e2d2613e3 |
children | 2f321fe55bdb |
files | subreader.c subreader.h |
diffstat | 2 files changed, 70 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/subreader.c Tue Apr 24 20:38:41 2001 +0000 +++ b/subreader.c Tue Apr 24 21:39:18 2001 +0000 @@ -17,8 +17,60 @@ int sub_uses_time=0; int sub_errs=0; -int sub_num=0; // number of subtitle structs -int sub_format=-1; // 0 for microdvd, 1 for SubRip, 2 for the third format +int sub_num=0; // number of subtitle structs +int sub_format=-1; // 0 for microdvd + // 1 for SubRip + // 2 for the third format (what's this?) + // 3 for SAMI (smi) + +int eol(char p) { + return (p=='\r' || p=='\n' || p=='\0'); +} + + +subtitle *sub_read_line_sami(FILE *fd, subtitle *current) { + char line[1001]; + int i; + char *s, *p; + + current->start=0; + do { + if (! (fgets (line, 1000, fd))) return 0; + s= strstr(line, "Start="); + if (s) { + sscanf (s, "Start=%d", ¤t->start); + if (strstr (s, "<P><br>")) current->start=0; + } + } while ( !current->start ); + + if (! (fgets (line, 1000, fd))) return 0; + s=strstr (line, "<P>")+3; + + i=0; + do { + for (p=s; !eol(*p) && strncmp(p,"<br>",4); p++); + if (p==s) { + s+=4; + continue; + } + current->text[i]=(char *)malloc(p-s+1); + strncpy (current->text[i], s, p-s); + current->text[i++][p-s]='\0'; + if (!strncmp(p,"<br>",4)) s=p+4; + else s=p; + } while (!eol (*p)); + + current->lines=i; + + if (! (fgets (line, 1000, fd))) return 0; + s= strstr(line, "Start="); + if (s) { + sscanf (s, "Start=%d", ¤t->end); + if (!strstr (s, "<P><br>")) return ERR; + } else return ERR; + + return current; +} char *sub_readtext(char *source, char **dest) { @@ -39,8 +91,6 @@ else return NULL; // last text field } - - subtitle *sub_read_line_microdvd(FILE *fd,subtitle *current) { char line[1001]; char line2[1001]; @@ -138,20 +188,22 @@ int i,j=0; // char *p; - while (1) { + while (j < 100) { j++; if (!fgets (line, 1000, fd)) return -1; -// if (sscanf (line, "{%i}{%i}", &i, &i, p)==2) // ha valaki tudja miert 2, mondja mar el nekem ;) - if (sscanf (line, "{%d}{%d}", &i, &i)==2) // ha valaki tudja miert 2, mondja mar el nekem ;) + if (sscanf (line, "{%d}{%d}", &i, &i)==2) {sub_uses_time=0;return 0;} if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d", &i, &i, &i, &i, &i, &i, &i, &i)==8) {sub_uses_time=1;return 1;} if (sscanf (line, "%d:%d:%d,%d --> %d:%d:%d,%d", &i, &i, &i, &i, &i, &i, &i, &i)==8) {sub_uses_time=1;return 2;} - if (j>100) return -1; // too many bad lines or bad coder + if (strstr (line, "<SAMI>")) + {sub_uses_time=0; return 3;} } + + return -1; // too many bad lines } @@ -159,18 +211,19 @@ FILE *fd; int n_max; subtitle *first; - subtitle * (*func[3])(FILE *fd,subtitle *dest)= + subtitle * (*func[4])(FILE *fd,subtitle *dest)= { sub_read_line_microdvd, sub_read_line_subrip, - sub_read_line_third + sub_read_line_third, + sub_read_line_sami }; fd=fopen (filename, "r"); if (!fd) return NULL; sub_format=sub_autodetect (fd); if (sub_format==-1) {printf ("SUB: Could not determine file format\n");return NULL;} - printf ("SUB: Detected subtitle file format: %i\n",sub_format); + printf ("SUB: Detected subtitle file format: %d\n",sub_format); rewind (fd); @@ -193,7 +246,7 @@ // printf ("SUB: Subtitle format %s time.\n", sub_uses_time?"uses":"doesn't use"); printf ("SUB: Read %i subtitles", sub_num); - if (sub_errs) printf (", %i error(s).\n", sub_errs); + if (sub_errs) printf (", %i bad line(s).\n", sub_errs); else printf (".\n"); return first; @@ -247,7 +300,6 @@ return NULL; } -#if 0 int main(int argc, char **argv) { // for testing int i,j; @@ -259,7 +311,7 @@ exit(1); } - subs=sub_get_subtitles(argv[1]); + subs=sub_read_file(argv[1]); if(!subs){ printf("Couldn't load file... let's write a bugreport :)\n"); exit(1); @@ -282,4 +334,3 @@ printf ("Read %i subtitles, %i errors.\n", sub_num, sub_errs); return 0; } -#endif
--- a/subreader.h Tue Apr 24 20:38:41 2001 +0000 +++ b/subreader.h Tue Apr 24 21:39:18 2001 +0000 @@ -5,7 +5,10 @@ extern int sub_uses_time; extern int sub_errs; extern int sub_num; // number of subtitle structs -extern int sub_format; // 0 for microdvd, 1 for SubRip, 2 for the third format +extern int sub_format; // 0 for microdvd + // 1 for SubRip + // 2 for the third format + // 3 for SAMI (smi) #define SUB_MAX_TEXT 5