private bool TryGetWriter(string format, [NotNullWhen(true)] out ISubtitleWriter?value) { if (string.IsNullOrEmpty(format)) { throw new ArgumentNullException(nameof(format)); } if (string.Equals(format, "json", StringComparison.OrdinalIgnoreCase)) { value = new JsonWriter(); return(true); } if (string.Equals(format, SubtitleFormat.SRT, StringComparison.OrdinalIgnoreCase)) { value = new SrtWriter(); return(true); } if (string.Equals(format, SubtitleFormat.VTT, StringComparison.OrdinalIgnoreCase)) { value = new VttWriter(); return(true); } if (string.Equals(format, SubtitleFormat.TTML, StringComparison.OrdinalIgnoreCase)) { value = new TtmlWriter(); return(true); } value = null; return(false); }
public void TestParse2() { var sut = new AssParser(); var stream = File.OpenRead(@"MediaEncoding\Subtitles\TestSubtitles\data2.ass"); var result = sut.Parse(stream, CancellationToken.None); Assert.IsNotNull(result); using (var ms = new MemoryStream()) { var writer = new SrtWriter(); writer.Write(result, ms, CancellationToken.None); ms.Position = 0; var text = Encoding.UTF8.GetString(ms.ToArray()); var b = text; } }