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


C# Subtitle.GetParagraphOrDefault方法代码示例

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


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

示例1: AdjustAllParagraphs

        public Subtitle AdjustAllParagraphs(Subtitle subtitle)
        {
            foreach (Paragraph p in subtitle.Paragraphs)
            {
                AdjustParagraph(p);
            }

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
                if (next != null)
                {
                    if (p.EndTime.TotalMilliseconds >= next.StartTime.TotalMilliseconds)
                        p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
                }
            }
            return subtitle;
        }
开发者ID:athikan,项目名称:subtitleedit,代码行数:19,代码来源:ChangeSpeedInPercent.cs

示例2: GetSelectedParagraph

 public Paragraph GetSelectedParagraph(Subtitle subtitle)
 {
     if (subtitle != null && SelectedItems.Count > 0)
         return subtitle.GetParagraphOrDefault(SelectedItems[0].Index);
     return null;
 }
开发者ID:rragu,项目名称:subtitleedit,代码行数:6,代码来源:SubtitleListView.cs

示例3: MergeLineswithSameTextInSubtitle

        public Subtitle MergeLineswithSameTextInSubtitle(Subtitle subtitle, List<int> mergedIndexes, out int numberOfMerges, bool clearFixes, bool fixIncrementing, bool lineAfterNext, int maxMsBetween)
        {
            List<int> removed = new List<int>();
            if (!loading)
                listViewFixes.ItemChecked -= listViewFixes_ItemChecked;
            if (clearFixes)
                listViewFixes.Items.Clear();
            numberOfMerges = 0;
            var mergedSubtitle = new Subtitle();
            bool lastMerged = false;
            Paragraph p = null;
            var lineNumbers = new StringBuilder();
            for (int i = 1; i < subtitle.Paragraphs.Count; i++)
            {
                if (!lastMerged)
                {
                    p = new Paragraph(subtitle.GetParagraphOrDefault(i - 1));
                    mergedSubtitle.Paragraphs.Add(p);
                }
                Paragraph next = subtitle.GetParagraphOrDefault(i);
                Paragraph afterNext = subtitle.GetParagraphOrDefault(i + 1);
                if (p != null && next != null)
                {
                    if ((QualifiesForMerge(p, next, maxMsBetween) || (fixIncrementing && QualifiesForMergeIncrement(p, next, maxMsBetween))) && IsFixAllowed(p))
                    {
                        p.Text = next.Text;
                        p.EndTime = next.EndTime;
                        if (lastMerged)
                        {
                            lineNumbers.Append(next.Number.ToString() + ",");
                        }
                        else
                        {
                            lineNumbers.Append(p.Number.ToString() + ",");
                            lineNumbers.Append(next.Number.ToString() + ",");
                        }

                        lastMerged = true;
                        removed.Add(i);
                        numberOfMerges++;
                        if (!mergedIndexes.Contains(i))
                            mergedIndexes.Add(i);
                        if (!mergedIndexes.Contains(i - 1))
                            mergedIndexes.Add(i - 1);
                    }
                    else if (lineAfterNext && QualifiesForMerge(p, afterNext, maxMsBetween) && p.Duration.TotalMilliseconds > afterNext.Duration.TotalMilliseconds && IsFixAllowed(p))
                    {
                        removed.Add(i + 2);
                        numberOfMerges++;
                        if (lastMerged)
                        {
                            lineNumbers.Append(afterNext.Number.ToString() + ",");
                        }
                        else
                        {
                            lineNumbers.Append(p.Number.ToString() + ",");
                            lineNumbers.Append(afterNext.Number.ToString() + ",");
                        }
                        lastMerged = true;
                        if (!mergedIndexes.Contains(i))
                            mergedIndexes.Add(i);
                        if (!mergedIndexes.Contains(i - 1))
                            mergedIndexes.Add(i - 1);
                    }
                    else
                    {
                        lastMerged = false;
                    }
                }
                else
                {
                    lastMerged = false;
                }

                if (!removed.Contains(i) && lineNumbers.Length > 0 && clearFixes)
                {
                    AddToListView(p, lineNumbers.ToString(), p.Text);
                    lineNumbers = new StringBuilder();
                }
            }
            if (lineNumbers.Length > 0 && clearFixes)
            {
                AddToListView(p, lineNumbers.ToString(), p.Text);
            }
            if (!lastMerged)
                mergedSubtitle.Paragraphs.Add(new Paragraph(subtitle.GetParagraphOrDefault(subtitle.Paragraphs.Count - 1)));

            if (!loading)
                listViewFixes.ItemChecked += listViewFixes_ItemChecked;

            mergedSubtitle.Renumber(1);
            return mergedSubtitle;
        }
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:93,代码来源:MergeDoubleLines.cs

示例4: checkBoxUseTimeCodesFromIdx_CheckedChanged

 private void checkBoxUseTimeCodesFromIdx_CheckedChanged(object sender, EventArgs e)
 {
     Subtitle oldSubtitle = new Subtitle(_subtitle);
     subtitleListView1.BeginUpdate();
     LoadVobRip();
     for (int i = 0; i < _subtitle.Paragraphs.Count; i++)
     {
         Paragraph p = oldSubtitle.GetParagraphOrDefault(i);
         if (p != null && p.Text.Length > 0)
         {
             _subtitle.Paragraphs[i].Text = p.Text;
         }
     }
     subtitleListView1.Fill(_subtitle);
     subtitleListView1.EndUpdate();
 }
开发者ID:Tarhan,项目名称:subtitleedit,代码行数:16,代码来源:VobSubOcr.cs

示例5: buttonConvert_Click


//.........这里部分代码省略.........
                                    }
                                }
                            }
                        }
                        else if (bluRaySubtitles.Count > 0)
                        {
                            item.SubItems[3].Text = "OCR...";
                            var vobSubOcr = new VobSubOcr();
                            vobSubOcr.FileName = Path.GetFileName(fileName);
                            vobSubOcr.InitializeBatch(bluRaySubtitles, Configuration.Settings.VobSubOcr, fileName);
                            sub = vobSubOcr.SubtitleFromOcr;
                        }
                        else if (isVobSub)
                        {
                            item.SubItems[3].Text = "OCR...";
                            var vobSubOcr = new VobSubOcr();
                            vobSubOcr.InitializeBatch(fileName, Configuration.Settings.VobSubOcr, true);
                            sub = vobSubOcr.SubtitleFromOcr;
                        }

                        if (comboBoxSubtitleFormats.Text == new AdvancedSubStationAlpha().Name && _assStyle != null)
                        {
                            sub.Header = _assStyle;
                        }
                        else if (comboBoxSubtitleFormats.Text == new SubStationAlpha().Name && _ssaStyle != null)
                        {
                            sub.Header = _ssaStyle;
                        }

                        int prevIndex = -1;
                        foreach (Paragraph p in sub.Paragraphs)
                        {
                            string prevText = string.Empty;
                            var prev = sub.GetParagraphOrDefault(prevIndex);
                            if (prev != null)
                                prevText = prev.Text;
                            prevIndex++;

                            if (checkBoxRemoveTextForHI.Checked)
                            {
                                p.Text = _removeForHI.RemoveTextFromHearImpaired(p.Text, prevText);
                            }
                            if (checkBoxRemoveFormatting.Checked)
                            {
                                p.Text = Utilities.RemoveHtmlTags(p.Text);
                                if (p.Text.StartsWith("{") && p.Text.Length > 6 && p.Text[5] == '}')
                                    p.Text = p.Text.Remove(0, 6);
                                if (p.Text.StartsWith("{") && p.Text.Length > 6 && p.Text[4] == '}')
                                    p.Text = p.Text.Remove(0, 5);
                            }
                        }
                        if (checkBoxFixCasing.Checked)
                        {
                            _changeCasing.FixCasing(sub, Utilities.AutoDetectGoogleLanguage(sub));
                            _changeCasingNames.Initialize(sub);
                            _changeCasingNames.FixCasing();
                        }

                        double fromFrameRate;
                        double toFrameRate;
                        if (double.TryParse(comboBoxFrameRateFrom.Text, out fromFrameRate) &&
                            double.TryParse(comboBoxFrameRateTo.Text, out toFrameRate))
                        {
                            sub.ChangeFramerate(fromFrameRate, toFrameRate);
                        }
开发者ID:novaterata,项目名称:subtitleedit,代码行数:66,代码来源:BatchConvert.cs

示例6: toolStripMenuItemImportTimeCodes_Click

        private void toolStripMenuItemImportTimeCodes_Click(object sender, EventArgs e)
        {
            if (_subtitle.Paragraphs.Count < 1)
            {
                MessageBox.Show(_language.NoSubtitleLoaded, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            openFileDialog1.Title = _languageGeneral.OpenSubtitle;
            openFileDialog1.FileName = string.Empty;
            openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                Encoding encoding = null;
                Subtitle timeCodeSubtitle = new Subtitle();
                SubtitleFormat format = timeCodeSubtitle.LoadSubtitle(openFileDialog1.FileName, out encoding, encoding);
                if (format == null)
                {
                    ShowUnknownSubtitle();
                    return;
                }

                if (timeCodeSubtitle.Paragraphs.Count != _subtitle.Paragraphs.Count && !string.IsNullOrEmpty(_language.ImportTimeCodesDifferentNumberOfLinesWarning))
                {
                    if (MessageBox.Show(string.Format(_language.ImportTimeCodesDifferentNumberOfLinesWarning, timeCodeSubtitle.Paragraphs.Count, _subtitle.Paragraphs.Count), _title, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                        return;
                }

                MakeHistoryForUndo(_language.BeforeTimeCodeImport);

                if (GetCurrentSubtitleFormat().IsFrameBased)
                    timeCodeSubtitle.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
                else
                    timeCodeSubtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);

                int count = 0;
                for (int i = 0; i < timeCodeSubtitle.Paragraphs.Count; i++)
                {
                    Paragraph existing = _subtitle.GetParagraphOrDefault(i);
                    Paragraph newTimeCode = timeCodeSubtitle.GetParagraphOrDefault(i);
                    if (existing == null || newTimeCode == null)
                        break;
                    existing.StartTime.TotalMilliseconds = newTimeCode.StartTime.TotalMilliseconds;
                    existing.EndTime.TotalMilliseconds = newTimeCode.EndTime.TotalMilliseconds;
                    existing.StartFrame = newTimeCode.StartFrame;
                    existing.EndFrame = newTimeCode.EndFrame;
                    count++;

                }
                ShowStatus(string.Format(_language.TimeCodeImportedFromXY, Path.GetFileName(openFileDialog1.FileName), count));
                SaveSubtitleListviewIndexes();
                ShowSource();
                SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                RestoreSubtitleListviewIndexes();
            }

        }
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:57,代码来源:Main.cs

示例7: SetPosition

 public void SetPosition(double startPositionSeconds, Subtitle subtitle, double currentVideoPositionSeconds, int subtitleIndex, ListView.SelectedIndexCollection selectedIndices)
 {
     StartPositionSeconds = startPositionSeconds;
     _selectedIndices = selectedIndices;
     _subtitle = subtitle;
     _currentVideoPositionSeconds = currentVideoPositionSeconds;
     _selectedParagraph = _subtitle.GetParagraphOrDefault(subtitleIndex);
     NearestSubtitles(subtitle, currentVideoPositionSeconds, subtitleIndex);
     Invalidate();
 }
开发者ID:novaterata,项目名称:subtitleedit,代码行数:10,代码来源:AudioVisualizer.cs

示例8: GeneratePreview

        private void GeneratePreview()
        {
            List<int> fixes = new List<int>();
            if (_subtitle == null)
                return;

            FixedSubtitle = new Subtitle(_subtitle);
            var onlyFixedSubtitle = new Subtitle();

            double minumumMillisecondsBetweenLines = (double)numericUpDownMinMillisecondsBetweenLines.Value;
            for (int i = 0; i < FixedSubtitle.Paragraphs.Count - 1; i++)
            {
                Paragraph p = FixedSubtitle.GetParagraphOrDefault(i);
                Paragraph next = FixedSubtitle.GetParagraphOrDefault(i + 1);
                if (next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds < minumumMillisecondsBetweenLines)
                {
                    p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - minumumMillisecondsBetweenLines;
                    fixes.Add(i);
                    onlyFixedSubtitle.Paragraphs.Add(new Paragraph(p));
                }
            }

            SubtitleListview1.BeginUpdate();
            groupBoxLinesFound.Text = string.Format(Configuration.Settings.Language.SetMinimumDisplayTimeBetweenParagraphs.PreviewLinesModifiedX, fixes.Count);
            if (checkBoxShowOnlyChangedLines.Checked)
            {
                SubtitleListview1.Fill(onlyFixedSubtitle);
            }
            else
            {
                SubtitleListview1.Fill(FixedSubtitle);
                foreach (int index in fixes)
                    SubtitleListview1.SetBackgroundColor(index, Color.Silver);
            }
            SubtitleListview1.EndUpdate();
            FixCount = fixes.Count;
        }
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:37,代码来源:SetMinimumDisplayTimeBetweenParagraphs.cs

示例9: AddWaterMark

        private void AddWaterMark(Subtitle subtitle, string input)
        {
            if (subtitle == null || subtitle.Paragraphs.Count == 0)
            {
                return;
            }

            byte[] buffer = Encoding.ASCII.GetBytes(input);

            if (radioButtonCurrentLine.Checked)
            {
                StringBuilder sb = new StringBuilder();
                foreach (byte b in buffer)
                {
                    sb.Append(zeroWhiteSpace);
                    for (int i = 0; i < b; i++)
                        sb.Append(zeroWidthNoBreakSpace);
                }
                Paragraph p = subtitle.GetParagraphOrDefault(_firstSelectedIndex);
                if (p != null)
                {
                    if (p.Text.Length > 1)
                        p.Text = p.Text.Insert(p.Text.Length / 2, sb.ToString());
                    else
                        p.Text = sb.ToString() + p.Text;
                }
            }
            else
            {
                Random r = new Random();
                List<int> indices = new List<int>();
                foreach (byte b in buffer)
                {
                    int number = r.Next(subtitle.Paragraphs.Count - 1);
                    if (indices.Contains(number))
                        number = r.Next(subtitle.Paragraphs.Count - 1);
                    if (indices.Contains(number))
                        number = r.Next(subtitle.Paragraphs.Count - 1);
                    indices.Add(number);
                }

                indices.Sort();
                int j = 0;
                foreach (byte b in buffer)
                {
                    StringBuilder sb = new StringBuilder();
                    Paragraph p = subtitle.Paragraphs[indices[j]];
                    sb.Append(zeroWhiteSpace);
                    for (int i = 0; i < b; i++)
                        sb.Append(zeroWidthNoBreakSpace);
                    if (p.Text.Length > 1)
                        p.Text = p.Text.Insert(p.Text.Length / 2, sb.ToString());
                    else
                        p.Text = sb.ToString() + p.Text;
                    j++;
                }
            }
        }
开发者ID:radinamatic,项目名称:subtitleedit,代码行数:58,代码来源:Watermark.cs

示例10: CompareSubtitles

        private void CompareSubtitles()
        {
            timer1.Stop();
            var sub1 = new Subtitle(_subtitle1);
            var sub2 = new Subtitle(_subtitle2);

            int index = 0;
            Paragraph p1 = sub1.GetParagraphOrDefault(index);
            Paragraph p2 = sub2.GetParagraphOrDefault(index);
            int max = sub1.Paragraphs.Count;
            if (max < sub2.Paragraphs.Count)
                max = sub2.Paragraphs.Count;
            while (index < max)
            {
                if (p1 != null && p2 != null)
                {
                    if (p1.ToString() == p2.ToString())
                    {
                    }
                    else
                    {
                        if (GetColumnsEqualExceptNumber(p1, p2) == 0)
                        {
                            int oldIndex = index;
                            for (int i = 1; oldIndex + i < max; i++)
                            {
                                if (GetColumnsEqualExceptNumber(sub1.GetParagraphOrDefault(index + i), p2) > 1)
                                {
                                    for (int j = 0; j < i; j++)
                                    {
                                        sub2.Paragraphs.Insert(index, new Paragraph());
                                        index++;
                                    }
                                    break;
                                }
                                else if (GetColumnsEqualExceptNumber(p1, sub2.GetParagraphOrDefault(index + i)) > 1)
                                {
                                    for (int j = 0; j < i; j++)
                                    {
                                        sub1.Paragraphs.Insert(index, new Paragraph());
                                        index++;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
                index++;
                p1 = sub1.GetParagraphOrDefault(index);
                p2 = sub2.GetParagraphOrDefault(index);
            }
            subtitleListView1.Fill(sub1);
            subtitleListView2.Fill(sub2);

            // coloring + differences index list
            _differences = new List<int>();
            index = 0;
            p1 = sub1.GetParagraphOrDefault(index);
            p2 = sub2.GetParagraphOrDefault(index);
            int totalWords = 0;
            int wordsChanged = 0;
            if (checkBoxOnlyListDifferencesInText.Checked)
            {
                while (index < sub1.Paragraphs.Count || index < sub2.Paragraphs.Count)
                {
                    if (p1 != null && p2 != null)
                    {
                        Utilities.GetTotalAndChangedWords(p1.Text, p2.Text, ref totalWords, ref wordsChanged, checkBoxIgnoreLineBreaks.Checked, GetBreakToLetter());
                        if (FixWhitespace(p1.ToString()) == FixWhitespace(p2.ToString()) && p1.Number == p2.Number)
                        { // no differences
                        }
                        else if (p1.ToString() == new Paragraph().ToString())
                        {
                            _differences.Add(index);
                            subtitleListView1.ColorOut(index, Color.Salmon);
                        }
                        else if (p2.ToString() == new Paragraph().ToString())
                        {
                            _differences.Add(index);
                            subtitleListView2.ColorOut(index, Color.Salmon);
                        }
                        else if (FixWhitespace(p1.Text) != FixWhitespace(p2.Text))
                        {
                            _differences.Add(index);
                            subtitleListView1.SetBackgroundColor(index, Color.LightGreen, SubtitleListView.ColumnIndexText);
                        }
                    }
                    else
                    {
                        if (p1 != null && p1.Text != null)
                            totalWords += Utilities.SplitForChangedCalc(p1.Text, checkBoxIgnoreLineBreaks.Checked, GetBreakToLetter()).Length;
                        else if (p2 != null && p2.Text != null)
                            totalWords += Utilities.SplitForChangedCalc(p2.Text, checkBoxIgnoreLineBreaks.Checked, GetBreakToLetter()).Length;
                        _differences.Add(index);
                    }
                    index++;
                    p1 = sub1.GetParagraphOrDefault(index);
                    p2 = sub2.GetParagraphOrDefault(index);
                }
//.........这里部分代码省略.........
开发者ID:nshayanfar,项目名称:subtitleedit,代码行数:101,代码来源:Compare.cs

示例11: MergeLinesWithSameTimeCodes

        public Subtitle MergeLinesWithSameTimeCodes(Subtitle subtitle, List<int> mergedIndexes, out int numberOfMerges, bool clearFixes, bool reBreak, int maxMsBetween)
        {
            listViewFixes.BeginUpdate();
            List<int> removed = new List<int>();
            if (!_loading)
                listViewFixes.ItemChecked -= listViewFixes_ItemChecked;
            if (clearFixes)
            {
                listViewFixes.Items.Clear();
                _isFixAllowedList = new Dictionary<int, bool>();
            }
            numberOfMerges = 0;
            var mergedSubtitle = new Subtitle();
            bool lastMerged = false;
            Paragraph p = null;
            var lineNumbers = new StringBuilder();
            for (int i = 1; i < subtitle.Paragraphs.Count; i++)
            {
                if (!lastMerged)
                {
                    p = new Paragraph(subtitle.GetParagraphOrDefault(i - 1));
                    mergedSubtitle.Paragraphs.Add(p);
                }
                Paragraph next = subtitle.GetParagraphOrDefault(i);
                Paragraph afterNext = subtitle.GetParagraphOrDefault(i + 1);
                if (next != null)
                {
                    if (QualifiesForMerge(p, next, maxMsBetween) && IsFixAllowed(p))
                    {
                        if (p.Text.StartsWith("<i>") && p.Text.EndsWith("</i>") && next.Text.StartsWith("<i>") && next.Text.EndsWith("</i>"))
                        {
                            p.Text = p.Text.Remove(p.Text.Length - 4) + Environment.NewLine + next.Text.Remove(0, 3);
                        }
                        else
                        {
                            p.Text = p.Text + Environment.NewLine + next.Text;
                        }
                        if (reBreak)
                            p.Text = Utilities.AutoBreakLine(p.Text, _language);
                        lastMerged = true;
                        removed.Add(i);
                        numberOfMerges++;
                        if (!mergedIndexes.Contains(i))
                            mergedIndexes.Add(i);
                        if (!mergedIndexes.Contains(i - 1))
                            mergedIndexes.Add(i - 1);

                        lineNumbers.Append(p.Number.ToString() + ", ");
                        lineNumbers.Append(next.Number.ToString());
                    }
                    else
                    {
                        lastMerged = false;
                    }
                }
                else
                {
                    lastMerged = false;
                }

                if (!removed.Contains(i) && lineNumbers.Length > 0 && clearFixes)
                {
                    AddToListView(p, lineNumbers.ToString(), p.Text);
                    lineNumbers = new StringBuilder();
                }
            }
            if (lineNumbers.Length > 0 && clearFixes)
            {
                AddToListView(p, lineNumbers.ToString(), p.Text);
            }
            if (!lastMerged)
                mergedSubtitle.Paragraphs.Add(new Paragraph(subtitle.GetParagraphOrDefault(subtitle.Paragraphs.Count - 1)));

            listViewFixes.EndUpdate();
            if (!_loading)
                listViewFixes.ItemChecked += listViewFixes_ItemChecked;

            mergedSubtitle.Renumber(1);
            return mergedSubtitle;
        }
开发者ID:athikan,项目名称:subtitleedit,代码行数:80,代码来源:MergeTextWithSameTimeCodes.cs

示例12: ImportTimeCodesOnSameSeperateLine


//.........这里部分代码省略.........
                        string[] end = arr[1].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
                        if ((start.Length == 3 || start.Length == 4) && (end.Length == 3 || end.Length == 4))
                        {
                            if (paragraph != null)
                            {
                                paragraph.Text = sb.ToString().Trim();
                                subtitle.Paragraphs.Add(paragraph);
                            }

                            paragraph = new Paragraph();
                            sb = new StringBuilder();
                            paragraph.StartTime = DecodeTime(start);
                            paragraph.EndTime = DecodeTime(end);
                        }
                    }
                    else if (arr.Length == 3)
                    {
                        string[] start = arr[0].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
                        string[] end = arr[1].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
                        string[] duration = arr[2].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);

                        if (start.Length < 3)
                        {
                            start = end;
                            end = duration;
                        }

                        if ((start.Length == 3 || start.Length == 4) && (end.Length == 3 || end.Length == 4))
                        {
                            if (paragraph != null)
                            {
                                paragraph.Text = sb.ToString().Trim();
                                subtitle.Paragraphs.Add(paragraph);
                            }

                            paragraph = new Paragraph();
                            sb = new StringBuilder();
                            paragraph.StartTime = DecodeTime(start);
                            paragraph.EndTime = DecodeTime(end);
                        }
                    }
                }

                if (paragraph == null || allNumbers || line.Length <= 1)
                {
                    continue;
                }

                line = line.Trim();
                if (line.StartsWith("}{}") || line.StartsWith("][]"))
                {
                    line = line.Remove(0, 3);
                }

                sb.AppendLine(line.Trim());
            }

            if (paragraph != null)
            {
                paragraph.Text = sb.ToString().Trim();
                subtitle.Paragraphs.Add(paragraph);
            }

            double averateDuration = 0;
            foreach (Paragraph a in subtitle.Paragraphs)
            {
                double d = a.Duration.TotalSeconds;
                if (d > 10)
                {
                    d = 8;
                }

                averateDuration += d;
            }

            averateDuration = averateDuration / subtitle.Paragraphs.Count;
            if (averateDuration < 0.2 ||
                (averateDuration < 0.5 &&
                subtitle.Paragraphs.Count > 100 &&
                subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].StartTime.TotalSeconds < 140 &&
                subtitle.Paragraphs[subtitle.Paragraphs.Count - 2].StartTime.TotalSeconds < 140))
            {
                subtitle = ImportTimeCodesOnSameSeperateLineNoMilliseconds(lines);
                int i = 0;
                foreach (Paragraph a in subtitle.Paragraphs)
                {
                    i++;
                    var next = subtitle.GetParagraphOrDefault(i);
                    if (next != null && a.EndTime.TotalMilliseconds >= next.StartTime.TotalMilliseconds)
                    {
                        a.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
                    }
                }

                return subtitle;
            }

            subtitle.Renumber();
            return subtitle;
        }
开发者ID:AsenTahchiyski,项目名称:SoftUni-Projects,代码行数:101,代码来源:UknownFormatImporter.cs

示例13: MergeShortLinesInSubtitle

        public Subtitle MergeShortLinesInSubtitle(Subtitle subtitle, List<int> mergedIndexes, out int numberOfMerges, double maxMillisecondsBetweenLines, int maxCharacters, bool clearFixes)
        {
            listViewFixes.ItemChecked -= listViewFixes_ItemChecked;
            if (clearFixes)
                listViewFixes.Items.Clear();
            numberOfMerges = 0;
            string language = Utilities.AutoDetectGoogleLanguage(subtitle);
            Subtitle mergedSubtitle = new Subtitle();
            bool lastMerged = false;
            Paragraph p = null;
            StringBuilder lineNumbers = new StringBuilder();
            for (int i = 1; i < subtitle.Paragraphs.Count; i++)
            {
                if (!lastMerged)
                {
                    p = new Paragraph(subtitle.GetParagraphOrDefault(i - 1));
                    mergedSubtitle.Paragraphs.Add(p);
                }
                Paragraph next = subtitle.GetParagraphOrDefault(i);
                if (next != null)
                {
                    if (QualifiesForMerge(p, next, maxMillisecondsBetweenLines, maxCharacters) && IsFixAllowed(p))
                    {
                        if (GetStartTag(p.Text) == GetStartTag(next.Text) &&
                            GetEndTag(p.Text) == GetEndTag(next.Text))
                        {
                            string s1 = p.Text.Trim();
                            s1 = s1.Substring(0, s1.Length - GetEndTag(s1).Length);
                            string s2 = next.Text.Trim();
                            s2 = s2.Substring(GetStartTag(s2).Length);
                            p.Text = Utilities.AutoBreakLine(s1 + Environment.NewLine + s2, language);
                        }
                        else
                        {
                            p.Text = Utilities.AutoBreakLine(p.Text + Environment.NewLine + next.Text, language);
                        }
                        p.EndTime = next.EndTime;

                        if (lastMerged)
                        {
                            lineNumbers.Append(next.Number.ToString() + ",");
                        }
                        else
                        {
                            lineNumbers.Append(p.Number.ToString() + ",");
                            lineNumbers.Append(next.Number.ToString() + ",");
                        }

                        lastMerged = true;
                        numberOfMerges++;
                        if (!mergedIndexes.Contains(i))
                            mergedIndexes.Add(i);
                        if (!mergedIndexes.Contains(i - 1))
                            mergedIndexes.Add(i - 1);
                    }
                    else
                    {
                        lastMerged = false;
                    }
                }
                else
                {
                    lastMerged = false;
                }
                if (!lastMerged && lineNumbers.Length > 0 && clearFixes)
                {
                    AddToListView(p, lineNumbers.ToString(), p.Text);
                    lineNumbers = new StringBuilder();
                }
            }
            if (!lastMerged)
                mergedSubtitle.Paragraphs.Add(new Paragraph(subtitle.GetParagraphOrDefault(subtitle.Paragraphs.Count - 1)));

            listViewFixes.ItemChecked += listViewFixes_ItemChecked;
            return mergedSubtitle;
        }
开发者ID:rragu,项目名称:subtitleedit,代码行数:76,代码来源:MergeShortLines.cs

示例14: SplitLongLinesInSubtitle

        public Subtitle SplitLongLinesInSubtitle(Subtitle subtitle, List<int> splittedIndexes, List<int> autoBreakedIndexes, out int numberOfSplits, int totalLineMaxCharacters, int singleLineMaxCharacters, bool clearFixes)
        {
            listViewFixes.ItemChecked -= listViewFixes_ItemChecked;
            if (clearFixes)
                listViewFixes.Items.Clear();
            numberOfSplits = 0;
            string language = Utilities.AutoDetectGoogleLanguage(subtitle);
            Subtitle splittedSubtitle = new Subtitle();
            Paragraph p = null;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                bool added = false;
                p = subtitle.GetParagraphOrDefault(i);
                if (p != null && p.Text != null)
                {
                    string oldText = Utilities.RemoveHtmlTags(p.Text);
                    if (SplitLongLinesHelper.QualifiesForSplit(p.Text, singleLineMaxCharacters, totalLineMaxCharacters) && IsFixAllowed(p))
                    {
                        if (!SplitLongLinesHelper.QualifiesForSplit(Utilities.AutoBreakLine(p.Text, language), singleLineMaxCharacters, totalLineMaxCharacters))
                        {
                            Paragraph newParagraph = new Paragraph(p);
                            newParagraph.Text = Utilities.AutoBreakLine(p.Text, language);
                            if (clearFixes)
                                AddToListView(p, (splittedSubtitle.Paragraphs.Count + 1).ToString(), oldText);
                            autoBreakedIndexes.Add(splittedSubtitle.Paragraphs.Count);
                            splittedSubtitle.Paragraphs.Add(newParagraph);
                            added = true;
                            numberOfSplits++;
                        }
                        else
                        {
                            string text = Utilities.AutoBreakLine(p.Text, language);
                            if (text.Contains(Environment.NewLine))
                            {
                                string[] arr = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                if (arr.Length == 2)
                                {
                                    int spacing1 = Configuration.Settings.General.MininumMillisecondsBetweenLines / 2;
                                    int spacing2 = Configuration.Settings.General.MininumMillisecondsBetweenLines / 2;
                                    if (Configuration.Settings.General.MininumMillisecondsBetweenLines % 2 == 1)
                                        spacing2++;

                                    double duration = p.Duration.TotalMilliseconds / 2.0;
                                    Paragraph newParagraph1 = new Paragraph(p);
                                    Paragraph newParagraph2 = new Paragraph(p);
                                    newParagraph1.Text = Utilities.AutoBreakLine(arr[0], language);
                                    newParagraph1.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + duration - spacing1;
                                    newParagraph2.Text = Utilities.AutoBreakLine(arr[1], language);
                                    newParagraph2.StartTime.TotalMilliseconds = newParagraph1.EndTime.TotalMilliseconds + spacing2;

                                    if (clearFixes)
                                        AddToListView(p, (splittedSubtitle.Paragraphs.Count + 1).ToString(), oldText);
                                    splittedIndexes.Add(splittedSubtitle.Paragraphs.Count);
                                    splittedIndexes.Add(splittedSubtitle.Paragraphs.Count + 1);

                                    string p1 = Utilities.RemoveHtmlTags(newParagraph1.Text);
                                    bool p1Ends = false;
                                    if (p1.EndsWith(".") || p1.EndsWith("!") || p1.EndsWith("?") || p1.EndsWith(":") || p1.EndsWith(")") || p1.EndsWith("]") || p1.EndsWith("♪"))
                                        p1Ends = true;

                                    if (p1Ends)
                                    {
                                        if (newParagraph1.Text.StartsWith("-") && newParagraph2.Text.StartsWith("-"))
                                        {
                                            newParagraph1.Text = newParagraph1.Text.Remove(0, 1).Trim();
                                            newParagraph2.Text = newParagraph2.Text.Remove(0, 1).Trim();
                                        }
                                        else if (newParagraph1.Text.StartsWith("<i>-") && newParagraph2.Text.StartsWith("-"))
                                        {
                                            newParagraph1.Text = newParagraph1.Text.Remove(3, 1).Trim();
                                            if (newParagraph1.Text.StartsWith("<i> "))
                                                newParagraph1.Text = newParagraph1.Text.Remove(3, 1).Trim();
                                            newParagraph2.Text = newParagraph2.Text.Remove(0, 1).Trim();
                                        }
                                    }
                                    else
                                    {
                                        string post = string.Empty;
                                        if (newParagraph1.Text.EndsWith("</i>"))
                                        {
                                            post = "</i>";
                                            newParagraph1.Text = newParagraph1.Text.Remove(newParagraph1.Text.Length - post.Length);
                                        }
                                        newParagraph1.Text += comboBoxLineContinuationEnd.Text.TrimEnd() + post;

                                        string pre = string.Empty;
                                        if (newParagraph2.Text.StartsWith("<i>"))
                                        {
                                            pre = "<i>";
                                            newParagraph2.Text = newParagraph2.Text.Remove(0, pre.Length);
                                        }
                                        newParagraph2.Text = pre + comboBoxLineContinuationBegin.Text + newParagraph2.Text;
                                    }

                                    if (newParagraph1.Text.IndexOf("<i>") >= 0 && newParagraph1.Text.IndexOf("<i>") < 10 & newParagraph1.Text.IndexOf("</i>") < 0 &&
                                        newParagraph2.Text.Contains("</i>") && newParagraph2.Text.IndexOf("<i>") < 0)
                                    {
                                        newParagraph1.Text += "</i>";
                                        newParagraph2.Text = "<i>" + newParagraph2.Text;
                                    }
//.........这里部分代码省略.........
开发者ID:novaterata,项目名称:subtitleedit,代码行数:101,代码来源:SplitLongLines.cs

示例15: ContinueSpellcheck

        public void ContinueSpellcheck(Subtitle subtitle)
        {
            _subtitle = subtitle;

            buttonUndo.Visible = false;
            _undoList = new List<UndoObject>();

            if (_currentIndex >= subtitle.Paragraphs.Count)
                _currentIndex = 0;

            _currentParagraph = _subtitle.GetParagraphOrDefault(_currentIndex);
            if (_currentParagraph == null)
                return;

            SetWords(_currentParagraph.Text);
            _wordsIndex = -1;

            PrepareNextWord();
        }
开发者ID:radinamatic,项目名称:subtitleedit,代码行数:19,代码来源:SpellCheck.cs


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