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; } }
private void bgwA2SOutput_DoWork(object sender, DoWorkEventArgs e) { A2SControlEnabled(false); string strDialogues; string strDescriptions; string strFolderPath; string strFileNameWithExtension; string strFileNameWithoutExtension; string strFilePath; string strDestDir = null; int fileNum = lvASSFileSelection.Items.Count; ssProgressBar.Maximum = fileNum; ssProgressBar.Minimum = 0; ssProgressBar.Step = 1; ssProgressBar.Value = 0; foreach (ListViewItem lviFile in lvASSFileSelection.Items) { strDestDir = tbSrtOutputFolder.Text; strFilePath = (string)lviFile.Tag; int lastSlash = strFilePath.LastIndexOf("\\"); strFolderPath = strFilePath.Substring(0, lastSlash); strFileNameWithExtension = strFilePath.Substring(lastSlash + 1); int lastDot = strFileNameWithExtension.LastIndexOf("."); strFileNameWithoutExtension = strFileNameWithExtension.Substring(0, lastDot); AssReader ar = new AssReader(strFilePath); if (ar.IsValid()) { foreach (ListViewItem lviType in lvVersionSelection.CheckedItems) { if (lviType.Index <= 4) { strDialogues = ar.ReadDialogues(); AssAnalyzerForSrt aafs = new AssAnalyzerForSrt(strDialogues, lviType.Index, rbChinEng.Checked); string[] strSrtLines = aafs.Analyze(); SrtWriter sw = new SrtWriter(strDestDir, strFileNameWithoutExtension, lviType.Index); sw.WriteSrtFile(strSrtLines); } else { string[] strAssDialogues; string[] strAssDescriptions; strDialogues = ar.ReadDialogues(); strDescriptions = ar.ReadDescription(); AssAnalyzerForAss aafa = new AssAnalyzerForAss(strDialogues, strDescriptions, lviType.Index, rbChinEng.Checked); aafa.Analyze(out strAssDescriptions, out strAssDialogues); AssWriter aw = new AssWriter(strDestDir, strFileNameWithoutExtension, lviType.Index); aw.WriteAssFile(strAssDescriptions, strAssDialogues); } } ZipPatcher(strDestDir, strFileNameWithoutExtension); ssProgressBar.PerformStep(); } else { MessageBox.Show("不是.ass文件!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } A2SControlEnabled(true); }