当前位置: 首页>>代码示例>>C#>>正文


C# Subtitle.ToText方法代码示例

本文整理汇总了C#中Subtitle.ToText方法的典型用法代码示例。如果您正苦于以下问题:C# Subtitle.ToText方法的具体用法?C# Subtitle.ToText怎么用?C# Subtitle.ToText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subtitle的用法示例。


在下文中一共展示了Subtitle.ToText方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReloadFromSourceView

        private void ReloadFromSourceView()
        {
            if (_sourceViewChange)
            {
                SaveSubtitleListviewIndices();
                if (!string.IsNullOrWhiteSpace(textBoxSource.Text))
                {
                    SubtitleFormat format = GetCurrentSubtitleFormat();
                    var list = textBoxSource.Lines.ToList();
                    format = new Subtitle().ReloadLoadSubtitle(list, null, format);
                    if (format == null)
                    {
                        MessageBox.Show(_language.UnableToParseSourceView);
                        return;
                    }
                    _sourceViewChange = false;
                    MakeHistoryForUndo(_language.BeforeChangesMadeInSourceView);
                    _subtitle.ReloadLoadSubtitle(list, null, format);
                    if (format.IsFrameBased)
                        _subtitle.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
                    int index = 0;
                    foreach (object obj in comboBoxSubtitleFormats.Items)
                    {
                        if (obj.ToString() == format.FriendlyName)
                            comboBoxSubtitleFormats.SelectedIndex = index;
                        index++;
                    }

                    var formatType = format.GetType();
                    if (formatType == typeof(AdvancedSubStationAlpha) || formatType == typeof(SubStationAlpha))
                    {
                        string errors = AdvancedSubStationAlpha.CheckForErrors(_subtitle.Header);
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(SubRip))
                    {
                        string errors = (format as SubRip).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(MicroDvd))
                    {
                        string errors = (format as MicroDvd).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(DCinemaSmpte2007))
                    {
                        format.ToText(_subtitle, string.Empty);
                        string errors = (format as DCinemaSmpte2007).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(DCinemaSmpte2010))
                    {
                        format.ToText(_subtitle, string.Empty);
                        string errors = (format as DCinemaSmpte2010).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    _sourceViewChange = false;
                    MakeHistoryForUndo(_language.BeforeChangesMadeInSourceView);
                    _sourceViewChange = false;
                    _subtitle.Paragraphs.Clear();
                }
                _subtitleListViewIndex = -1;
                SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                RestoreSubtitleListviewIndices();
            }
        }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:74,代码来源:Main.cs

示例2: SubStationAlphaProperties

        public SubStationAlphaProperties(Subtitle subtitle, SubtitleFormat format, string videoFileName, string subtitleFileName)
        {
            InitializeComponent();
            _subtitle = subtitle;
            _isSubStationAlpha = format.Name == SubStationAlpha.NameOfFormat;
            _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)
            {
                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:"))
                    {
                        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().Equals("yes");
                    }
                }
//.........这里部分代码省略.........
开发者ID:leeyikkong,项目名称:testing,代码行数:101,代码来源:SubStationAlphaProperties.cs

示例3: ToolStripMenuItemSaveSelectedLinesClick

        private void ToolStripMenuItemSaveSelectedLinesClick(object sender, EventArgs e)
        {
            var newSub = new Subtitle(_subtitle);
            newSub.Header = _subtitle.Header;
            newSub.Paragraphs.Clear();
            foreach (int index in SubtitleListview1.SelectedIndices)
                newSub.Paragraphs.Add(_subtitle.Paragraphs[index]);

            SubtitleFormat currentFormat = GetCurrentSubtitleFormat();
            UiUtil.SetSaveDialogFilter(saveFileDialog1, currentFormat);
            saveFileDialog1.Title = _language.SaveSubtitleAs;
            saveFileDialog1.DefaultExt = "*" + currentFormat.Extension;
            saveFileDialog1.AddExtension = true;
            if (!string.IsNullOrEmpty(_fileName))
                saveFileDialog1.InitialDirectory = Path.GetDirectoryName(_fileName);

            if (saveFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                int index = 0;
                foreach (SubtitleFormat format in SubtitleFormat.AllSubtitleFormats)
                {
                    if (saveFileDialog1.FilterIndex == index + 1)
                    {
                        if (format.IsTextBased)
                        {
                            // only allow current extension or ".txt"
                            string fileName = saveFileDialog1.FileName;
                            string ext = Path.GetExtension(fileName).ToLowerInvariant();
                            bool extOk = ext.Equals(format.Extension, StringComparison.OrdinalIgnoreCase) || format.AlternateExtensions.Contains(ext) || ext == ".txt";
                            if (!extOk)
                            {
                                if (fileName.EndsWith('.'))
                                    fileName = fileName.TrimEnd('.');
                                fileName += format.Extension;
                            }

                            string allText = newSub.ToText(format);
                            File.WriteAllText(fileName, allText, GetCurrentEncoding());
                            ShowStatus(string.Format(_language.XLinesSavedAsY, newSub.Paragraphs.Count, fileName));
                            return;
                        }
                    }
                    index++;
                }
            }
        }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:46,代码来源:Main.cs

示例4: SaveSubtitle

        private DialogResult SaveSubtitle(SubtitleFormat format)
        {
            if (string.IsNullOrEmpty(_fileName) || _converted)
                return FileSaveAs(false);

            try
            {
                if (format != null && !format.IsTextBased)
                {
                    if (format.GetType() == typeof(Ebu))
                    {
                        Ebu.Save(_fileName, _subtitle);
                    }
                    return DialogResult.OK;
                }

                string allText = _subtitle.ToText(format);

                // Seungki begin
                if (_splitDualSami && _subtitleAlternate != null)
                {
                    var s = new Subtitle(_subtitle);
                    foreach (var p in _subtitleAlternate.Paragraphs)
                        s.Paragraphs.Add(p);
                    allText = s.ToText(format);
                }
                // Seungki end

                var currentEncoding = GetCurrentEncoding();
                bool isUnicode = currentEncoding == Encoding.Unicode || currentEncoding == Encoding.UTF32 || currentEncoding == Encoding.UTF7 || currentEncoding == Encoding.UTF8;
                if (!isUnicode && (allText.Contains(new[] { '♪', '♫', '♥', '—', '―', '…' }))) // ANSI & music/unicode symbols
                {
                    if (MessageBox.Show(string.Format(_language.UnicodeMusicSymbolsAnsiWarning), Title, MessageBoxButtons.YesNo) == DialogResult.No)
                        return DialogResult.No;
                }

                if (!isUnicode)
                {
                    allText = NormalizeUnicode(allText);
                }

                bool containsNegativeTime = false;
                foreach (var p in _subtitle.Paragraphs)
                {
                    if (p.StartTime.TotalMilliseconds < 0 || p.EndTime.TotalMilliseconds < 0)
                    {
                        containsNegativeTime = true;
                        break;
                    }
                }
                if (containsNegativeTime)
                {
                    if (MessageBox.Show(_language.NegativeTimeWarning, Title, MessageBoxButtons.YesNo) == DialogResult.No)
                        return DialogResult.No;
                }

                if (File.Exists(_fileName))
                {
                    var fileInfo = new FileInfo(_fileName);
                    var fileOnDisk = fileInfo.LastWriteTime;
                    if (_fileDateTime != fileOnDisk && _fileDateTime != new DateTime())
                    {
                        if (MessageBox.Show(string.Format(_language.OverwriteModifiedFile,
                            _fileName, fileOnDisk.ToShortDateString(), fileOnDisk.ToString("HH:mm:ss"),
                            Environment.NewLine, _fileDateTime.ToShortDateString(), _fileDateTime.ToString("HH:mm:ss")),
                            Title + " - " + _language.FileOnDiskModified, MessageBoxButtons.YesNo) == DialogResult.No)
                            return DialogResult.No;
                    }
                    if (fileInfo.IsReadOnly)
                    {
                        MessageBox.Show(string.Format(_language.FileXIsReadOnly, _fileName));
                        return DialogResult.No;
                    }
                }

                if ((format.GetType() == typeof(WebVTT) || format.GetType() == typeof(WebVTTFileWithLineNumber)))
                {
                    SetEncoding(Encoding.UTF8);
                    currentEncoding = Encoding.UTF8;
                }

                if (ModifierKeys == (Keys.Control | Keys.Shift))
                    allText = allText.Replace("\r\n", "\n");

                if (format.GetType() == typeof(ItunesTimedText) || format.GetType() == typeof(ScenaristClosedCaptions) || format.GetType() == typeof(ScenaristClosedCaptionsDropFrame))
                {
                    var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
                    using (var file = new StreamWriter(_fileName, false, outputEnc)) // open file with encoding
                    {
                        file.Write(allText);
                    }
                }
                else if (currentEncoding == Encoding.UTF8 && (format.GetType() == typeof(TmpegEncAW5) || format.GetType() == typeof(TmpegEncXml)))
                {
                    var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
                    using (var file = new StreamWriter(_fileName, false, outputEnc)) // open file with encoding
                    {
                        file.Write(allText);
                    }
                }
//.........这里部分代码省略.........
开发者ID:m1croN,项目名称:subtitleedit,代码行数:101,代码来源:Main.cs

示例5: joinSessionToolStripMenuItem_Click

        private void joinSessionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _networkSession = new NikseWebServiceSession(_subtitle, _subtitleAlternate, TimerWebServiceTick, OnUpdateUserLogEntries);
            using (var networkJoin = new NetworkJoin())
            {
                networkJoin.Initialize(_networkSession);

                if (networkJoin.ShowDialog(this) == DialogResult.OK)
                {
                    _subtitle = _networkSession.Subtitle;
                    _subtitleAlternate = _networkSession.OriginalSubtitle;
                    if (_subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
                        SubtitleListview1.ShowAlternateTextColumn(_languageGeneral.OriginalText);
                    _fileName = networkJoin.FileName;
                    SetTitle();
                    Text = Title;
                    toolStripStatusNetworking.Visible = true;
                    toolStripStatusNetworking.Text = _language.NetworkMode;
                    EnableDisableControlsNotWorkingInNetworkMode(false);
                    _networkSession.AppendToLog(string.Format(_language.XStartedSessionYAtZ, _networkSession.CurrentUser.UserName, _networkSession.SessionId, DateTime.Now.ToLongTimeString()));
                    SubtitleListview1.ShowExtraColumn(_language.UserAndAction);
                    SubtitleListview1.AutoSizeAllColumns(this);
                    _subtitleListViewIndex = -1;
                    _oldSelectedParagraph = null;

                    if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
                    {
                        buttonUnBreak.Visible = false;
                        buttonAutoBreak.Visible = false;
                        buttonSplitLine.Visible = false;

                        textBoxListViewText.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom;
                        textBoxListViewText.Width = (groupBoxEdit.Width - (textBoxListViewText.Left + 10)) / 2;
                        textBoxListViewTextAlternate.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom;
                        textBoxListViewTextAlternate.Left = textBoxListViewText.Left + textBoxListViewText.Width + 3;
                        textBoxListViewTextAlternate.Width = textBoxListViewText.Width;
                        textBoxListViewTextAlternate.Visible = true;
                        labelAlternateText.Text = _languageGeneral.OriginalText;
                        labelAlternateText.Visible = true;
                        labelAlternateCharactersPerSecond.Visible = true;
                        labelTextAlternateLineLengths.Visible = true;
                        labelAlternateSingleLine.Visible = true;
                        labelTextAlternateLineTotal.Visible = true;

                        labelCharactersPerSecond.Left = textBoxListViewText.Left + (textBoxListViewText.Width - labelCharactersPerSecond.Width);
                        labelTextLineTotal.Left = textBoxListViewText.Left + (textBoxListViewText.Width - labelTextLineTotal.Width);
                        AddAlternate();
                        Main_Resize(null, null);
                        _changeAlternateSubtitleToString = _subtitleAlternate.ToText(new SubRip()).Trim();
                    }
                    else
                    {
                        RemoveAlternate(false);
                    }
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                    SubtitleListview1.SelectIndexAndEnsureVisible(0);
                    TimerWebServiceTick(null, null);
                }
                else
                {
                    _networkSession = null;
                }
            }
        }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:64,代码来源:Main.cs

示例6: ToolStripMenuItemCopySourceTextClick

 private void ToolStripMenuItemCopySourceTextClick(object sender, EventArgs e)
 {
     var selectedLines = new Subtitle(_subtitle);
     selectedLines.Paragraphs.Clear();
     foreach (int index in SubtitleListview1.SelectedIndices)
         selectedLines.Paragraphs.Add(_subtitle.Paragraphs[index]);
     Clipboard.SetText(selectedLines.ToText(GetCurrentSubtitleFormat()));
 }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:8,代码来源:Main.cs

示例7: SubtitleListview1KeyDown

        private void SubtitleListview1KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.C && e.Modifiers == Keys.Control) //Ctrl+c = Copy to clipboard
            {
                var tmp = new Subtitle();
                foreach (int i in SubtitleListview1.SelectedIndices)
                {
                    var p = _subtitle.GetParagraphOrDefault(i);
                    if (p != null)
                        tmp.Paragraphs.Add(new Paragraph(p));
                }
                if (tmp.Paragraphs.Count > 0)
                {
                    Clipboard.SetText(tmp.ToText(new SubRip()));
                }
                e.SuppressKeyPress = true;
            }
            else if (e.KeyData == _mainListViewCopyText)
            {
                var sb = new StringBuilder();
                foreach (int i in SubtitleListview1.SelectedIndices)
                {
                    var p = _subtitle.GetParagraphOrDefault(i);
                    if (p != null)
                        sb.AppendLine(p.Text + Environment.NewLine);
                }
                if (sb.Length > 0)
                {
                    Clipboard.SetText(sb.ToString().Trim());
                }
                e.SuppressKeyPress = true;
            }
            else if (e.KeyData == _mainListViewAutoDuration)
            {
                MakeAutoDurationSelectedLines();
            }
            else if (e.KeyData == _mainListViewFocusWaveform)
            {
                if (audioVisualizer.CanFocus)
                {
                    audioVisualizer.Focus();
                    e.SuppressKeyPress = true;
                }
            }
            else if (e.KeyData == _mainListViewGoToNextError)
            {
                GoToNextSynaxError();
                e.SuppressKeyPress = true;
            }
            else if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control) //Ctrl+vPaste from clipboard
            {
                if (Clipboard.ContainsText())
                {
                    var text = Clipboard.GetText();
                    var tmp = new Subtitle();
                    var format = new SubRip();
                    var list = new List<string>(text.SplitToLines());
                    format.LoadSubtitle(tmp, list, null);
                    if (SubtitleListview1.SelectedItems.Count == 1 && tmp.Paragraphs.Count > 0)
                    {
                        MakeHistoryForUndo(_language.BeforeInsertLine);
                        _makeHistoryPaused = true;
                        Paragraph lastParagraph = null;
                        Paragraph lastTempParagraph = null;
                        foreach (var p in tmp.Paragraphs)
                        {
                            InsertAfter();
                            textBoxListViewText.Text = p.Text;
                            if (lastParagraph != null)
                            {
                                double millisecondsBetween = p.StartTime.TotalMilliseconds - lastTempParagraph.EndTime.TotalMilliseconds;
                                timeUpDownStartTime.TimeCode = new TimeCode(lastParagraph.EndTime.TotalMilliseconds + millisecondsBetween);
                            }
                            SetDurationInSeconds(p.Duration.TotalSeconds);
                            lastParagraph = _subtitle.GetParagraphOrDefault(_subtitleListViewIndex);
                            lastTempParagraph = p;
                        }
                        RestartHistory();
                    }
                    else if (SubtitleListview1.Items.Count == 0 && tmp.Paragraphs.Count > 0)
                    { // insert into empty subtitle
                        MakeHistoryForUndo(_language.BeforeInsertLine);
                        foreach (var p in tmp.Paragraphs)
                        {
                            _subtitle.Paragraphs.Add(p);
                        }
                        SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                        SubtitleListview1.SelectIndexAndEnsureVisible(0, true);
                    }
                    else if (SubtitleListview1.Items.Count > 1 && tmp.Paragraphs.Count > 0)
                    {
                        // multiple lines selected - first delete, then insert
                        int firstIndex = FirstSelectedIndex;
                        if (firstIndex >= 0)
                        {
                            MakeHistoryForUndo(_language.BeforeInsertLine);
                            _makeHistoryPaused = true;

                            DeleteSelectedLines();
                            foreach (var p in tmp.Paragraphs)
//.........这里部分代码省略.........
开发者ID:m1croN,项目名称:subtitleedit,代码行数:101,代码来源:Main.cs

示例8: SavePart

        private void SavePart(Subtitle part, string title, string name)
        {
            saveFileDialog1.Title = title;
            saveFileDialog1.FileName = name;
            UiUtil.SetSaveDialogFilter(saveFileDialog1, _format);
            saveFileDialog1.DefaultExt = "*" + _format.Extension;
            saveFileDialog1.AddExtension = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string fileName = saveFileDialog1.FileName;

                try
                {
                    if (File.Exists(fileName))
                        File.Delete(fileName);

                    int index = 0;
                    foreach (SubtitleFormat format in SubtitleFormat.AllSubtitleFormats)
                    {
                        if (saveFileDialog1.FilterIndex == index + 1)
                        {
                            if (format.IsFrameBased)
                                part.CalculateFrameNumbersFromTimeCodesNoCheck(Configuration.Settings.General.CurrentFrameRate);
                            File.WriteAllText(fileName, part.ToText(format), _encoding);
                        }
                        index++;
                    }
                }
                catch
                {
                    MessageBox.Show(string.Format(Configuration.Settings.Language.SplitSubtitle.UnableToSaveFileX, fileName));
                }
            }
        }
开发者ID:mgziminsky,项目名称:subtitleedit,代码行数:35,代码来源:SplitSubtitle.cs

示例9: BatchConvertSave

        internal static bool BatchConvertSave(string toFormat, string offset, Encoding targetEncoding, string outputFolder, int count, ref int converted, ref int errors, IList<SubtitleFormat> formats, string fileName, Subtitle sub, SubtitleFormat format, bool overwrite, string pacCodePage, double? targetFrameRate)
        {
            double oldFrameRate = Configuration.Settings.General.CurrentFrameRate;
            try
            {
                // adjust offset
                if (!string.IsNullOrEmpty(offset) && (offset.StartsWith("/offset:") || offset.StartsWith("offset:")))
                {
                    string[] parts = offset.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length == 5)
                    {
                        try
                        {
                            var ts = new TimeSpan(0, int.Parse(parts[1].TrimStart('-')), int.Parse(parts[2]), int.Parse(parts[3]), int.Parse(parts[4]));
                            if (parts[1].StartsWith('-'))
                                sub.AddTimeToAllParagraphs(ts.Negate());
                            else
                                sub.AddTimeToAllParagraphs(ts);
                        }
                        catch
                        {
                            Console.Write(" (unable to read offset " + offset + ")");
                        }
                    }
                }

                // adjust frame rate
                if (targetFrameRate.HasValue)
                {
                    sub.ChangeFrameRate(Configuration.Settings.General.CurrentFrameRate, targetFrameRate.Value);
                    Configuration.Settings.General.CurrentFrameRate = targetFrameRate.Value;
                }

                bool targetFormatFound = false;
                string outputFileName;
                foreach (SubtitleFormat sf in formats)
                {
                    if (sf.IsTextBased && (sf.Name.Replace(" ", string.Empty).Equals(toFormat, StringComparison.OrdinalIgnoreCase) || sf.Name.Replace(" ", string.Empty).Equals(toFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase)))
                    {
                        targetFormatFound = true;
                        sf.BatchMode = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, sf.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        if (sf.IsFrameBased && !sub.WasLoadedWithFrameNumbers)
                            sub.CalculateFrameNumbersFromTimeCodesNoCheck(Configuration.Settings.General.CurrentFrameRate);
                        else if (sf.IsTimeBased && sub.WasLoadedWithFrameNumbers)
                            sub.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);

                        if ((sf.GetType() == typeof(WebVTT) || sf.GetType() == typeof(WebVTTFileWithLineNumber)))
                        {
                            targetEncoding = Encoding.UTF8;
                        }

                        if (sf.GetType() == typeof(ItunesTimedText) || sf.GetType() == typeof(ScenaristClosedCaptions) || sf.GetType() == typeof(ScenaristClosedCaptionsDropFrame))
                        {
                            Encoding outputEnc = new UTF8Encoding(false); // create encoding with no BOM
                            using (var file = new StreamWriter(outputFileName, false, outputEnc)) // open file with encoding
                            {
                                file.Write(sub.ToText(sf));
                            } // save and close it
                        }
                        else if (targetEncoding == Encoding.UTF8 && (format.GetType() == typeof(TmpegEncAW5) || format.GetType() == typeof(TmpegEncXml)))
                        {
                            Encoding outputEnc = new UTF8Encoding(false); // create encoding with no BOM
                            using (var file = new StreamWriter(outputFileName, false, outputEnc)) // open file with encoding
                            {
                                file.Write(sub.ToText(sf));
                            } // save and close it
                        }
                        else
                        {
                            try
                            {
                                File.WriteAllText(outputFileName, sub.ToText(sf), targetEncoding);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                errors++;
                                return false;
                            }
                        }

                        if (format.GetType() == typeof(Sami) || format.GetType() == typeof(SamiModern))
                        {
                            var sami = (Sami)format;
                            foreach (string className in Sami.GetStylesFromHeader(sub.Header))
                            {
                                var newSub = new Subtitle();
                                foreach (Paragraph p in sub.Paragraphs)
                                {
                                    if (p.Extra != null && p.Extra.Trim().Equals(className.Trim(), StringComparison.OrdinalIgnoreCase))
                                        newSub.Paragraphs.Add(p);
                                }
                                if (newSub.Paragraphs.Count > 0 && newSub.Paragraphs.Count < sub.Paragraphs.Count)
                                {
                                    string s = fileName;
                                    if (s.LastIndexOf('.') > 0)
                                        s = s.Insert(s.LastIndexOf('.'), "_" + className);
                                    else
//.........这里部分代码省略.........
开发者ID:sayidly,项目名称:subtitleedit,代码行数:101,代码来源:CommandLineConvert.cs

示例10: SaveSubtitle

        private DialogResult SaveSubtitle(SubtitleFormat format)
        {
            if (string.IsNullOrEmpty(_fileName) || _converted)
                return FileSaveAs(false);

            try
            {
                var sub = GetSaveSubtitle(_subtitle);

                if (format != null && !format.IsTextBased)
                {
                    var ebu = format as Ebu;
                    if (ebu != null)
                    {
                        var header = new Ebu.EbuGeneralSubtitleInformation();
                        if (_subtitle != null && _subtitle.Header != null && (_subtitle.Header.Contains("STL2") || _subtitle.Header.Contains("STL3")))
                        {
                            header = Ebu.ReadHeader(Encoding.UTF8.GetBytes(_subtitle.Header));
                        }
                        if (ebu.Save(_fileName, sub, !_saveAsCalled, header))
                        {
                            _changeSubtitleToString = _subtitle.GetFastHashCode();
                            Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName, _subtitleAlternateFileName, Configuration.Settings.General.CurrentVideoOffsetInMs);
                            Configuration.Settings.Save();
                        }
                    }
                    return DialogResult.OK;
                }

                string allText = sub.ToText(format);

                // Seungki begin
                if (_splitDualSami && _subtitleAlternate != null)
                {
                    var s = new Subtitle(_subtitle);
                    foreach (var p in _subtitleAlternate.Paragraphs)
                        s.Paragraphs.Add(p);
                    allText = s.ToText(format);
                }
                // Seungki end

                var currentEncoding = GetCurrentEncoding();
                bool isUnicode = currentEncoding == Encoding.Unicode || currentEncoding == Encoding.UTF32 || currentEncoding == Encoding.GetEncoding(12001) || currentEncoding == Encoding.UTF7 || currentEncoding == Encoding.UTF8;
                if (!isUnicode && (allText.Contains(new[] { '♪', '♫', '♥', '—', '―', '…' }))) // ANSI & music/unicode symbols
                {
                    if (MessageBox.Show(string.Format(_language.UnicodeMusicSymbolsAnsiWarning), Title, MessageBoxButtons.YesNo) == DialogResult.No)
                        return DialogResult.No;
                }

                if (!isUnicode)
                {
                    allText = NormalizeUnicode(allText);
                }

                bool containsNegativeTime = false;
                foreach (var p in sub.Paragraphs)
                {
                    if (p.StartTime.TotalMilliseconds < 0 || p.EndTime.TotalMilliseconds < 0)
                    {
                        containsNegativeTime = true;
                        break;
                    }
                }
                if (containsNegativeTime)
                {
                    if (MessageBox.Show(_language.NegativeTimeWarning, Title, MessageBoxButtons.YesNo) == DialogResult.No)
                        return DialogResult.No;
                }

                if (File.Exists(_fileName))
                {
                    var fileInfo = new FileInfo(_fileName);
                    var fileOnDisk = fileInfo.LastWriteTime;
                    if (_fileDateTime != fileOnDisk && _fileDateTime != new DateTime())
                    {
                        if (MessageBox.Show(string.Format(_language.OverwriteModifiedFile,
                            _fileName, fileOnDisk.ToShortDateString(), fileOnDisk.ToString("HH:mm:ss"),
                            Environment.NewLine, _fileDateTime.ToShortDateString(), _fileDateTime.ToString("HH:mm:ss")),
                            Title + " - " + _language.FileOnDiskModified, MessageBoxButtons.YesNo) == DialogResult.No)
                            return DialogResult.No;
                    }
                    if (fileInfo.IsReadOnly)
                    {
                        MessageBox.Show(string.Format(_language.FileXIsReadOnly, _fileName));
                        return DialogResult.No;
                    }
                }

                if ((format.GetType() == typeof(WebVTT) || format.GetType() == typeof(WebVTTFileWithLineNumber)))
                {
                    SetEncoding(Encoding.UTF8);
                    currentEncoding = Encoding.UTF8;
                }

                if (ModifierKeys == (Keys.Control | Keys.Shift))
                    allText = allText.Replace("\r\n", "\n");

                if (format.GetType() == typeof(ItunesTimedText) || format.GetType() == typeof(ScenaristClosedCaptions) || format.GetType() == typeof(ScenaristClosedCaptionsDropFrame))
                {
                    var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
//.........这里部分代码省略.........
开发者ID:LeonCheung,项目名称:subtitleedit,代码行数:101,代码来源:Main.cs

示例11: BatchConvertSave


//.........这里部分代码省略.........
                        mr.RunFromBatch(sub, multipleReplaceImportFiles);
                        sub = mr.FixedSubtitle;
                        sub.RemoveParagraphsByIndices(mr.DeleteIndices);
                    }
                }

                bool targetFormatFound = false;
                string outputFileName;
                foreach (SubtitleFormat sf in formats)
                {
                    if (sf.IsTextBased && sf.Name.Replace(" ", string.Empty).Equals(targetFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        sf.BatchMode = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, sf.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        if (sf.IsFrameBased && !sub.WasLoadedWithFrameNumbers)
                            sub.CalculateFrameNumbersFromTimeCodesNoCheck(Configuration.Settings.General.CurrentFrameRate);
                        else if (sf.IsTimeBased && sub.WasLoadedWithFrameNumbers)
                            sub.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);

                        if (sf.GetType() == typeof(WebVTT))
                        {
                            targetEncoding = Encoding.UTF8;
                        }

                        try
                        {
                            if (sf.GetType() == typeof(ItunesTimedText) || sf.GetType() == typeof(ScenaristClosedCaptions) || sf.GetType() == typeof(ScenaristClosedCaptionsDropFrame))
                            {
                                var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
                                using (var file = new StreamWriter(outputFileName, false, outputEnc)) // open file with encoding
                                {
                                    file.Write(sub.ToText(sf));
                                } // save and close it
                            }
                            else if (targetEncoding == Encoding.UTF8 && (format.GetType() == typeof(TmpegEncAW5) || format.GetType() == typeof(TmpegEncXml)))
                            {
                                var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
                                using (var file = new StreamWriter(outputFileName, false, outputEnc)) // open file with encoding
                                {
                                    file.Write(sub.ToText(sf));
                                } // save and close it
                            }
                            else
                            {
                                File.WriteAllText(outputFileName, sub.ToText(sf), targetEncoding);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            errors++;
                            return false;
                        }

                        if (format.GetType() == typeof(Sami) || format.GetType() == typeof(SamiModern))
                        {
                            var sami = (Sami)format;
                            foreach (string className in Sami.GetStylesFromHeader(sub.Header))
                            {
                                var newSub = new Subtitle();
                                foreach (Paragraph p in sub.Paragraphs)
                                {
                                    if (p.Extra != null && p.Extra.Trim().Equals(className.Trim(), StringComparison.OrdinalIgnoreCase))
                                        newSub.Paragraphs.Add(p);
开发者ID:mgziminsky,项目名称:subtitleedit,代码行数:67,代码来源:CommandLineConvert.cs


注:本文中的Subtitle.ToText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。