Пример #1
0
Tsubtitle* TsubtitleParserAqt::parse(Tstream &fd, int flags, REFERENCE_TIME, REFERENCE_TIME)
{
    wchar_t line[this->LINE_LEN + 1];
    const wchar_t *next;
    //int i;

    long start;
    while (1) {
        // try to locate next subtitle
        if (!fd.fgets(line, this->LINE_LEN)) {
            return NULL;
        }
        if (!(swscanf(line, L"-->> %ld", &start) < 1)) {
            break;
        }
    }
    TsubtitleText current(this->format);
    current.start = this->frameToTime(start);
    if (previous != NULL) {
        previous->stop = current.start - 1;
    }

    //previous_aqt_sub = current;

    if (!fd.fgets(line, this->LINE_LEN)) {
        return NULL;
    }

    sub_readtext(line, current);
    current.stop = current.start; // will be corrected by next subtitle

    if (!fd.fgets(line, this->LINE_LEN)) {
        return previous = store(current);
    }

    next = line;//,i=1;
    while ((next = sub_readtext(next, current)) != NULL) {
        ;
    }

    if (current.at(0)[0] == '\0' && current.at(1)[0] == '\0') {
        // void subtitle -> end of previous marked and exit
        previous = NULL;
        return NULL;
    }

    return previous = store(current);
}
Пример #2
0
Tsubtitle* TsubtitleParserRt::parse(Tstream &fd, int flags, REFERENCE_TIME start, REFERENCE_TIME stop)
{
    //TODO: This format uses quite rich (sub/super)set of xhtml
    // I couldn't check it since DTD is not included.
    // WARNING: full XML parses can be required for proper parsing
    wchar_t line[this->LINE_LEN + 1];
    int a1, a2, a3, a4, b1, b2, b3, b4;
    const wchar_t *p = NULL, *next = NULL;
    int plen;
    TsubtitleText current(this->format);
    while (current.empty()) {
        if (!fd.fgets(line, this->LINE_LEN)) {
            return NULL;
        }
        //TODO: it seems that format of time is not easily determined, it may be 1:12, 1:12.0 or 0:1:12.0
        //to describe the same moment in time. Maybe there are even more formats in use.
        //if ((len=wsscanf (line, L"<Time Begin=\"%d:%d:%d.%d\" End=\"%d:%d:%d.%d\"",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8)
        plen = a1 = a2 = a3 = a4 = b1 = b2 = b3 = b4 = 0;
        if (
            (swscanf(line, L"<%*[tT]ime %*[bB]egin=\"%d.%d\" %*[Ee]nd=\"%d.%d\"%*[^<]<clear/>%n", &a3, &a4, &b3, &b4, &plen) < 4) &&
            (swscanf(line, L"<%*[tT]ime %*[bB]egin=\"%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n", &a3, &a4, &b2, &b3, &b4, &plen) < 5) &&
            (swscanf(line, L"<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n", &a2, &a3, &b2, &b3, &plen) < 4) &&
            (swscanf(line, L"<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n", &a2, &a3, &b2, &b3, &b4, &plen) < 5) &&
            //      (swscanf(line, L"<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&plen) < 5) &&
            (swscanf(line, L"<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n", &a2, &a3, &a4, &b2, &b3, &b4, &plen) < 6) &&
            (swscanf(line, L"<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\" %*[Ee]nd=\"%d:%d:%d.%d\"%*[^<]<clear/>%n", &a1, &a2, &a3, &a4, &b1, &b2, &b3, &b4, &plen) < 8) &&
            //now try it without end time
            (swscanf(line, L"<%*[tT]ime %*[bB]egin=\"%d.%d\"%*[^<]<clear/>%n", &a3, &a4, &plen) < 2) &&
            (swscanf(line, L"<%*[tT]ime %*[bB]egin=\"%d:%d\"%*[^<]<clear/>%n", &a2, &a3, &plen) < 2) &&
            (swscanf(line, L"<%*[tT]ime %*[bB]egin=\"%d:%d.%d\"%*[^<]<clear/>%n", &a2, &a3, &a4, &plen) < 3) &&
            (swscanf(line, L"<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\"%*[^<]<clear/>%n", &a1, &a2, &a3, &a4, &plen) < 4)
        ) {
            continue;
        }
        current.start = this->hmsToTime(a1, a2, a3, a4);
        current.stop  = this->hmsToTime(a1, a2, a3, a4);
        if (b1 == 0 && b2 == 0 && b3 == 0 && b4 == 0) {
            current.stop = current.start + this->frameToTime(200);
        }
        p = line;
        p += plen;
        // TODO: I don't know what kind of convention is here for marking multiline subs, maybe <br/> like in xml?
        next = strstr(line, L"<clear/>");
        if (next && strlen(next) > 8) {
            next += 8;
            while ((next = sub_readtext(next, current)) != NULL) {
                ;
            }
        }
    }

    return store(current);
}
Пример #3
0
static subtitle *set_multiline_text(struct readline_args *arg, subtitle *current,
                                    const char *text, int start)
{
    int i = start;
    while ((text = sub_readtext(text, current->text + i))) {
        if (current->text[i] == ERR) return ERR;
        i++;
        if (i >= SUB_MAX_TEXT) {
            MP_WARN(arg, "Too many lines in a subtitle\n");
            current->lines = i;
            return current;
        }
    }
    current->lines = i + 1;
    return current;
}
Пример #4
0
Tsubtitle* TsubtitleParserVplayer::parse(Tstream &fd, int flags, REFERENCE_TIME start, REFERENCE_TIME stop)
{
    wchar_t line[this->LINE_LEN + 1];
    int a1, a2, a3, a4;
    const wchar_t *p = NULL, *next;
    wchar_t separator1;//,separator2;
    int plen;
    TsubtitleText current(this->format);
    while (current.empty()) {
        if (!fd.fgets(line, this->LINE_LEN)) {
            return NULL;
        }
        int ret;

        //KD. Comments this, a never see vplayer sub with decimal fraction of second. Is this standard?
        //Also this incorrect display:
        //00:00:01:7weeks ago
        //sub to display is "7weeks ago" not "eeks ago". 7 is text not decisecund

        //ret=swscanf(line, L"%d:%d:%d%c%d%c%n",&a1,&a2,&a3,&separator1,&a4,&separator2,&plen);
        //if (ret!=6)
        // {
        a4 = 0;
        ret = swscanf(line, L"%d:%d:%d%c%n", &a1, &a2, &a3, &separator1, &plen);
        if (ret != 4) {
            continue;
        }
        // }

        if ((current.start = this->hmsToTime(a1, a2, a3, a4 * 10)) == NULL) {
            continue;
        }

        //by wodzu fast finds the body of the subtitle
        p = &line[ plen ];

        if (*p != '|') {
            next = p;
            while ((next = sub_readtext(next, current)) != NULL) {
                ;
            }
        }
    }

    return store(current);
}
Пример #5
0
Tsubtitle* TsubtitleParserSubrip09::parse(Tstream &fd, int flags, REFERENCE_TIME start, REFERENCE_TIME stop)
{
    wchar_t line[this->LINE_LEN + 1];
    int a1, a2, a3;
    const wchar_t * next = NULL;
    int i;

    while (1) {
        // try to locate next subtitle
        if (!fd.fgets(line, this->LINE_LEN)) {
            return NULL;
        }
        if (!(swscanf(line, L"[%d:%d:%d]", &a1, &a2, &a3) < 3)) {
            break;
        }
    }
    TsubtitleText current(this->format);
    current.start = this->hmsToTime(a1, a2, a3);
    if (previous != NULL) {
        previous->stop = current.start - 1;
    }

    if (!fd.fgets(line, this->LINE_LEN)) {
        return NULL;
    }

    next = line;
    i = 0;

    //(*current)[0]=""; // just to be sure that string is clear

    while ((next = sub_readtext(next, current)) != NULL) {
        i++;
    }

    if (current.size() == 0 || (current.at(0)[0] == '\0') && (i == 0)) {
        // void subtitle -> end of previous marked and exit
        previous = NULL;
        return NULL;
    }

    return previous = store(current);
}
Пример #6
0
Tsubtitle* TsubtitleParserMicrodvd::parse(Tstream &fd, int flags, REFERENCE_TIME, REFERENCE_TIME)
{
    wchar_t line[this->LINE_LEN + 1];
    wchar_t line2[this->LINE_LEN + 1];
    const wchar_t *p, *next;

    int start = 0, stop = 0;
    bool skip;
    do {
        do {
            if (!fd.fgets(line, this->LINE_LEN)) {
                return NULL;
            }
        } while ((swscanf(line,
                          L"{%ld}{}%[^\r\n]",
                          &start, line2) < 2) &&
                 (swscanf(line,
                          L"{%ld}{%ld}%[^\r\n]",
                          &start, &stop, line2) < 3));
        skip = false;
        if (start == 1 && stop == 1) {
            wchar_t *e;
            double newfps;
            if ((newfps = strtod(line2, &e)) > 0 && !*e) {
                this->fps = newfps;
                skip = true;
            }
        }
    } while (skip);

    TsubtitleText current(this->format);
    current.start = this->frameToTime(start);
    current.stop = this->frameToTime(stop);

    p = line2;

    next = p;
    while ((next = sub_readtext(next, current)) != NULL) {
        ;
    }
    return store(current);
}
Пример #7
0
static subtitle *sub_read_line_aqt(stream_t *st,subtitle *current,
                                   struct readline_args *args)
{
    int utf16 = args->utf16;
    char line[LINE_LEN+1];

retry:
    while (1) {
    // try to locate next subtitle
        if (!stream_read_line (st, line, LINE_LEN, utf16))
		return NULL;
        if (!(sscanf (line, "-->> %ld", &(current->start)) <1))
		break;
    }

    if (!args->previous_sub_end)
    args->previous_sub_end = (current->start) ? current->start - 1 : 0;

    if (!stream_read_line (st, line, LINE_LEN, utf16))
	return NULL;

    sub_readtext((char *) &line,&current->text[0]);
    current->lines = 1;
    current->end = current->start; // will be corrected by next subtitle

    if (!stream_read_line (st, line, LINE_LEN, utf16))
	return current;

    if (set_multiline_text(args, current, line, 1) == ERR)
        return ERR;

    if (!strlen(current->text[0]) && !strlen(current->text[1]))
	goto retry;

    return current;
}
Пример #8
0
Tsubtitle* TsubtitleParserMPL2::parse(Tstream &fd, int flags, REFERENCE_TIME, REFERENCE_TIME)
{
    wchar_t line[this->LINE_LEN + 1];
    wchar_t line2[this->LINE_LEN + 1];
    const wchar_t *p, *next;
    int start = 0, end = 0;

    do {
        if (!fd.fgets(line, this->LINE_LEN)) {
            return NULL;
        }
    } while (swscanf(line,
                     L"[%ld][%ld]%[^\r\n]",
                     &start, &end, line2) < 3);
    TsubtitleText current(this->format);
    current.start = (REFERENCE_TIME)start * 1000000;
    current.stop = (REFERENCE_TIME)end * 1000000;
    p = line2;
    next = p;
    while ((next = sub_readtext(next, current)) != NULL) {
        ;
    }
    return store(current);
}