diff --git a/subreader.c b/subreader.c index ef5f7e1bb4..5c8f67bc48 100644 --- a/subreader.c +++ b/subreader.c @@ -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, "
")) current->start=0;
+ }
+ } while ( !current->start );
+
+ if (! (fgets (line, 1000, fd))) return 0;
+ s=strstr (line, "
")+3;
+
+ i=0;
+ do {
+ for (p=s; !eol(*p) && strncmp(p,"
",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,"
",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, "
")) return ERR;
+ } else return ERR;
+
+ return current;
+}
char *sub_readtext(char *source, char **dest) {
@@ -39,8 +91,6 @@ char *sub_readtext(char *source, char **dest) {
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 sub_autodetect (FILE *fd) {
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, "