예제 #1
0
파일: Main.cs 프로젝트: m1croN/subtitleedit
        private bool ImportSubtitleFromTransportStream(string fileName)
        {
            ShowStatus(_language.ParsingTransportStream);
            Refresh();
            var tsParser = new TransportStreamParser();
            tsParser.Parse(fileName, (pos, total) => UpdateProgress(pos, total, _language.ParsingTransportStreamFile));
            ShowStatus(string.Empty);
            TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);

            if (tsParser.SubtitlePacketIds.Count == 0)
            {
                MessageBox.Show(_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)
                {
                    MakeHistoryForUndo(_language.BeforeImportingDvdSubtitle);

                    _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);

                    _fileName = string.Empty;
                    Text = Title;

                    Configuration.Settings.Save();
                    return true;
                }
                return false;
            }
        }
예제 #2
0
        private bool ImportSubtitleFromTransportStream(string fileName)
        {
            if (string.IsNullOrEmpty(_language.ParsingTransportStream))
                ShowStatus("Parsing transport stream - please wait...");
            else
                ShowStatus(_language.ParsingTransportStream);
            Refresh();
            var tsParser = new Nikse.SubtitleEdit.Logic.TransportStream.TransportStreamParser();
            tsParser.ParseTsFile(fileName);
            ShowStatus(string.Empty);

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

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

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

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

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

                _fileName = string.Empty;
                Text = Title;

                Configuration.Settings.Save();
                _formPositionsAndSizes.SavePositionAndSize(formSubOcr);
                return true;
            }
            _formPositionsAndSizes.SavePositionAndSize(formSubOcr);
            return false;
        }