示例#1
0
        private bool InitializeSubIdx(string vobSubFileName)
        {
            var vobSubParser = new VobSubParser(true);
            string idxFileName = Path.ChangeExtension(vobSubFileName, ".idx");
            vobSubParser.OpenSubIdx(vobSubFileName, idxFileName);
            _vobSubMergedPackist = vobSubParser.MergeVobSubPacks();
            _palette = vobSubParser.IdxPalette;
            vobSubParser.VobSubPacks.Clear();

            var 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)
            {
                using (var chooseLanguage = new DvdSubRipChooseLanguage())
                {
                    if (ShowInTaskbar)
                    {
                        chooseLanguage.Icon = (Icon)Icon.Clone();
                        chooseLanguage.ShowInTaskbar = true;
                        chooseLanguage.ShowIcon = true;
                    }
                    chooseLanguage.Initialize(_vobSubMergedPackist, _palette, vobSubParser.IdxLanguages, string.Empty);
                    Form form = _main;
                    if (form == null)
                        form = this;
                    chooseLanguage.Activate();
                    if (chooseLanguage.ShowDialog(form) == DialogResult.OK)
                    {
                        _vobSubMergedPackist = chooseLanguage.SelectedVobSubMergedPacks;
                        SetTesseractLanguageFromLanguageString(chooseLanguage.SelectedLanguageString);
                        _importLanguageString = chooseLanguage.SelectedLanguageString;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            return true;
        }
示例#2
0
        private void ToolStripMenuItemImportDvdSubtitlesClick(object sender, EventArgs e)
        {
            if (!ContinueNewOrExit())
            {
                return;
            }

            using (var formSubRip = new DvdSubRip(Handle))
            {
                if (formSubRip.ShowDialog(this) == DialogResult.OK)
                {
                    using (var showSubtitles = new DvdSubRipChooseLanguage())
                    {
                        showSubtitles.Initialize(formSubRip.MergedVobSubPacks, formSubRip.Palette, formSubRip.Languages, formSubRip.SelectedLanguage);
                        if (formSubRip.Languages.Count == 1 || showSubtitles.ShowDialog(this) == DialogResult.OK)
                        {
                            using (var formSubOcr = new VobSubOcr())
                            {
                                var subs = formSubRip.MergedVobSubPacks;
                                if (showSubtitles.SelectedVobSubMergedPacks != null)
                                    subs = showSubtitles.SelectedVobSubMergedPacks;
                                formSubOcr.Initialize(subs, formSubRip.Palette, Configuration.Settings.VobSubOcr, formSubRip.SelectedLanguage);
                                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                                {
                                    MakeHistoryForUndo(_language.BeforeImportingDvdSubtitle);
                                    FileNew();
                                    _subtitle.Paragraphs.Clear();
                                    SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                                    _subtitle.WasLoadedWithFrameNumbers = false;
                                    _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                                    foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs)
                                    {
                                        _subtitle.Paragraphs.Add(p);
                                    }

                                    ShowSource();
                                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                                    _subtitleListViewIndex = -1;
                                    SubtitleListview1.FirstVisibleIndex = -1;
                                    SubtitleListview1.SelectIndexAndEnsureVisible(0, true);

                                    _fileName = string.Empty;
                                    Text = Title;

                                    Configuration.Settings.Save();
                                }
                            }
                        }
                    }
                }
            }
        }