private void buttonConvert_Click(object sender, EventArgs e) { if (listViewInputFiles.Items.Count == 0) { MessageBox.Show(Configuration.Settings.Language.BatchConvert.NothingToConvert); return; } if (!checkBoxOverwriteOriginalFiles.Checked) { if (textBoxOutputFolder.Text.Length < 2) { MessageBox.Show(Configuration.Settings.Language.BatchConvert.PleaseChooseOutputFolder); return; } else if (!Directory.Exists(textBoxOutputFolder.Text)) { try { Directory.CreateDirectory(textBoxOutputFolder.Text); } catch (Exception exception) { MessageBox.Show(exception.Message); return; } } } _converting = true; buttonConvert.Enabled = false; buttonCancel.Enabled = false; progressBar1.Style = ProgressBarStyle.Blocks; progressBar1.Maximum = listViewInputFiles.Items.Count; progressBar1.Value = 0; progressBar1.Visible = progressBar1.Maximum > 2; string toFormat = comboBoxSubtitleFormats.Text; groupBoxOutput.Enabled = false; groupBoxConvertOptions.Enabled = false; buttonInputBrowse.Enabled = false; buttonSearchFolder.Enabled = false; _count = 0; _converted = 0; _errors = 0; _abort = false; BackgroundWorker worker1 = new BackgroundWorker(); BackgroundWorker worker2 = new BackgroundWorker(); BackgroundWorker worker3 = new BackgroundWorker(); worker1.DoWork += DoThreadWork; worker1.RunWorkerCompleted += ThreadWorkerCompleted; worker2.DoWork += DoThreadWork; worker2.RunWorkerCompleted += ThreadWorkerCompleted; worker3.DoWork += DoThreadWork; worker3.RunWorkerCompleted += ThreadWorkerCompleted; listViewInputFiles.BeginUpdate(); foreach (ListViewItem item in listViewInputFiles.Items) item.SubItems[3].Text = "-"; listViewInputFiles.EndUpdate(); Refresh(); int index = 0; while (index < listViewInputFiles.Items.Count && _abort == false) { ListViewItem item = listViewInputFiles.Items[index]; string fileName = item.Text; try { SubtitleFormat format = null; Encoding encoding; var sub = new Subtitle(); var fi = new FileInfo(fileName); if (fi.Length < 1024 * 1024) // max 1 mb { format = sub.LoadSubtitle(fileName, out encoding, null); if (format == null) { var ebu = new Ebu(); if (ebu.IsMine(null, fileName)) { ebu.LoadSubtitle(sub, null, fileName); format = ebu; } } if (format == null) { var pac = new Pac(); if (pac.IsMine(null, fileName)) { pac.LoadSubtitle(sub, null, fileName); format = pac; } } if (format == null) { var cavena890 = new Cavena890(); if (cavena890.IsMine(null, fileName)) { cavena890.LoadSubtitle(sub, null, fileName); format = cavena890; } } if (format == null) { var spt = new Spt(); if (spt.IsMine(null, fileName)) { spt.LoadSubtitle(sub, null, fileName); format = spt; } } if (format == null) { var cheetahCaption = new CheetahCaption(); if (cheetahCaption.IsMine(null, fileName)) { cheetahCaption.LoadSubtitle(sub, null, fileName); format = cheetahCaption; } } if (format == null) { var capMakerPlus = new CapMakerPlus(); if (capMakerPlus.IsMine(null, fileName)) { capMakerPlus.LoadSubtitle(sub, null, fileName); format = capMakerPlus; } } if (format == null) { var captionate = new Captionate(); if (captionate.IsMine(null, fileName)) { captionate.LoadSubtitle(sub, null, fileName); format = captionate; } } if (format == null) { var ultech130 = new Ultech130(); if (ultech130.IsMine(null, fileName)) { ultech130.LoadSubtitle(sub, null, fileName); format = ultech130; } } if (format == null) { var nciCaption = new NciCaption(); if (nciCaption.IsMine(null, fileName)) { nciCaption.LoadSubtitle(sub, null, fileName); format = nciCaption; } } if (format == null) { var avidStl = new AvidStl(); if (avidStl.IsMine(null, fileName)) { avidStl.LoadSubtitle(sub, null, fileName); format = avidStl; } } if (format == null) { var elr = new ELRStudioClosedCaption(); if (elr.IsMine(null, fileName)) { elr.LoadSubtitle(sub, null, fileName); format = elr; } } if (format != null && format.GetType() == typeof(MicroDvd)) { if (sub != null && sub.Paragraphs.Count > 0 && sub.Paragraphs[0].Duration.TotalMilliseconds < 1001) { if (sub.Paragraphs[0].Text.StartsWith("29.") || sub.Paragraphs[0].Text.StartsWith("23.") || sub.Paragraphs[0].Text.StartsWith("29,") || sub.Paragraphs[0].Text.StartsWith("23,") || sub.Paragraphs[0].Text == "24" || sub.Paragraphs[0].Text == "25" || sub.Paragraphs[0].Text == "30" || sub.Paragraphs[0].Text == "60") sub.Paragraphs.RemoveAt(0); } } } var bluRaySubtitles = new List<BluRaySupParser.PcsData>(); bool isVobSub = false; bool isMatroska = false; if (format == null && fileName.ToLower().EndsWith(".sup") && Main.IsBluRaySupFile(fileName)) { var log = new StringBuilder(); bluRaySubtitles = BluRaySupParser.ParseBluRaySup(fileName, log); } else if (format == null && fileName.ToLower().EndsWith(".sub") && Main.HasVobSubHeader(fileName)) { isVobSub = true; } else if (format == null && fileName.ToLower().EndsWith(".mkv") && item.SubItems[2].Text.StartsWith("Matroska")) { isMatroska = true; } if (format == null && bluRaySubtitles.Count == 0 && !isVobSub && !isMatroska) { if (progressBar1.Value < progressBar1.Maximum) progressBar1.Value++; labelStatus.Text = progressBar1.Value + " / " + progressBar1.Maximum; } else { if (isMatroska) { if (Path.GetExtension(fileName).ToLower() == ".mkv" || Path.GetExtension(fileName).ToLower() == ".mks") { Matroska mkv = new Matroska(); bool isValid = false; bool hasConstantFrameRate = false; double frameRate = 0; int width = 0; int height = 0; double milliseconds = 0; string videoCodec = string.Empty; mkv.GetMatroskaInfo(fileName, ref isValid, ref hasConstantFrameRate, ref frameRate, ref width, ref height, ref milliseconds, ref videoCodec); if (isValid) { var subtitleList = mkv.GetMatroskaSubtitleTracks(fileName, out isValid); if (subtitleList.Count > 0) { foreach (MatroskaSubtitleInfo x in subtitleList) { if (x.CodecId.ToUpper() == "S_VOBSUB") { //TODO: convert from VobSub image based format } else if (x.CodecId.ToUpper() == "S_HDMV/PGS") { //TODO: convert from Blu-ray image based format } else if (x.CodecId.ToUpper() == "S_TEXT/UTF8" || x.CodecId.ToUpper() == "S_TEXT/SSA" || x.CodecId.ToUpper() == "S_TEXT/ASS") { _matroskaListViewItem = item; List<SubtitleSequence> mkvSub = mkv.GetMatroskaSubtitle(fileName, (int)x.TrackNumber, out isValid, MatroskaProgress); bool isSsa = false; if (x.CodecPrivate.ToLower().Contains("[script info]")) { if (x.CodecPrivate.ToLower().Contains("[V4 Styles]".ToLower())) format = new SubStationAlpha(); else format = new AdvancedSubStationAlpha(); isSsa = true; } else { format = new SubRip(); } if (isSsa) { foreach (Paragraph p in Main.LoadMatroskaSSa(x, fileName, format, mkvSub).Paragraphs) { sub.Paragraphs.Add(p); } } else { foreach (SubtitleSequence p in mkvSub) { sub.Paragraphs.Add(new Paragraph(p.Text, p.StartMilliseconds, p.EndMilliseconds)); } } break; } } } } } } else if (bluRaySubtitles.Count > 0) { item.SubItems[3].Text = "OCR..."; var vobSubOcr = new VobSubOcr(); vobSubOcr.FileName = Path.GetFileName(fileName); vobSubOcr.InitializeBatch(bluRaySubtitles, Configuration.Settings.VobSubOcr, fileName); sub = vobSubOcr.SubtitleFromOcr; } else if (isVobSub) { item.SubItems[3].Text = "OCR..."; var vobSubOcr = new VobSubOcr(); vobSubOcr.InitializeBatch(fileName, Configuration.Settings.VobSubOcr, true); sub = vobSubOcr.SubtitleFromOcr; } if (comboBoxSubtitleFormats.Text == new AdvancedSubStationAlpha().Name && _assStyle != null) { sub.Header = _assStyle; } else if (comboBoxSubtitleFormats.Text == new SubStationAlpha().Name && _ssaStyle != null) { sub.Header = _ssaStyle; } int prevIndex = -1; foreach (Paragraph p in sub.Paragraphs) { string prevText = string.Empty; var prev = sub.GetParagraphOrDefault(prevIndex); if (prev != null) prevText = prev.Text; prevIndex++; if (checkBoxRemoveTextForHI.Checked) { p.Text = _removeForHI.RemoveTextFromHearImpaired(p.Text, prevText); } if (checkBoxRemoveFormatting.Checked) { p.Text = Utilities.RemoveHtmlTags(p.Text); if (p.Text.StartsWith("{") && p.Text.Length > 6 && p.Text[5] == '}') p.Text = p.Text.Remove(0, 6); if (p.Text.StartsWith("{") && p.Text.Length > 6 && p.Text[4] == '}') p.Text = p.Text.Remove(0, 5); } } if (checkBoxFixCasing.Checked) { _changeCasing.FixCasing(sub, Utilities.AutoDetectGoogleLanguage(sub)); _changeCasingNames.Initialize(sub); _changeCasingNames.FixCasing(); } double fromFrameRate; double toFrameRate; if (double.TryParse(comboBoxFrameRateFrom.Text, out fromFrameRate) && double.TryParse(comboBoxFrameRateTo.Text, out toFrameRate)) { sub.ChangeFramerate(fromFrameRate, toFrameRate); } if (timeUpDownAdjust.TimeCode.TotalMilliseconds > 0.00001) { var totalMilliseconds = timeUpDownAdjust.TimeCode.TotalMilliseconds; if (radioButtonShowEarlier.Checked) totalMilliseconds *= -1; sub.AddTimeToAllParagraphs(TimeSpan.FromMilliseconds(totalMilliseconds)); } while (worker1.IsBusy && worker2.IsBusy && worker3.IsBusy) { Application.DoEvents(); System.Threading.Thread.Sleep(100); } ThreadDoWorkParameter parameter = new ThreadDoWorkParameter(checkBoxFixCommonErrors.Checked, checkBoxMultipleReplace.Checked, checkBoxSplitLongLines.Checked, checkBoxAutoBalance.Checked, checkBoxSetMinimumDisplayTimeBetweenSubs.Checked, item, sub, GetCurrentSubtitleFormat(), GetCurrentEncoding(), Configuration.Settings.Tools.BatchConvertLanguage, fileName, toFormat, format); if (!worker1.IsBusy) worker1.RunWorkerAsync(parameter); else if (!worker2.IsBusy) worker2.RunWorkerAsync(parameter); else if (!worker3.IsBusy) worker3.RunWorkerAsync(parameter); } } catch { if (progressBar1.Value < progressBar1.Maximum) progressBar1.Value++; labelStatus.Text = progressBar1.Value + " / " + progressBar1.Maximum; } index++; } while (worker1.IsBusy || worker2.IsBusy || worker3.IsBusy) { try { Application.DoEvents(); } catch { } System.Threading.Thread.Sleep(100); } _converting = false; labelStatus.Text = string.Empty; progressBar1.Visible = false; buttonConvert.Enabled = true; buttonCancel.Enabled = true; groupBoxOutput.Enabled = true; groupBoxConvertOptions.Enabled = true; buttonInputBrowse.Enabled = true; buttonSearchFolder.Enabled = true; }
internal Subtitle LoadMatroskaSubtitleForSync(MatroskaSubtitleInfo matroskaSubtitleInfo, string fileName) { Subtitle subtitle = new Subtitle(); bool isValid; bool isSsa = false; var matroska = new Matroska(); SubtitleFormat format; if (matroskaSubtitleInfo.CodecId.ToUpper() == "S_VOBSUB") { return subtitle; } if (matroskaSubtitleInfo.CodecId.ToUpper() == "S_HDMV/PGS") { return subtitle; } List<SubtitleSequence> sub = matroska.GetMatroskaSubtitle(fileName, (int)matroskaSubtitleInfo.TrackNumber, out isValid, MatroskaProgress); if (isValid) { if (matroskaSubtitleInfo.CodecPrivate.ToLower().Contains("[script info]")) { if (matroskaSubtitleInfo.CodecPrivate.ToLower().Contains("[V4 Styles]".ToLower())) format = new SubStationAlpha(); else format = new AdvancedSubStationAlpha(); isSsa = true; } else { format = new SubRip(); } if (isSsa) { foreach (Paragraph p in LoadMatroskaSSa(matroskaSubtitleInfo, fileName, format, sub).Paragraphs) { subtitle.Paragraphs.Add(p); } } else { foreach (SubtitleSequence p in sub) { subtitle.Paragraphs.Add(new Paragraph(p.Text, p.StartMilliseconds, p.EndMilliseconds)); } } } return subtitle; }
internal void LoadMatroskaSubtitle(MatroskaSubtitleInfo matroskaSubtitleInfo, string fileName, bool batchMode) { bool isValid; bool isSsa = false; var matroska = new Matroska(); SubtitleFormat format; if (matroskaSubtitleInfo.CodecId.ToUpper() == "S_VOBSUB") { if (batchMode) return; LoadVobSubFromMatroska(matroskaSubtitleInfo, fileName); return; } if (matroskaSubtitleInfo.CodecId.ToUpper() == "S_HDMV/PGS") { if (batchMode) return; LoadBluRaySubFromMatroska(matroskaSubtitleInfo, fileName); return; } ShowStatus(_language.ParsingMatroskaFile); Refresh(); Cursor.Current = Cursors.WaitCursor; List<SubtitleSequence> sub = matroska.GetMatroskaSubtitle(fileName, (int)matroskaSubtitleInfo.TrackNumber, out isValid, MatroskaProgress); Cursor.Current = Cursors.Default; if (isValid) { MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile); _subtitleListViewIndex = -1; if (!batchMode) ResetSubtitle(); _subtitle.Paragraphs.Clear(); if (matroskaSubtitleInfo.CodecPrivate.ToLower().Contains("[script info]")) { if (matroskaSubtitleInfo.CodecPrivate.ToLower().Contains("[V4 Styles]".ToLower())) format = new SubStationAlpha(); else format = new AdvancedSubStationAlpha(); isSsa = true; if (_networkSession == null) { SubtitleListview1.ShowExtraColumn(Configuration.Settings.Language.General.Style); SubtitleListview1.DisplayExtraFromExtra = true; } } else { format = new SubRip(); if (_networkSession == null && SubtitleListview1.IsExtraColumnVisible) SubtitleListview1.HideExtraColumn(); } comboBoxSubtitleFormats.SelectedIndexChanged -= ComboBoxSubtitleFormatsSelectedIndexChanged; SetCurrentFormat(format); comboBoxSubtitleFormats.SelectedIndexChanged += ComboBoxSubtitleFormatsSelectedIndexChanged; if (isSsa) { foreach (Paragraph p in LoadMatroskaSSa(matroskaSubtitleInfo, fileName, format, sub).Paragraphs) { _subtitle.Paragraphs.Add(p); } if (!string.IsNullOrEmpty(matroskaSubtitleInfo.CodecPrivate)) { bool eventsStarted = false; bool fontsStarted = false; bool graphicsStarted = false; var header = new StringBuilder(); foreach (string line in matroskaSubtitleInfo.CodecPrivate.Replace(Environment.NewLine, "\n").Split('\n')) { if (!eventsStarted && !fontsStarted && !graphicsStarted) { header.AppendLine(line); } else if (line.Trim().ToLower().StartsWith("dialogue:")) { eventsStarted = true; fontsStarted = false; graphicsStarted = false; } else if (line.Trim().ToLower() == "[events]") { eventsStarted = true; fontsStarted = false; graphicsStarted = false; } else if (line.Trim().ToLower() == "[fonts]") { eventsStarted = false; fontsStarted = true; graphicsStarted = false; } else if (line.Trim().ToLower() == "[graphics]") { eventsStarted = false; fontsStarted = false; graphicsStarted = true; } } _subtitle.Header = header.ToString(); } } else { foreach (SubtitleSequence p in sub) { _subtitle.Paragraphs.Add(new Paragraph(p.Text, p.StartMilliseconds, p.EndMilliseconds)); } } SetEncoding(Encoding.UTF8); ShowStatus(_language.SubtitleImportedFromMatroskaFile); _subtitle.Renumber(1); _subtitle.WasLoadedWithFrameNumbers = false; if (fileName.ToLower().EndsWith(".mkv") || fileName.ToLower().EndsWith(".mks")) { _fileName = fileName.Substring(0, fileName.Length - 4); Text = Title + " - " + _fileName; } else { Text = Title; } _fileDateTime = new DateTime(); _converted = true; if (batchMode) return; SubtitleListview1.Fill(_subtitle, _subtitleAlternate); if (_subtitle.Paragraphs.Count > 0) SubtitleListview1.SelectIndexAndEnsureVisible(0); ShowSource(); } }
public void SsaSimpleFontColorAndItalic() { var target = new SubStationAlpha(); var subtitle = new Subtitle(); target.LoadSubtitle(subtitle, GetSsaLines(@"{\c&HFFFF00&\i1}CYAN{\i0}"), null); string actual = subtitle.Paragraphs[0].Text; const string expected = "<font color=\"#00ffff\"><i>CYAN</i></font>"; Assert.AreEqual(expected, actual); }
private Subtitle LoadMatroskaSubtitleForSync(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska) { var subtitle = new Subtitle(); bool isSsa = false; if (matroskaSubtitleInfo.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase)) { return subtitle; } if (matroskaSubtitleInfo.CodecId.Equals("S_HDMV/PGS", StringComparison.OrdinalIgnoreCase)) { return subtitle; } SubtitleFormat format; if (matroskaSubtitleInfo.CodecPrivate.Contains("[script info]", StringComparison.OrdinalIgnoreCase)) { if (matroskaSubtitleInfo.CodecPrivate.Contains("[V4 Styles]", StringComparison.OrdinalIgnoreCase)) { format = new SubStationAlpha(); } else { format = new AdvancedSubStationAlpha(); } isSsa = true; } else { format = new SubRip(); } var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, this.MatroskaProgress); TaskbarList.SetProgressState(this.Handle, TaskbarButtonProgressFlags.NoProgress); if (isSsa) { foreach (var p in Utilities.LoadMatroskaSSA(matroskaSubtitleInfo, matroska.Path, format, sub).Paragraphs) { subtitle.Paragraphs.Add(p); } } else { foreach (var p in sub) { subtitle.Paragraphs.Add(new Paragraph(p.Text, p.Start, p.End)); } } return subtitle; }
private string GetDefaultHeader() { SubtitleFormat format; if (_isSubStationAlpha) format = new SubStationAlpha(); else format = new AdvancedSubStationAlpha(); var sub = new Subtitle(); string text = format.ToText(sub, string.Empty); string[] lineArray = text.Split(Utilities.NewLineChars); var lines = new List<string>(); foreach (string line in lineArray) lines.Add(line); format.LoadSubtitle(sub, lines, string.Empty); return sub.Header.Trim(); }
public SubStationAlphaProperties(Subtitle subtitle, SubtitleFormat format, string videoFileName, string subtitleFileName) { InitializeComponent(); _subtitle = subtitle; _isSubStationAlpha = format.FriendlyName == new SubStationAlpha().FriendlyName; _videoFileName = videoFileName; var l = Configuration.Settings.Language.SubStationAlphaProperties; if (_isSubStationAlpha) { Text = l.TitleSubstationAlpha; labelWrapStyle.Visible = false; comboBoxWrapStyle.Visible = false; checkBoxScaleBorderAndShadow.Visible = false; Height = Height - (comboBoxWrapStyle.Height + checkBoxScaleBorderAndShadow.Height + 8); } else { Text = l.Title; } comboBoxWrapStyle.SelectedIndex = 2; comboBoxCollision.SelectedIndex = 0; string header = subtitle.Header; if (subtitle.Header == null) { SubStationAlpha ssa = new SubStationAlpha(); var sub = new Subtitle(); var lines = new List<string>(); foreach (string line in subtitle.ToText(ssa).Replace(Environment.NewLine, "\n").Split('\n')) lines.Add(line); string title = "Untitled"; if (!string.IsNullOrEmpty(subtitleFileName)) title = Path.GetFileNameWithoutExtension(subtitleFileName); else if (!string.IsNullOrEmpty(videoFileName)) title = Path.GetFileNameWithoutExtension(videoFileName); ssa.LoadSubtitle(sub, lines, title); header = sub.Header; } if (header != null) { foreach (string line in header.Split(Utilities.NewLineChars, StringSplitOptions.RemoveEmptyEntries)) { string s = line.ToLower().Trim(); if (s.StartsWith("title:")) { textBoxTitle.Text = s.Remove(0, 6).Trim(); } else if (s.StartsWith("original script:")) { textBoxOriginalScript.Text = s.Remove(0, 16).Trim(); } else if (s.StartsWith("original translation:")) { textBoxTranslation.Text = s.Remove(0, 21).Trim(); } else if (s.StartsWith("original editing:")) { textBoxEditing.Text = s.Remove(0, 17).Trim(); } else if (s.StartsWith("original timing:")) { textBoxTiming.Text = s.Remove(0, 16).Trim(); } else if (s.StartsWith("synch point:")) { textBoxSyncPoint.Text = s.Remove(0, 12).Trim(); } else if (s.StartsWith("script updated by:")) { textBoxUpdatedBy.Text = s.Remove(0, 18).Trim(); } else if (s.StartsWith("update details:")) { textBoxUpdateDetails.Text = s.Remove(0, 15).Trim(); } else if (s.StartsWith("collisions:")) { if (s.Remove(0, 11).Trim() == "reverse") comboBoxCollision.SelectedIndex = 1; } else if (s.StartsWith("playresx:")) { int number; if (int.TryParse(s.Remove(0, 9).Trim(), out number)) numericUpDownVideoWidth.Value = number; } else if (s.StartsWith("playresy:")) { int number; if (int.TryParse(s.Remove(0, 9).Trim(), out number)) numericUpDownVideoHeight.Value = number; } else if (s.StartsWith("scaledborderandshadow:")) { checkBoxScaleBorderAndShadow.Checked = s.Remove(0, 22).Trim().ToLower() == "yes"; } } } groupBoxScript.Text = l.Script; labelTitle.Text = l.ScriptTitle; labelOriginalScript.Text = l.OriginalScript; labelTranslation.Text = l.Translation; labelEditing.Text = l.Editing; labelTiming.Text = l.Timing; labelSyncPoint.Text = l.SyncPoint; labelUpdatedBy.Text = l.UpdatedBy; labelUpdateDetails.Text = l.UpdateDetails; groupBoxResolution.Text = l.Resolution; labelVideoResolution.Text = l.VideoResolution; groupBoxOptions.Text = l.Options; labelCollision.Text = l.Collision; labelWrapStyle.Text = l.WrapStyle; checkBoxScaleBorderAndShadow.Text = l.ScaleBorderAndShadow; buttonOK.Text = Configuration.Settings.Language.General.Ok; buttonCancel.Text = Configuration.Settings.Language.General.Cancel; FixLargeFonts(); }
private void ResetHeader() { SubtitleFormat format; if (_isSubStationAlpha) format = new SubStationAlpha(); else format = new AdvancedSubStationAlpha(); var sub = new Subtitle(); string text = format.ToText(sub, string.Empty); string[] lineArray = text.Replace(Environment.NewLine, "\n").Split('\n'); var lines = new List<string>(); foreach (string line in lineArray) lines.Add(line); format.LoadSubtitle(sub, lines, string.Empty); Header = sub.Header; }
private void buttonRemoveAll_Click(object sender, EventArgs e) { listViewStyles.Items.Clear(); var sub = new Subtitle(); if (_isSubStationAlpha) { var ssa = new SubStationAlpha(); string text = ssa.ToText(sub, string.Empty); string[] lineArray = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); var lines = new List<string>(); foreach (string line in lineArray) lines.Add(line); ssa.LoadSubtitle(sub, lines, string.Empty); Header = Header.Remove(Header.IndexOf("[V4 Styles]")) + sub.Header.Substring(sub.Header.IndexOf("[V4 Styles]")); } else { var ass = new AdvancedSubStationAlpha(); string text = ass.ToText(sub, string.Empty); string[] lineArray = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); var lines = new List<string>(); foreach (string line in lineArray) lines.Add(line); ass.LoadSubtitle(sub, lines, string.Empty); Header = Header.Remove(Header.IndexOf("[V4+ Styles]")) + sub.Header.Substring(sub.Header.IndexOf("[V4+ Styles]")); } InitializeListView(); }
private void ResetHeader() { SubtitleFormat format; if (_isSubStationAlpha) format = new SubStationAlpha(); else format = new AdvancedSubStationAlpha(); var sub = new Subtitle(); string text = format.ToText(sub, string.Empty); var lines = new List<string>(); foreach (string line in text.SplitToLines()) lines.Add(line); format.LoadSubtitle(sub, lines, string.Empty); _header = sub.Header; }
internal static SubtitleFormat LoadMatroskaTextSubtitle(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska, List<MatroskaSubtitle> sub, Subtitle subtitle) { if (subtitle == null) throw new ArgumentNullException("subtitle"); subtitle.Paragraphs.Clear(); var isSsa = false; SubtitleFormat format = new SubRip(); if (matroskaSubtitleInfo.CodecPrivate.Contains("[script info]", StringComparison.OrdinalIgnoreCase)) { if (matroskaSubtitleInfo.CodecPrivate.Contains("[V4 Styles]", StringComparison.OrdinalIgnoreCase)) format = new SubStationAlpha(); else format = new AdvancedSubStationAlpha(); isSsa = true; } if (isSsa) { foreach (var p in LoadMatroskaSSA(matroskaSubtitleInfo, matroska.Path, format, sub).Paragraphs) { subtitle.Paragraphs.Add(p); } if (!string.IsNullOrEmpty(matroskaSubtitleInfo.CodecPrivate)) { bool eventsStarted = false; bool fontsStarted = false; bool graphicsStarted = false; var header = new StringBuilder(); foreach (string line in matroskaSubtitleInfo.CodecPrivate.Replace(Environment.NewLine, "\n").Split('\n')) { if (!eventsStarted && !fontsStarted && !graphicsStarted) { header.AppendLine(line); } if (line.TrimStart().StartsWith("dialog:", StringComparison.OrdinalIgnoreCase)) { eventsStarted = true; fontsStarted = false; graphicsStarted = false; } else if (line.Trim().Equals("[events]", StringComparison.OrdinalIgnoreCase)) { eventsStarted = true; fontsStarted = false; graphicsStarted = false; } else if (line.Trim().Equals("[fonts]", StringComparison.OrdinalIgnoreCase)) { eventsStarted = false; fontsStarted = true; graphicsStarted = false; } else if (line.Trim().Equals("[graphics]", StringComparison.OrdinalIgnoreCase)) { eventsStarted = false; fontsStarted = false; graphicsStarted = true; } } subtitle.Header = header.ToString().TrimEnd(); if (!subtitle.Header.Contains("[events]", StringComparison.OrdinalIgnoreCase)) { subtitle.Header += Environment.NewLine + Environment.NewLine + "[Events]" + Environment.NewLine; } } } else { foreach (var p in sub) { subtitle.Paragraphs.Add(new Paragraph(p.Text, p.Start, p.End)); } } subtitle.Renumber(); return format; }
private void ButtonStylesClick(object sender, EventArgs e) { SubStationAlphaStyles form = null; try { var assa = new AdvancedSubStationAlpha(); if (comboBoxSubtitleFormats.Text == assa.Name) { form = new SubStationAlphaStyles(new Subtitle(), assa); form.MakeOnlyOneStyle(); if (form.ShowDialog(this) == DialogResult.OK) { _assStyle = form.Header; } } else { var ssa = new SubStationAlpha(); if (comboBoxSubtitleFormats.Text == ssa.Name) { form = new SubStationAlphaStyles(new Subtitle(), ssa); if (form.ShowDialog(this) == DialogResult.OK) { _ssaStyle = form.Header; } } } } finally { if (form != null) { form.Dispose(); } } }
public void LineCount() { var target = new SubStationAlpha(); var subtitle = new Subtitle(); subtitle.Paragraphs.Add(new Paragraph("Line 1", 0, 3000)); subtitle.Paragraphs.Add(new Paragraph("Line 2", 4000, 7000)); subtitle.Paragraphs.Add(new Paragraph("Line 3", 8000, 11000)); subtitle.Paragraphs.Add(new Paragraph("Line 4", 12000, 15000)); int expected = subtitle.Paragraphs.Count; foreach (SubtitleFormat format in SubtitleFormat.AllSubtitleFormats) { if (format.GetType() != typeof(JsonType6) && format.IsTextBased) { format.BatchMode = true; string text = format.ToText(subtitle, "test"); var list = new List<string>(); foreach (string line in text.Replace("\r\n", "\n").Split('\n')) list.Add(line); var s2 = new Subtitle(); format.LoadSubtitle(s2, list, null); int actual = s2.Paragraphs.Count; Assert.AreEqual(expected, actual, format.FriendlyName); } } }
/// <summary> /// Initializes a new instance of the <see cref="SubStationAlphaProperties"/> class. /// </summary> /// <param name="subtitle"> /// The subtitle. /// </param> /// <param name="format"> /// The format. /// </param> /// <param name="videoFileName"> /// The video file name. /// </param> /// <param name="subtitleFileName"> /// The subtitle file name. /// </param> public SubStationAlphaProperties(Subtitle subtitle, SubtitleFormat format, string videoFileName, string subtitleFileName) { this.InitializeComponent(); this._subtitle = subtitle; this._isSubStationAlpha = format.Name == SubStationAlpha.NameOfFormat; this._videoFileName = videoFileName; var l = Configuration.Settings.Language.SubStationAlphaProperties; if (this._isSubStationAlpha) { this.Text = l.TitleSubstationAlpha; this.labelWrapStyle.Visible = false; this.comboBoxWrapStyle.Visible = false; this.checkBoxScaleBorderAndShadow.Visible = false; this.Height = this.Height - (this.comboBoxWrapStyle.Height + this.checkBoxScaleBorderAndShadow.Height + 8); } else { this.Text = l.Title; } this.comboBoxWrapStyle.SelectedIndex = 2; this.comboBoxCollision.SelectedIndex = 0; string header = subtitle.Header; if (subtitle.Header == null) { var ssa = new SubStationAlpha(); var sub = new Subtitle(); var lines = new List<string>(); foreach (string line in subtitle.ToText(ssa).SplitToLines()) { lines.Add(line); } string title = "Untitled"; if (!string.IsNullOrEmpty(subtitleFileName)) { title = Path.GetFileNameWithoutExtension(subtitleFileName); } else if (!string.IsNullOrEmpty(videoFileName)) { title = Path.GetFileNameWithoutExtension(videoFileName); } ssa.LoadSubtitle(sub, lines, title); header = sub.Header; } if (header != null) { foreach (string line in header.SplitToLines()) { string s = line.ToLowerInvariant().Trim(); if (s.StartsWith("title:")) { this.textBoxTitle.Text = s.Remove(0, 6).Trim(); } else if (s.StartsWith("original script:")) { this.textBoxOriginalScript.Text = s.Remove(0, 16).Trim(); } else if (s.StartsWith("original translation:")) { this.textBoxTranslation.Text = s.Remove(0, 21).Trim(); } else if (s.StartsWith("original editing:")) { this.textBoxEditing.Text = s.Remove(0, 17).Trim(); } else if (s.StartsWith("original timing:")) { this.textBoxTiming.Text = s.Remove(0, 16).Trim(); } else if (s.StartsWith("synch point:")) { this.textBoxSyncPoint.Text = s.Remove(0, 12).Trim(); } else if (s.StartsWith("script updated by:")) { this.textBoxUpdatedBy.Text = s.Remove(0, 18).Trim(); } else if (s.StartsWith("update details:")) { this.textBoxUpdateDetails.Text = s.Remove(0, 15).Trim(); } else if (s.StartsWith("collisions:")) { if (s.Remove(0, 11).Trim() == "reverse") { this.comboBoxCollision.SelectedIndex = 1; } } else if (s.StartsWith("playresx:")) { int number; if (int.TryParse(s.Remove(0, 9).Trim(), out number)) { this.numericUpDownVideoWidth.Value = number; } } else if (s.StartsWith("playresy:")) { int number; if (int.TryParse(s.Remove(0, 9).Trim(), out number)) { this.numericUpDownVideoHeight.Value = number; } } else if (s.StartsWith("scaledborderandshadow:")) { this.checkBoxScaleBorderAndShadow.Checked = s.Remove(0, 22).Trim().Equals("yes"); } } } this.groupBoxScript.Text = l.Script; this.labelTitle.Text = l.ScriptTitle; this.labelOriginalScript.Text = l.OriginalScript; this.labelTranslation.Text = l.Translation; this.labelEditing.Text = l.Editing; this.labelTiming.Text = l.Timing; this.labelSyncPoint.Text = l.SyncPoint; this.labelUpdatedBy.Text = l.UpdatedBy; this.labelUpdateDetails.Text = l.UpdateDetails; this.groupBoxResolution.Text = l.Resolution; this.labelVideoResolution.Text = l.VideoResolution; this.groupBoxOptions.Text = l.Options; this.labelCollision.Text = l.Collision; this.labelWrapStyle.Text = l.WrapStyle; this.checkBoxScaleBorderAndShadow.Text = l.ScaleBorderAndShadow; this.buttonOK.Text = Configuration.Settings.Language.General.Ok; this.buttonCancel.Text = Configuration.Settings.Language.General.Cancel; Utilities.FixLargeFonts(this, this.buttonCancel); }
/// <summary> /// The get default header. /// </summary> /// <returns> /// The <see cref="string"/>. /// </returns> private string GetDefaultHeader() { SubtitleFormat format; if (this._isSubStationAlpha) { format = new SubStationAlpha(); } else { format = new AdvancedSubStationAlpha(); } var sub = new Subtitle(); string text = format.ToText(sub, string.Empty); var lines = new List<string>(); foreach (string line in text.SplitToLines()) { lines.Add(line); } format.LoadSubtitle(sub, lines, string.Empty); return sub.Header.Trim(); }
public void LineContent() { var target = new SubStationAlpha(); var subtitle = new Subtitle(); subtitle.Paragraphs.Add(new Paragraph("Line 1", 0, 3000)); subtitle.Paragraphs.Add(new Paragraph("Line 2", 4000, 7000)); subtitle.Paragraphs.Add(new Paragraph("Line 3", 8000, 11000)); subtitle.Paragraphs.Add(new Paragraph("Line 4", 12000, 15000)); foreach (SubtitleFormat format in SubtitleFormat.AllSubtitleFormats) { format.BatchMode = true; string text = format.ToText(subtitle, "test"); var list = new List<string>(); foreach (string line in text.Replace("\r\n", "\n").Split('\n')) list.Add(line); var s2 = new Subtitle(); format.LoadSubtitle(s2, list, null); if (s2.Paragraphs.Count == 4) { Assert.AreEqual(subtitle.Paragraphs[0].Text, s2.Paragraphs[0].Text, format.FriendlyName); Assert.AreEqual(subtitle.Paragraphs[3].Text, s2.Paragraphs[3].Text, format.FriendlyName); } } }