예제 #1
0
        private bool ImportSubtitleFromTransportStream(string fileName)
        {
            this.ShowStatus(this._language.ParsingTransportStream);
            this.Refresh();
            var tsParser = new TransportStreamParser();
            tsParser.Parse(fileName, (pos, total) => this.UpdateProgress(pos, total, this._language.ParsingTransportStreamFile));
            this.ShowStatus(string.Empty);
            TaskbarList.SetProgressState(this.Handle, TaskbarButtonProgressFlags.NoProgress);

            if (tsParser.SubtitlePacketIds.Count == 0)
            {
                MessageBox.Show(this._language.NoSubtitlesFound);
                return false;
            }

            int packedId = tsParser.SubtitlePacketIds[0];
            if (tsParser.SubtitlePacketIds.Count > 1)
            {
                using (var subChooser = new TransportStreamSubtitleChooser())
                {
                    subChooser.Initialize(tsParser, fileName);
                    if (subChooser.ShowDialog(this) == DialogResult.Cancel)
                    {
                        return false;
                    }

                    packedId = tsParser.SubtitlePacketIds[subChooser.SelectedIndex];
                }
            }

            var subtitles = tsParser.GetDvbSubtitles(packedId);

            using (var formSubOcr = new VobSubOcr())
            {
                formSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, fileName);
                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    this.MakeHistoryForUndo(this._language.BeforeImportingDvdSubtitle);

                    this._subtitle.Paragraphs.Clear();
                    this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                    this._subtitle.WasLoadedWithFrameNumbers = false;
                    this._subtitle.CalculateFrameNumbersFromTimeCodes(this.CurrentFrameRate);
                    foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs)
                    {
                        this._subtitle.Paragraphs.Add(p);
                    }

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

                    this._fileName = string.Empty;
                    this.Text = this.Title;

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

                return false;
            }
        }
        /// <summary>
        /// The initialize.
        /// </summary>
        /// <param name="tsParser">
        /// The ts parser.
        /// </param>
        /// <param name="fileName">
        /// The file name.
        /// </param>
        internal void Initialize(TransportStreamParser tsParser, string fileName)
        {
            this._tsParser = tsParser;
            this.Text = string.Format(Configuration.Settings.Language.TransportStreamSubtitleChooser.Title, fileName);

            foreach (int id in tsParser.SubtitlePacketIds)
            {
                this.listBoxTracks.Items.Add(string.Format(Configuration.Settings.Language.TransportStreamSubtitleChooser.PidLine, id, tsParser.GetDvbSubtitles(id).Count));
            }

            this.listBoxTracks.SelectedIndex = 0;
        }