<commit_before>"use strict";

module SamiTS {
    export interface SubRipWriterOptions {
        useTextStyles?: boolean
    }

    export class SubRipWriter {
        write(xsyncs: SAMICue[], options: SubRipWriterOptions = {}) {
            let subDocument = "";
            let writeText = (i: number, syncindex: number, text: string) => {
                subDocument += syncindex.toString();
                subDocument += "\r\n" + this.getSubRipTime(parseInt(xsyncs[i].syncElement.getAttribute("start"))) + " --> " + this.getSubRipTime(parseInt(xsyncs[i + 1].syncElement.getAttribute("start")));
                subDocument += "\r\n" + text;
            };
            options = util.assign<any>(<DOMReadOptionBag>{ preventEmptyLine: true }, options);

            var text: string;
            if (xsyncs.length > 0) {
                let syncindex = 1;
                let readElement = (options.useTextStyles ? this.readElementRich : this.readElementSimple).bind(this);

                for (let i = 0; i < xsyncs.length - 1; i++) {
                    text = util.absorbAir(xsyncs[i].readDOM(readElement, options));
                    if (text.length > 0) {
                        if (syncindex > 1)
                            subDocument += "\r\n\r\n";
                        writeText(i, syncindex, text);
                        syncindex++;
                    }
                }
            }
            return <SamiTSResult>{ subtitle: subDocument };
        }

        private getSubRipTime(ms: number) {
            let hour = (ms - ms % 3600000) / 3600000;
            ms -= hour * 3600000;
            let min = (ms - ms % 60000) / 60000;
            ms -= min * 60000;
            let sec = (ms - ms % 1000) / 1000;
            ms -= sec * 1000;
            let hourstr = hour.toString();
            if (hourstr.length < 2) hourstr = '0' + hourstr;
            let minstr = min.toString();
            if (minstr.length < 2) minstr = '0' + minstr;
            let secstr = sec.toString();
            if (secstr.length < 2) secstr = '0' + secstr;
            let msstr = ms.toString();
            while (msstr.length < 3) msstr = '0' + msstr;
            return hourstr + ':' + minstr + ':' + secstr + ',' + msstr;
        }

        private readElementSimple(element: SAMISyncElement) {
            let template = util.generateTagReadResultTemplate();
            switch (element.tagName.toLowerCase()) {
                case "p":
                    template.divides = true;
                    break;
                case "br":
                    template.linebreak = true;
                    break;
            }
            return template;
        }

        private readElementRich(element: SAMISyncElement) {
            let template = util.generateTagReadResultTemplate();
            switch (element.tagName.toLowerCase()) {
                case "p":
                    template.divides = true;
                    break;
                case "br":
                    template.linebreak = true;
                    break;
                case "font":
                    let fontelement = document.createElement("font");
                    let color = element.getAttribute("color");
                    if (color) fontelement.setAttribute("color", color);<commit_msg>template for subripwriter<commit_after>"use strict";

module SamiTS {
    export interface SubRipWriterOptions {
        useTextStyles?: boolean
    }

    export class SubRipWriter {
        write(xsyncs: SAMICue[], options: SubRipWriterOptions = {}) {
            let subDocument = "";
            let writeText = (i: number, syncindex: number, text: string) => {
                subDocument += syncindex.toString();
                subDocument += "\r\n" + this.getSubRipTime(parseInt(xsyncs[i].syncElement.getAttribute("start"))) + " --> " + this.getSubRipTime(parseInt(xsyncs[i + 1].syncElement.getAttribute("start")));
                subDocument += "\r\n" + text;
            };
            options = util.assign<any>(<DOMReadOptionBag>{ preventEmptyLine: true }, options);

            var text: string;
            if (xsyncs.length > 0) {
                let syncindex = 1;
                let readElement = (options.useTextStyles ? this.readElementRich : this.readElementSimple).bind(this);

                for (let i = 0; i < xsyncs.length - 1; i++) {
                    text = util.absorbAir(xsyncs[i].readDOM(readElement, options));
                    if (text.length > 0) {
                        if (syncindex > 1)
                            subDocument += "\r\n\r\n";
                        writeText(i, syncindex, text);
                        syncindex++;
                    }
                }
            }
            return <SamiTSResult>{ subtitle: subDocument };
        }

        private getSubRipTime(ms: number) {
            let hour = (ms - ms % 3600000) / 3600000;
            ms -= hour * 3600000;
            let min = (ms - ms % 60000) / 60000;
            ms -= min * 60000;
            let sec = (ms - ms % 1000) / 1000;
            ms -= sec * 1000;
            let hourstr = hour.toString();
            if (hourstr.length < 2) hourstr = '0' + hourstr;
            let minstr = min.toString();
            if (minstr.length < 2) minstr = '0' + minstr;
            let secstr = sec.toString();
            if (secstr.length < 2) secstr = '0' + secstr;
            let msstr = ms.toString();
            while (msstr.length < 3) msstr = '0' + msstr;
            return `${hourstr}:${minstr}:${secstr},${msstr}`;
        }

        private readElementSimple(element: SAMISyncElement) {
            let template = util.generateTagReadResultTemplate();
            switch (element.tagName.toLowerCase()) {
                case "p":
                    template.divides = true;
                    break;
                case "br":
                    template.linebreak = true;
                    break;
            }
            return template;
        }

        private readElementRich(element: SAMISyncElement) {
            let template = util.generateTagReadResultTemplate();
            switch (element.tagName.toLowerCase()) {
                case "p":
                    template.divides = true;
                    break;
                case "br":
                    template.linebreak = true;
                    break;
                case "font":
                    let fontelement = document.createElement("font");
                    let color = element.getAttribute("color");
                    if (color) fontelement.setAttribute("color", color);
{'fraction_non_alphanumeric': 0.11691842900302114, 'fraction_numerical': 0.019033232628398792, 'mean_word_length': 1.427942794279428, 'pattern_counts': {'":': 10, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '320959', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1728, 'n_words': 404}