public void VobSubWriteAndReadTwoBitmaps() { string fileName = Guid.NewGuid() + ".sub"; using (var writer = new VobSubWriter(fileName, 800, 600, 10, 10, 32, Color.White, Color.Black, true, "English", "en")) { var p1 = new Paragraph("Line1", 0, 1000); var p2 = new Paragraph("Line2", 2000, 3000); writer.WriteParagraph(p1, new Bitmap(200, 20), ContentAlignment.BottomCenter); writer.WriteParagraph(p2, new Bitmap(200, 20), ContentAlignment.BottomCenter); } var reader = new VobSubParser(true); reader.Open(fileName); var list = reader.MergeVobSubPacks(); Assert.IsTrue(list.Count == 2); }
private bool InitializeSubIdx(string vobSubFileName) { VobSubParser vobSubParser = new VobSubParser(true); string idxFileName = Path.ChangeExtension(vobSubFileName, ".idx"); vobSubParser.OpenSubIdx(vobSubFileName, idxFileName); _vobSubMergedPackist = vobSubParser.MergeVobSubPacks(); _palette = vobSubParser.IdxPalette; vobSubParser.VobSubPacks.Clear(); List<int> languageStreamIds = new List<int>(); foreach (var pack in _vobSubMergedPackist) { if (pack.SubPicture.Delay.TotalMilliseconds > 500 && !languageStreamIds.Contains(pack.StreamId)) languageStreamIds.Add(pack.StreamId); } if (languageStreamIds.Count > 1) { DvdSubRipChooseLanguage ChooseLanguage = new DvdSubRipChooseLanguage(); ChooseLanguage.Initialize(_vobSubMergedPackist, _palette, vobSubParser.IdxLanguages, string.Empty); Form form = _main; if (form == null) form = this; ChooseLanguage.Activate(); if (ChooseLanguage.ShowDialog(form) == System.Windows.Forms.DialogResult.OK) { _vobSubMergedPackist = ChooseLanguage.SelectedVobSubMergedPacks; SetTesseractLanguageFromLanguageString(ChooseLanguage.SelectedLanguageString); _importLanguageString = ChooseLanguage.SelectedLanguageString; } else { return false; } } return true; }
private void ButtonStartRippingClick(object sender, EventArgs e) { if (buttonStartRipping.Text == _language.Abort) { _abort = true; buttonStartRipping.Text = _language.StartRipping; return; } _abort = false; buttonStartRipping.Text = _language.Abort; _lastPresentationTimeStamp = 0; _lastVobPresentationTimeStamp = 0; _lastNavEndPts = 0; _accumulatedPresentationTimeStamp = 0; progressBarRip.Visible = true; var ms = new MemoryStream(); int i = 0; foreach (string vobFileName in listBoxVobFiles.Items) { i++; labelStatus.Text = string.Format(_language.RippingVobFileXofYZ, Path.GetFileName(vobFileName), i, listBoxVobFiles.Items.Count); Refresh(); Application.DoEvents(); if (!_abort) RipSubtitles(vobFileName, ms, i-1); // Rip/demux subtitle vob packs } progressBarRip.Visible = false; buttonStartRipping.Enabled = false; if (_abort) { labelStatus.Text = _language.AbortedByUser; buttonStartRipping.Text = _language.StartRipping; buttonStartRipping.Enabled = true; return; } labelStatus.Text = string.Format(_language.ReadingSubtitleData); Refresh(); Application.DoEvents(); var vobSub = new VobSubParser(radioButtonPal.Checked); vobSub.Open(ms); ms.Close(); labelStatus.Text = string.Empty; MergedVobSubPacks = vobSub.MergeVobSubPacks(); // Merge splitted-packs to whole-packs if (MergedVobSubPacks.Count == 0) { MessageBox.Show(Configuration.Settings.Language.Main.NoSubtitlesFound); buttonStartRipping.Text = _language.StartRipping; buttonStartRipping.Enabled = true; return; } Languages = new List<string>(); for (int k = 0; k < comboBoxLanguages.Items.Count; k++) Languages.Add(string.Format("{0} (0x{1:x})", comboBoxLanguages.Items[k], k + 32)); buttonStartRipping.Text = _language.StartRipping; buttonStartRipping.Enabled = true; DialogResult = DialogResult.OK; }
/// <summary> /// The button start ripping click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void ButtonStartRippingClick(object sender, EventArgs e) { if (this.buttonStartRipping.Text == this._language.Abort) { this._abort = true; this.buttonStartRipping.Text = this._language.StartRipping; return; } this._abort = false; this.buttonStartRipping.Text = this._language.Abort; this._lastPresentationTimestamp = 0; this._lastVobPresentationTimestamp = 0; this._lastNavEndPts = 0; this._accumulatedPresentationTimestamp = 0; this.progressBarRip.Visible = true; var ms = new MemoryStream(); int i = 0; foreach (string vobFileName in this.listBoxVobFiles.Items) { i++; this.labelStatus.Text = string.Format(this._language.RippingVobFileXofYZ, Path.GetFileName(vobFileName), i, this.listBoxVobFiles.Items.Count); this.Refresh(); Application.DoEvents(); if (!this._abort) { this.RipSubtitles(vobFileName, ms, i - 1); // Rip/demux subtitle vob packs } } this.progressBarRip.Visible = false; TaskbarList.SetProgressState(this._taskbarFormHandle, TaskbarButtonProgressFlags.NoProgress); this.buttonStartRipping.Enabled = false; if (this._abort) { this.labelStatus.Text = this._language.AbortedByUser; this.buttonStartRipping.Text = this._language.StartRipping; this.buttonStartRipping.Enabled = true; return; } this.labelStatus.Text = string.Format(this._language.ReadingSubtitleData); this.Refresh(); Application.DoEvents(); var vobSub = new VobSubParser(this.radioButtonPal.Checked); vobSub.Open(ms); ms.Close(); this.labelStatus.Text = string.Empty; this.MergedVobSubPacks = vobSub.MergeVobSubPacks(); // Merge splitted-packs to whole-packs if (this.MergedVobSubPacks.Count == 0) { MessageBox.Show(Configuration.Settings.Language.Main.NoSubtitlesFound); this.buttonStartRipping.Text = this._language.StartRipping; this.buttonStartRipping.Enabled = true; return; } this.Languages = new List<string>(); for (int k = 0; k < this.comboBoxLanguages.Items.Count; k++) { this.Languages.Add(this.comboBoxLanguages.Items[k].ToString()); } this.buttonStartRipping.Text = this._language.StartRipping; this.buttonStartRipping.Enabled = true; this.DialogResult = DialogResult.OK; }
/// <summary> /// The initialize sub idx. /// </summary> /// <param name="vobSubFileName"> /// The vob sub file name. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool InitializeSubIdx(string vobSubFileName) { var vobSubParser = new VobSubParser(true); string idxFileName = Path.ChangeExtension(vobSubFileName, ".idx"); vobSubParser.OpenSubIdx(vobSubFileName, idxFileName); this._vobSubMergedPackist = vobSubParser.MergeVobSubPacks(); this._palette = vobSubParser.IdxPalette; vobSubParser.VobSubPacks.Clear(); var languageStreamIds = new List<int>(); foreach (var pack in this._vobSubMergedPackist) { if (pack.SubPicture.Delay.TotalMilliseconds > 500 && !languageStreamIds.Contains(pack.StreamId)) { languageStreamIds.Add(pack.StreamId); } } if (languageStreamIds.Count > 1) { using (var chooseLanguage = new DvdSubRipChooseLanguage()) { if (this.ShowInTaskbar) { chooseLanguage.Icon = (Icon)this.Icon.Clone(); chooseLanguage.ShowInTaskbar = true; chooseLanguage.ShowIcon = true; } chooseLanguage.Initialize(this._vobSubMergedPackist, this._palette, vobSubParser.IdxLanguages, string.Empty); Form form = this._main; if (form == null) { form = this; } chooseLanguage.Activate(); if (chooseLanguage.ShowDialog(form) == DialogResult.OK) { this._vobSubMergedPackist = chooseLanguage.SelectedVobSubMergedPacks; this.SetTesseractLanguageFromLanguageString(chooseLanguage.SelectedLanguageString); this._importLanguageString = chooseLanguage.SelectedLanguageString; } else { return false; } } } return true; }