using System; using System.Collections.Generic; using System.Globalization; using System.Text; namespace Nikse.SubtitleEdit.Core.SubtitleFormats { public class UnknownSubtitle9 : SubtitleFormat { //00:04:04.219 //The city council of long beach public override string Extension => ".html"; public override string Name => "Unknown 9"; public override string ToText(Subtitle subtitle, string title) { var sb = new StringBuilder(); sb.AppendLine("
"); sb.AppendLine("
"); sb.AppendLine("
"); foreach (Paragraph p in subtitle.Paragraphs) { sb.AppendLine($" {p.Text.Replace(Environment.NewLine, "
")}
"); } sb.AppendLine("
"); sb.AppendLine("
"); sb.AppendLine("
"); return sb.ToString().Trim(); } public override void LoadSubtitle(Subtitle subtitle, List lines, string fileName) { //[♪techno music♪] var temp = new StringBuilder(); foreach (string l in lines) { temp.Append(l); } string all = temp.ToString(); if (!all.Contains("class=\"caption\"")) { return; } _errorCount = 0; subtitle.Paragraphs.Clear(); for (int i = 0; i < lines.Count; i++) { string line = lines[i].Trim(); var indexOfStart = line.IndexOf("starttime=", StringComparison.Ordinal); var indexOfDuration = line.IndexOf("duration=", StringComparison.Ordinal); if (line.Contains("class=\"caption\"") && indexOfStart > 0 && indexOfDuration > 0) { string startTime = "0"; int index = indexOfStart + 10; while (index < line.Length && @"0123456789""'.,".Contains(line[index])) { if (@"0123456789,.".Contains(line[index])) { startTime += line[index]; } index++; } string duration = "0"; index = indexOfDuration + 9; while (index < line.Length && @"0123456789""'.,".Contains(line[index])) { if (@"0123456789,.".Contains(line[index])) { duration += line[index]; } index++; } string text = string.Empty; index = line.IndexOf('>', indexOfDuration); if (index > 0 && index + 1 < line.Length) { text = line.Substring(index + 1).Trim(); index = text.IndexOf(" 0) { text = text.Substring(0, index); } text = text.Replace("
", Environment.NewLine); } long startMilliseconds; long durationMilliseconds; if (text.Length > 0 && long.TryParse(startTime, out startMilliseconds) && long.TryParse(duration, out durationMilliseconds)) { subtitle.Paragraphs.Add(new Paragraph(text, startMilliseconds, startMilliseconds + durationMilliseconds)); } } } subtitle.Renumber(); } } }