示例#1
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (var s in lines)
            {
                sb.Append(s);
            }

            var text = sb.ToString().TrimStart();

            if (!text.Contains("\"segs\"", StringComparison.Ordinal) || !text.Contains('['))
            {
                return;
            }

            var parser   = new SeJsonParser();
            var elements = parser.GetArrayElements(text.Substring(text.IndexOf('[')));

            foreach (var element in elements)
            {
                var startTimeObject    = parser.GetFirstObject(element, "tStartMs");
                var durationTimeObject = parser.GetFirstObject(element, "dDurationMs");
                var idx = element.IndexOf('[');
                var s   = string.Empty;
                if (idx > 0)
                {
                    sb = new StringBuilder();
                    var arr = parser.GetArrayElements(element.Substring(idx));
                    foreach (var line in arr)
                    {
                        var content = parser.GetFirstObject(line, "utf8");
                        if (content != null)
                        {
                            sb.Append(content.Replace("\\n", Environment.NewLine) + " ");
                        }
                    }
                    s = sb.ToString().Trim();

                    if (!string.IsNullOrEmpty(s) && !string.IsNullOrEmpty(startTimeObject) && !string.IsNullOrEmpty(durationTimeObject))
                    {
                        if (double.TryParse(startTimeObject, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var startMs) &&
                            double.TryParse(durationTimeObject, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var durationMs))
                        {
                            var pText = Json.DecodeJsonText(s);
                            var p     = new Paragraph(pText, startMs, startMs + durationMs);
                            subtitle.Paragraphs.Add(p);
                        }
                        else
                        {
                            _errorCount++;
                        }
                    }
                }
            }
            subtitle.Renumber();
        }
示例#2
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }

            string allText        = sb.ToString();
            var    indexOfMainTag = allText.IndexOf("\"SubtitleLanguages\"", StringComparison.Ordinal);

            if (indexOfMainTag < 0)
            {
                return;
            }

            var startIndex = allText.Remove(indexOfMainTag).LastIndexOf('{');

            if (startIndex < 0)
            {
                return;
            }

            var json   = allText.Substring(startIndex);
            var parser = new SeJsonParser();
            var items  = parser.GetArrayElementsByName(json, "SubtitleItems");

            foreach (var item in items)
            {
                var textLines = parser.GetArrayElementsByName(item, "TextLines");
                var showTime  = parser.GetAllTagsByNameAsStrings(item, "ShowTime");
                var hideTime  = parser.GetAllTagsByNameAsStrings(item, "HideTime");
                if (textLines.Count > 0 && showTime.Count == 1 && hideTime.Count == 1 && long.TryParse(showTime[0], out var startMs) && long.TryParse(hideTime[0], out var endMs))
                {
                    var text = new StringBuilder();
                    foreach (var line in textLines)
                    {
                        text.AppendLine(Json.DecodeJsonText(line));
                    }

                    var p         = new Paragraph(text.ToString().Trim(), startMs, endMs);
                    var className = parser.GetAllTagsByNameAsStrings(item, "ClassName");
                    if (className.Count == 1)
                    {
                        p.Language = className[0];
                    }

                    subtitle.Paragraphs.Add(p);
                }
            }

            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
示例#3
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;
            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }
            var allText = sb.ToString().Trim();

            if (!allText.StartsWith("[", StringComparison.Ordinal) || !allText.Contains("\"start\""))
            {
                return;
            }

            foreach (var line in Json.ReadObjectArray(allText))
            {
                var s = line.Trim();
                if (s.Length > 10)
                {
                    var start = Json.ReadTag(s, "start");
                    var end   = Json.ReadTag(s, "end");
                    //var textLines = Json.ReadArray(s, "text");
                    var textLines     = Json.ReadTag(s, "text");
                    var horizontal    = Json.ReadTag(s, "horizontal");
                    var vertical      = Json.ReadTag(s, "vertical");
                    var justification = Json.ReadTag(s, "justification");
                    try
                    {
                        //if (textLines.Count == 0)
                        //{
                        //    _errorCount++;
                        //}
                        //sb.Clear();
                        //foreach (var textLine in textLines)
                        //{
                        //    sb.AppendLine(Json.DecodeJsonText(textLine));
                        //}

                        sb.Clear();
                        sb.AppendLine((Json.DecodeJsonText(textLines)).Replace("\n", Environment.NewLine).Replace("<br/>", Environment.NewLine).Replace("<br/>", Environment.NewLine));
                        //subtitle.Paragraphs.Add(new Paragraph(sb.ToString().Trim(), TimeCode.ParseToMilliseconds(start), TimeCode.ParseToMilliseconds(end)));
                        subtitle.Paragraphs.Add(new Paragraph(sb.ToString().Trim(), TimeCode.ParseToMilliseconds(start), TimeCode.ParseToMilliseconds(end), horizontal.Trim(), vertical.Trim(), justification.Trim()));
                    }
                    catch (Exception)
                    {
                        _errorCount++;
                    }
                }
            }
            subtitle.Renumber();
        }
示例#4
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }

            string allLines = sb.ToString();

            if (!allLines.Contains("\"subtitles\":", StringComparison.Ordinal))
            {
                return;
            }

            foreach (string line in sb.ToString().Replace("},{", Environment.NewLine).SplitToLines())
            {
                string s     = line.Trim() + "}";
                string start = Json.ReadTag(s, "start");
                string end   = Json.ReadTag(s, "end");
                string text  = Json.ReadTag(s, "text");
                string extra = Json.ReadTag(s, "comment");
                if (start != null && end != null && text != null)
                {
                    double startMilliseconds;
                    double endMilliseconds;
                    if (double.TryParse(start, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out startMilliseconds) &&
                        double.TryParse(end, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out endMilliseconds))
                    {
                        var p = new Paragraph(Json.DecodeJsonText(text), startMilliseconds, endMilliseconds);
                        if (!string.IsNullOrEmpty(extra))
                        {
                            p.Extra = extra;
                        }

                        subtitle.Paragraphs.Add(p);
                    }
                    else
                    {
                        _errorCount++;
                    }
                }
                else
                {
                    _errorCount++;
                }
            }
            subtitle.Renumber();
        }
示例#5
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }

            if (!sb.ToString().TrimStart().StartsWith("[{\"", StringComparison.Ordinal))
            {
                return;
            }

            foreach (string line in sb.ToString().Replace("},{", Environment.NewLine).SplitToLines())
            {
                string s     = line.Trim() + "}";
                string start = Json.ReadTag(s, "displayTimeOffset");
                string text  = Json.ReadTag(s, "text");
                if (start != null && text != null)
                {
                    double startSeconds;
                    if (double.TryParse(start, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out startSeconds))
                    {
                        var endMs = Utilities.GetOptimalDisplayMilliseconds(text) + startSeconds * 1000.0;
                        subtitle.Paragraphs.Add(new Paragraph(Json.DecodeJsonText(text), startSeconds * 1000.0, endMs));
                    }
                    else
                    {
                        _errorCount++;
                    }
                }
                else
                {
                    _errorCount++;
                }
            }

            for (int i = 0; i < subtitle.Paragraphs.Count - 1; i++)
            {
                var paragraph = subtitle.Paragraphs[i];
                var next      = subtitle.GetParagraphOrDefault(i + 1);
                if (next.StartTime.TotalMilliseconds < paragraph.EndTime.TotalMilliseconds)
                {
                    paragraph.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
                }
            }
            subtitle.Renumber();
        }
示例#6
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;
            var sb = new StringBuilder();

            foreach (var s in lines)
            {
                sb.Append(s);
            }

            var allText = sb.ToString().Trim();

            if (!allText.StartsWith("[", StringComparison.Ordinal) || !allText.Contains("\"start\""))
            {
                return;
            }

            foreach (var line in Json.ReadObjectArray(allText))
            {
                var s = line.Trim();
                if (s.Length > 10)
                {
                    var start     = Json.ReadTag(s, "start");
                    var end       = Json.ReadTag(s, "end");
                    var textLines = Json.ReadArray(s, "text");
                    try
                    {
                        if (textLines.Count == 0)
                        {
                            _errorCount++;
                        }
                        sb.Clear();
                        foreach (var textLine in textLines)
                        {
                            sb.AppendLine(Json.DecodeJsonText(textLine));
                        }
                        var startArr = start.Split(new[] { ':', ',', '.' }, StringSplitOptions.RemoveEmptyEntries);
                        var endArr   = end.Split(new[] { ':', ',', '.' }, StringSplitOptions.RemoveEmptyEntries);
                        if (startArr.Length == 4 && endArr.Length == 4)
                        {
                            subtitle.Paragraphs.Add(new Paragraph(sb.ToString().Trim(), TimeCode.ParseToMilliseconds(start), TimeCode.ParseToMilliseconds(end)));
                        }
                    }
                    catch (Exception)
                    {
                        _errorCount++;
                    }
                }
            }
            subtitle.Renumber();
        }
示例#7
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }
            if (!sb.ToString().TrimStart().StartsWith("[{\"", StringComparison.Ordinal))
            {
                return;
            }

            foreach (string line in sb.ToString().Replace("},{", Environment.NewLine).SplitToLines())
            {
                string s     = line.Trim() + "}";
                string start = Json.ReadTag(s, "start_millis");
                string end   = Json.ReadTag(s, "end_millis");
                string start_of_paragraph = Json.ReadTag(s, "start_of_paragraph");
                string start_of_statement = Json.ReadTag(s, "start_of_statement");
                string isolate_mean       = Json.ReadTag(s, "isolate_mean");
                string end_of_statement   = Json.ReadTag(s, "end_of_statement");
                string end_of_paragraph   = Json.ReadTag(s, "end_of_paragraph");
                string text = Json.ReadTag(s, "text");
                if (start != null && end != null && text != null)
                {
                    double startSeconds;
                    double endSeconds;
                    if (double.TryParse(start, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out startSeconds) &&
                        double.TryParse(end, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out endSeconds))
                    {
                        subtitle.Paragraphs.Add(new Paragraph(Json.DecodeJsonText(text), startSeconds, endSeconds, Convert.ToBoolean(start_of_paragraph), Convert.ToBoolean(start_of_statement)
                                                              , Convert.ToBoolean(isolate_mean), Convert.ToBoolean(end_of_statement), Convert.ToBoolean(end_of_paragraph)));
                    }
                    else
                    {
                        _errorCount++;
                    }
                }
                else
                {
                    _errorCount++;
                }
            }
            subtitle.Renumber();
        }
示例#8
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }

            int startIndex = sb.ToString().IndexOf("[{\"hitType", StringComparison.Ordinal);

            if (startIndex < 0)
            {
                return;
            }

            string text = sb.ToString().Substring(startIndex);

            foreach (string line in text.Replace("},{", Environment.NewLine).SplitToLines())
            {
                string s       = line.Trim() + "}";
                string start   = Json.ReadTag(s, "startTime");
                string end     = Json.ReadTag(s, "endTime");
                string content = Json.ReadTag(s, "Text");
                if (start != null && end != null && content != null)
                {
                    double startSeconds;
                    double endSeconds;
                    if (double.TryParse(start, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out startSeconds) &&
                        double.TryParse(end, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out endSeconds))
                    {
                        subtitle.Paragraphs.Add(new Paragraph(Json.DecodeJsonText(content), startSeconds * TimeCode.BaseUnit, endSeconds * TimeCode.BaseUnit));
                    }
                    else
                    {
                        _errorCount++;
                    }
                }
                else
                {
                    _errorCount++;
                }
            }
            subtitle.Renumber();
        }
示例#9
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }

            var text       = sb.ToString();
            int startIndex = text.IndexOf("[{\"", StringComparison.Ordinal);

            if (startIndex < 0 || text.Contains("\"captions\"", StringComparison.Ordinal))
            {
                return;
            }

            text = text.Substring(startIndex);
            foreach (string line in text.Replace("},{", Environment.NewLine).SplitToLines())
            {
                string s        = line.Trim() + "}";
                string start    = Json.ReadTag(s, "startTime");
                string duration = Json.ReadTag(s, "duration");
                string content  = Json.ReadTag(s, "content");
                if (start != null && duration != null && content != null)
                {
                    double startSeconds;
                    double durationSeconds;
                    if (double.TryParse(start, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out startSeconds) &&
                        double.TryParse(duration, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out durationSeconds))
                    {
                        subtitle.Paragraphs.Add(new Paragraph(Json.DecodeJsonText(content), startSeconds, startSeconds + durationSeconds));
                    }
                    else
                    {
                        _errorCount++;
                    }
                }
                else
                {
                    _errorCount++;
                }
            }
            subtitle.Renumber();
        }
示例#10
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;
            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }

            string allText = sb.ToString().Trim();

            if (!(allText.StartsWith("{", StringComparison.Ordinal) || allText.StartsWith("[", StringComparison.Ordinal)))
            {
                return;
            }

            foreach (string line in allText.Split('{', '}', '[', ']'))
            {
                string s = line.Trim();
                if (s.Length > 10)
                {
                    string start = Json.ReadTag(s, "start_time");
                    string end   = Json.ReadTag(s, "end_time");
                    string text  = Json.ReadTag(s, "text");
                    if (start != null && end != null && text != null)
                    {
                        double startMs;
                        double endMs;
                        if (double.TryParse(start, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out startMs) &&
                            double.TryParse(end, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out endMs))
                        {
                            subtitle.Paragraphs.Add(new Paragraph(Json.DecodeJsonText(text), startMs, endMs));
                        }
                        else
                        {
                            _errorCount++;
                        }
                    }
                    else
                    {
                        _errorCount++;
                    }
                }
            }
            subtitle.Renumber();
        }
示例#11
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;
            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }

            string allText = sb.ToString().Trim();

            if (!(allText.StartsWith("[", StringComparison.Ordinal) && allText.Contains("milliseconds", StringComparison.Ordinal)))
            {
                return;
            }

            foreach (string line in allText.Split('{', '}', '[', ']'))
            {
                string s = line.Trim();
                if (s.Length > 10)
                {
                    string start = Json.ReadTag(s, "milliseconds");
                    string text  = Json.ReadTag(s, "line");
                    if (start != null && text != null)
                    {
                        double startMilliseconds;
                        if (double.TryParse(start, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out startMilliseconds))
                        {
                            var duration        = Utilities.GetOptimalDisplayMilliseconds(text);
                            var endMilliseconds = startMilliseconds + duration;
                            subtitle.Paragraphs.Add(new Paragraph(Json.DecodeJsonText(text), startMilliseconds, endMilliseconds));
                        }
                        else
                        {
                            _errorCount++;
                        }
                    }
                    else
                    {
                        _errorCount++;
                    }
                }
            }
            subtitle.Renumber();
        }
示例#12
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (var s in lines)
            {
                sb.Append(s);
            }

            var text = sb.ToString().TrimStart();

            if (text.IndexOf("atpjfile_info", StringComparison.Ordinal) < 0)
            {
                return;
            }

            subtitle.Paragraphs.Clear();
            var parser   = new SeJsonParser();
            var elements = parser.GetArrayElementsByName(text, "BLOCKS");

            foreach (var element in elements)
            {
                var startTimeObject = parser.GetFirstObject(element, "time_start");
                var endTimeObject   = parser.GetFirstObject(element, "time_end");
                var textObject      = parser.GetFirstObject(element, "text");
                if (!string.IsNullOrEmpty(textObject) && !string.IsNullOrEmpty(startTimeObject) && !string.IsNullOrEmpty(endTimeObject))
                {
                    if (double.TryParse(startTimeObject, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var startMs) &&
                        double.TryParse(endTimeObject, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var endMs))
                    {
                        var s = Utilities.UrlDecode(Json.DecodeJsonText(textObject));
                        var p = new Paragraph(s, startMs, endMs);
                        subtitle.Paragraphs.Add(p);
                    }
                    else
                    {
                        _errorCount++;
                    }
                }
            }
            subtitle.Renumber();
        }
示例#13
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;
            var sb = new StringBuilder();

            foreach (var s in lines)
            {
                sb.Append(s);
            }

            var text = sb.ToString().TrimStart();

            if (text.IndexOf("captiondata", StringComparison.Ordinal) < 0)
            {
                return;
            }

            subtitle.Paragraphs.Clear();
            var parser        = new SeJsonParser();
            var captionDataAr = parser.GetArrayElementsByName(text, "captiondata");

            foreach (var captionData in captionDataAr)
            {
                var texts = parser.GetArrayElementsByName(captionData, "data");
                foreach (var textElement in texts)
                {
                    var start   = parser.GetFirstObject(textElement, "fromms");
                    var end     = parser.GetFirstObject(textElement, "toms");
                    var caption = parser.GetFirstObject(textElement, "caption");
                    if (!string.IsNullOrEmpty(caption) &&
                        double.TryParse(start, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var startMs) &&
                        double.TryParse(end, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var endMs))
                    {
                        caption = Json.DecodeJsonText(caption);
                        caption = caption.Replace("<br />", Environment.NewLine);
                        var p = new Paragraph(caption, startMs, endMs);
                        subtitle.Paragraphs.Add(p);
                    }
                }
            }

            subtitle.Renumber();
        }
示例#14
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (var s in lines)
            {
                sb.Append(s);
            }

            var text = sb.ToString().TrimStart();

            if (!text.StartsWith("[", StringComparison.Ordinal))
            {
                return;
            }

            var parser   = new SeJsonParser();
            var elements = parser.GetArrayElements(text);

            foreach (var element in elements)
            {
                var startTimeObject    = parser.GetFirstObject(element, "s");
                var durationTimeObject = parser.GetFirstObject(element, "d");
                var s = parser.GetFirstObject(element, "n");
                if (!string.IsNullOrEmpty(s) && !string.IsNullOrEmpty(startTimeObject) && !string.IsNullOrEmpty(durationTimeObject))
                {
                    if (double.TryParse(startTimeObject, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var startSeconds) &&
                        double.TryParse(durationTimeObject, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var durationSeconds))
                    {
                        var pText = Json.DecodeJsonText(s);
                        var p     = new Paragraph(pText, startSeconds * 1000.0, (startSeconds + durationSeconds) * 1000.0);
                        subtitle.Paragraphs.Add(p);
                    }
                    else
                    {
                        _errorCount++;
                    }
                }
            }
            subtitle.Renumber();
        }
示例#15
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;
            var sb = new StringBuilder();

            foreach (var s in lines)
            {
                sb.Append(s);
            }

            var text = sb.ToString().TrimStart();

            if (!text.Contains("\"alternatives\"", StringComparison.Ordinal) || !text.Contains("\"words\"", StringComparison.Ordinal))
            {
                return;
            }

            var parser = new SeJsonParser();
            var words  = parser.GetArrayElementsByName(text, "words");

            foreach (var word in words)
            {
                var startTimeObject = parser.GetFirstObject(word, "startTime");
                var endTimeObject   = parser.GetFirstObject(word, "endTime");
                var s = parser.GetFirstObject(word, "word");
                if (!string.IsNullOrEmpty(s) && !string.IsNullOrEmpty(startTimeObject) && !string.IsNullOrEmpty(endTimeObject))
                {
                    if (double.TryParse(startTimeObject.TrimEnd('s'), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var startSecs) &&
                        double.TryParse(endTimeObject.TrimEnd('s'), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var endSecs))
                    {
                        var pText = Json.DecodeJsonText(s);
                        var p     = new Paragraph(pText, startSecs * 1000.0, endSecs * 1000.0);
                        subtitle.Paragraphs.Add(p);
                    }
                    else
                    {
                        _errorCount++;
                    }
                }
            }

            subtitle.Renumber();
        }
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }

            string allText        = sb.ToString();
            var    indexOfMainTag = allText.IndexOf("\"timestamp_begin\"", StringComparison.Ordinal);

            if (indexOfMainTag < 0 && !allText.Contains("\"data\""))
            {
                return;
            }

            var startIndex = allText.IndexOf('{');

            if (startIndex < 0)
            {
                return;
            }

            var json         = allText.Substring(startIndex);
            var parser       = new SeJsonParser();
            var subtitleData = parser.GetFirstObject(json, "data");

            if (string.IsNullOrEmpty(subtitleData))
            {
                return;
            }

            var format    = new TwentyThreeJson();
            var innerJson = Json.DecodeJsonText(subtitleData);

            format.LoadSubtitle(subtitle, new List <string> {
                innerJson
            }, null);
        }
示例#17
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }

            var text = sb.ToString();

            if (!text.Contains("\"items\"") || !text.Contains("\"alternatives\"", StringComparison.Ordinal))
            {
                return;
            }

            var parser = new SeJsonParser();

            foreach (string json in parser.GetArrayElementsByName(text, "items"))
            {
                var start   = parser.GetAllTagsByNameAsStrings(json, "start_time").FirstOrDefault();
                var end     = parser.GetAllTagsByNameAsStrings(json, "end_time").FirstOrDefault();
                var content = parser.GetAllTagsByNameAsStrings(json, "content").FirstOrDefault();
                if (start != null && end != null && !string.IsNullOrEmpty(content))
                {
                    if (double.TryParse(start, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out var startSeconds) &&
                        double.TryParse(end, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out var endSeconds))
                    {
                        subtitle.Paragraphs.Add(new Paragraph(Json.DecodeJsonText(content), startSeconds * TimeCode.BaseUnit, endSeconds * TimeCode.BaseUnit));
                    }
                    else
                    {
                        _errorCount++;
                    }
                }
            }
            subtitle.Renumber();
        }
示例#18
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (var s in lines)
            {
                sb.Append(s);
            }

            var allText = sb.ToString();

            if (!allText.Contains("\"text\""))
            {
                return;
            }

            var startTimes = Json.ReadArray(allText, "start");
            var endTimes   = Json.ReadArray(allText, "end");
            var texts      = Json.ReadArray(allText, "text");

            var max = Math.Min(Math.Min(startTimes.Count, texts.Count), endTimes.Count);

            for (var i = 0; i < max; i++)
            {
                if (int.TryParse(startTimes[i], out var startMs) && int.TryParse(endTimes[i], out var endMs))
                {
                    var text = Json.DecodeJsonText(texts[i]);
                    var p    = new Paragraph(text, startMs, endMs);
                    subtitle.Paragraphs.Add(p);
                }
                else
                {
                    _errorCount++;
                }
            }
            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
示例#19
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }

            string allText = sb.ToString();

            if (!allText.Contains("\"text\""))
            {
                return;
            }

            var startTimes = Json.ReadArray(allText, "start");
            var endTimes   = Json.ReadArray(allText, "end");
            var texts      = Json.ReadArray(allText, "text");

            for (int i = 0; i < Math.Min(Math.Min(startTimes.Count, texts.Count), endTimes.Count); i++)
            {
                try
                {
                    string text = Json.DecodeJsonText(texts[i]);
                    var    p    = new Paragraph(text, int.Parse(startTimes[i]), int.Parse(endTimes[i]));
                    subtitle.Paragraphs.Add(p);
                }
                catch
                {
                    _errorCount++;
                }
            }
            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }

            string allText        = sb.ToString();
            var    indexOfMainTag = allText.IndexOf("\"timestamp_begin\"", StringComparison.Ordinal);

            if (indexOfMainTag < 0)
            {
                return;
            }

            var indexOfSubtitles = allText.IndexOf("subtitles", StringComparison.Ordinal);

            if (indexOfSubtitles <= 0)
            {
                return;
            }

            var startText  = allText.Substring(0, indexOfSubtitles);
            var startIndex = startText.LastIndexOf('{');

            if (startIndex < 0)
            {
                return;
            }

            var json   = allText.Substring(startIndex);
            var parser = new SeJsonParser();
            var items  = parser.GetArrayElementsByName(json, "subtitles");

            foreach (var item in items)
            {
                var textLines = parser.GetArrayElementsByName(item, "text");
                var beginTime = parser.GetAllTagsByNameAsStrings(item, "timestamp_begin");
                var endTime   = parser.GetAllTagsByNameAsStrings(item, "timestamp_end");
                if (textLines.Count > 0 && beginTime.Count == 1 && endTime.Count == 1 &&
                    double.TryParse(beginTime[0], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var startSeconds) &&
                    double.TryParse(endTime[0], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var endSeconds))
                {
                    var text = new StringBuilder();
                    foreach (var line in textLines)
                    {
                        text.AppendLine(Json.DecodeJsonText(line));
                    }

                    var p = new Paragraph(text.ToString().Trim(), startSeconds * 1000.0, endSeconds * 1000.0);
                    subtitle.Paragraphs.Add(p);
                }
            }

            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
示例#21
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }

            string allText = sb.ToString();

            if (!allText.Contains("text_tees"))
            {
                return;
            }

            var times = Json.ReadArray(allText, "text_tees");
            var texts = Json.ReadArray(allText, "text_content");

            for (int i = 0; i < Math.Min(times.Count, texts.Count); i++)
            {
                try
                {
                    string text = texts[i];
                    if (text.StartsWith('['))
                    {
                        var textLines = Json.ReadArray("{\"text\":" + texts[i] + "}", "text");
                        var textSb    = new StringBuilder();
                        foreach (string line in textLines)
                        {
                            string t = Json.DecodeJsonText(line);
                            if (t.StartsWith("[\"", StringComparison.Ordinal) && t.EndsWith("\"]", StringComparison.Ordinal))
                            {
                                var innerSb        = new StringBuilder();
                                var innerTextLines = Json.ReadArray("{\"text\":" + t + "}", "text");
                                foreach (string innerLine in innerTextLines)
                                {
                                    innerSb.Append(' ');
                                    innerSb.Append(innerLine);
                                }
                                textSb.AppendLine(innerSb.ToString().Trim());
                            }
                            else
                            {
                                textSb.AppendLine(t);
                            }
                        }
                        text = textSb.ToString().Trim();
                        text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
                    }
                    var p = new Paragraph(text, int.Parse(times[i]), 0);
                    if (i + 1 < times.Count)
                    {
                        p.EndTime.TotalMilliseconds = int.Parse(times[i + 1]);
                    }

                    subtitle.Paragraphs.Add(p);
                }
                catch
                {
                    _errorCount++;
                }
            }
            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
示例#22
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            foreach (string s in lines)
            {
                sb.Append(s);
            }

            if (!sb.ToString().Contains("\"words\":"))
            {
                return;
            }

            var temp = sb.ToString();

            while (temp.Contains("  "))
            {
                temp = temp.Replace("  ", " ");
            }

            temp = temp.Replace("}, {", "},{");
            temp = temp.Replace("} , {", "},{");
            temp = temp.Replace("} ,{", "},{");
            temp = temp.Substring(temp.IndexOf("\"words\":") + 10);
            Paragraph p = null;

            foreach (string line in temp.Replace("},{", Environment.NewLine).SplitToLines())
            {
                string s        = line.Trim() + "}";
                string start    = Json.ReadTag(s, "time");
                string duration = Json.ReadTag(s, "duration");
                string text     = Json.ReadTag(s, "name");
                if (start != null && duration != null && text != null)
                {
                    double startSeconds;
                    double durationSeconds;
                    if (double.TryParse(start, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out startSeconds) &&
                        double.TryParse(duration, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out durationSeconds))
                    {
                        if ((text == "." || text == "!" || text == "?" || text == ":") && p != null)
                        {
                            p.EndTime.TotalMilliseconds += durationSeconds * TimeCode.BaseUnit;
                            p.Text += text;
                        }
                        else
                        {
                            p = new Paragraph(Json.DecodeJsonText(text), startSeconds * TimeCode.BaseUnit, (startSeconds + durationSeconds) * TimeCode.BaseUnit);
                            subtitle.Paragraphs.Add(p);
                        }
                    }
                    else
                    {
                        _errorCount++;
                    }
                }
                else
                {
                    _errorCount++;
                }
            }
            subtitle.Renumber();
        }