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


C# Subtitle.GetParagraphOrDefault方法代码示例

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


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

示例1: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            subtitle.Paragraphs.Clear();
            foreach (string line in lines)
            {
                var pos0 = line.IndexOf("[0] = ", StringComparison.Ordinal);
                var pos1 = line.IndexOf("[1] = ", StringComparison.Ordinal);
                var pos2 = line.IndexOf("[2] = ", StringComparison.Ordinal);
                if (pos0 >= 0 && pos1 >= 0 && pos2 >= 0)
                {
                    var p = new Paragraph();
                    var sb = new StringBuilder();

                    for (int i = pos0 + 6; i < line.Length && char.IsDigit(line[i]); i++)
                    {
                        sb.Append(line[i]);
                    }
                    p.StartTime.TotalMilliseconds = int.Parse(sb.ToString());

                    sb = new StringBuilder();
                    for (int i = pos1 + 7; i < line.Length && line[i] != '\''; i++)
                    {
                        sb.Append(line[i]);
                    }
                    if (sb.Length > 0)
                        sb.AppendLine();
                    for (int i = pos2 + 7; i < line.Length && line[i] != '\''; i++)
                    {
                        sb.Append(line[i]);
                    }
                    p.Text = sb.ToString().Trim();
                    p.Text = WebUtility.HtmlDecode(p.Text);
                    p.Text = ConvertJavaSpecialCharacters(p.Text);
                    subtitle.Paragraphs.Add(p);
                }
            }
            for (int i = 1; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.GetParagraphOrDefault(i - 1);
                Paragraph next = subtitle.GetParagraphOrDefault(i);
                if (p != null && next != null)
                    p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds;
                if (!string.IsNullOrEmpty(next.Text))
                    p.EndTime.TotalMilliseconds--;
            }
            for (int i = subtitle.Paragraphs.Count - 1; i >= 0; i--)
            {
                Paragraph p = subtitle.GetParagraphOrDefault(i);
                if (p != null && string.IsNullOrEmpty(p.Text))
                    subtitle.Paragraphs.RemoveAt(i);
            }
            subtitle.Renumber();
        }
开发者ID:ARASHz4,项目名称:subtitleedit,代码行数:54,代码来源:HtmlSamiArray.cs

示例2: Initialize

        internal void Initialize(Subtitle subtitle, int firstSelectedIndex)
        {
            var sb = new StringBuilder();
            foreach (Paragraph p in subtitle.Paragraphs)
                sb.AppendLine(p.Text);

            string watermark = ReadWaterMark(sb.ToString().Trim());
            LabelWatermark.Text = string.Format("Watermark: {0}", watermark);
            if (watermark.Length == 0)
            {
                buttonRemove.Enabled = false;
                textBoxWatermark.Focus();
            }
            else
            {
                groupBoxGenerate.Enabled = false;
                buttonOK.Focus();
            }

            _firstSelectedIndex = firstSelectedIndex;
            Paragraph current = subtitle.GetParagraphOrDefault(_firstSelectedIndex);
            if (current != null)
                radioButtonCurrentLine.Text = radioButtonCurrentLine.Text + " " + current.Text.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString);
            else
                radioButtonCurrentLine.Enabled = false;
        }
开发者ID:ItsJustSean,项目名称:subtitleedit,代码行数:26,代码来源:Watermark.cs

示例3: Initialize

        internal void Initialize(Subtitle subtitle, int firstSelectedIndex)
        {
            var watermark = ReadWaterMark(subtitle.GetAllTexts().Trim());
            labelWatermark.Text = string.Format(_language.WatermarkX, watermark);
            if (watermark.Length == 0)
            {
                buttonRemove.Enabled = false;
                textBoxWatermark.Focus();
            }
            else
            {
                groupBoxGenerate.Enabled = false;
                buttonOK.Focus();
            }

            _firstSelectedIndex = firstSelectedIndex;
            var current = subtitle.GetParagraphOrDefault(_firstSelectedIndex);
            if (current != null)
            {
                radioButtonCurrentLine.Text = string.Format(_language.CurrentLineOnlyX, current.Text.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString));
            }
            else
            {
                radioButtonCurrentLine.Text = string.Format(_language.CurrentLineOnlyX, string.Empty);
                radioButtonCurrentLine.Enabled = false;
            }
        }
开发者ID:LeonCheung,项目名称:subtitleedit,代码行数:27,代码来源:Watermark.cs

示例4: ToText

        public override string ToText(Subtitle subtitle, string title)
        {
            var sb = new StringBuilder();
            sb.Append("{\"words\":[");
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];

                //split words
                string text = p.Text.Replace(Environment.NewLine, " ").Replace("  ", " ");
                var words = text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var times = GenerateTimes(words, text, p.StartTime, p.EndTime);
                for (int j = 0; j < words.Length; j++)
                {
                    sb.Append("[\"");
                    sb.Append(times[j]);
                    sb.Append("\",\"");
                    sb.Append(Json.EncodeJsonText(words[j]));
                    sb.Append("\"]");
                    sb.Append(',');
                }
                var next = subtitle.GetParagraphOrDefault(i + 1);
                if (next == null || next.StartTime.TotalMilliseconds - 200 < p.EndTime.TotalMilliseconds)
                {
                    sb.Append("[\"");
                    sb.Append(Convert.ToInt64(p.EndTime.TotalMilliseconds));
                    sb.Append("\",\"");
                    sb.Append("\"]");
                    sb.Append(',');
                }
            }
            return sb.ToString().Trim().TrimEnd(',') + "],\"paragraphs\":[],\"speakers\":{}}";
        }
开发者ID:ItsJustSean,项目名称:subtitleedit,代码行数:33,代码来源:JsonType6.cs

示例5: ToText

        public override string ToText(Subtitle subtitle, string title)
        {
            var sb = new StringBuilder();
            sb.AppendLine("#\tAppearance\tCaption\t");
            sb.AppendLine();
            int count = 1;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                string text = Utilities.RemoveHtmlTags(p.Text);
                sb.AppendLine(string.Format("{0}\t{1}\t{2}\t", count.ToString().PadLeft(5, ' '), MakeTimeCode(p.StartTime), text));
                sb.AppendLine("\t\t\t\t");
                Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
                if (next == null || Math.Abs(p.EndTime.TotalMilliseconds - next.StartTime.TotalMilliseconds) > 50)
                {
                    count++;
                    sb.AppendLine(string.Format("{0}\t{1}", count.ToString().PadLeft(5, ' '), MakeTimeCode(p.EndTime)));
                }
                count++;
            }

            var rtBox = new System.Windows.Forms.RichTextBox();
            rtBox.Text = sb.ToString();
            string rtf = rtBox.Rtf;
            rtBox.Dispose();
            return rtf;
        }
开发者ID:athikan,项目名称:subtitleedit,代码行数:27,代码来源:UnknownSubtitle21.cs

示例6: ToText

 public override string ToText(Subtitle subtitle, string title)
 {
     var sb = new StringBuilder();
     int index = 0;
     int index2 = 0;
     foreach (Paragraph p in subtitle.Paragraphs)
     {
         index++;
         StringBuilder text = new StringBuilder();
         text.Append(Utilities.RemoveHtmlTags(p.Text.Replace(Environment.NewLine, " ")));
         while (text.Length < 34)
             text.Append(" ");
         sb.Append(string.Format("{0}{1}", text, EncodeTimeCode(p.StartTime)));
         if (index % 50 == 1)
         {
             index2++;
             sb.Append(new string(' ', 25) + index2);
         }
         sb.AppendLine();
         Paragraph next = subtitle.GetParagraphOrDefault(index);
         if (next != null && next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds > 150)
         {
             text = new StringBuilder();
             while (text.Length < 34)
                 text.Append(" ");
             sb.AppendLine(string.Format("{0}{1}", text, EncodeTimeCode(p.EndTime)));
         }
     }
     return sb.ToString();
 }
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:30,代码来源:UnknownSubtitle44.cs

示例7: Fix

        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixSpanishInvertedQuestionAndExclamationMarks;
            int fixCount = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                Paragraph last = subtitle.GetParagraphOrDefault(i - 1);

                bool wasLastLineClosed = last == null || last.Text.EndsWith('?') || last.Text.EndsWith('!') || last.Text.EndsWith('.') ||
                                         last.Text.EndsWith(':') || last.Text.EndsWith(')') || last.Text.EndsWith(']');
                string trimmedStart = p.Text.TrimStart('-', ' ');
                if (last != null && last.Text.EndsWith("...", StringComparison.Ordinal) && trimmedStart.Length > 0 && char.IsLower(trimmedStart[0]))
                    wasLastLineClosed = false;
                if (!wasLastLineClosed && last.Text == last.Text.ToUpper())
                    wasLastLineClosed = true;

                string oldText = p.Text;

                FixSpanishInvertedLetter('?', "¿", p, last, ref wasLastLineClosed, fixAction, ref fixCount, callbacks);
                FixSpanishInvertedLetter('!', "¡", p, last, ref wasLastLineClosed, fixAction, ref fixCount, callbacks);

                if (p.Text != oldText)
                {
                    fixCount++;
                    callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            callbacks.UpdateFixStatus(fixCount, language.FixSpanishInvertedQuestionAndExclamationMarks, fixCount.ToString(CultureInfo.InvariantCulture));
        }
开发者ID:LeonCheung,项目名称:subtitleedit,代码行数:31,代码来源:FixSpanishInvertedQuestionAndExclamationMarks.cs

示例8: ToText

        public override string ToText(Subtitle subtitle, string title)
        {
            var sb = new StringBuilder();
            for (int index = 0; index < subtitle.Paragraphs.Count; index++)
            {
                Paragraph p = subtitle.Paragraphs[index];
                string text = HtmlUtil.RemoveHtmlTags(p.Text, true);
                if (text.Trim().Length == 0)
                {
                    text = "\u0014\u002C";
                }
                else
                {
                    text = text.Replace(Environment.NewLine, "\u0011P");
                    text = text.Replace("♪", "\u00117");
                    text = text.Replace("'", "'\u0012\u0029");
                    text = "\u0014" + "\u0025" + "\u0014" + "\u002d" + text;
                }
                sb.AppendLine(p.StartTime.ToHHMMSSFF() + "\r\n" + text);

                Paragraph next = subtitle.GetParagraphOrDefault(index + 1);
                if (next == null || next.StartTime.TotalMilliseconds > p.StartTime.TotalMilliseconds + MaxDurationMs)
                {
                    sb.AppendLine(p.EndTime.ToHHMMSSFF() + "\r\n\u0014\u002C");
                }
            }
            return sb.ToString().Trim();
        }
开发者ID:YangEunYong,项目名称:subtitleedit,代码行数:28,代码来源:NciTimedRollUpCaptions.cs

示例9: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            Paragraph p = null;
            foreach (string line in lines)
            {
                string s = line.Trim();
                if (RegexTimeCodes.Match(s).Success)
                {
                    if (p != null && !string.IsNullOrEmpty(p.Text))
                        subtitle.Paragraphs.Add(p);
                    p = new Paragraph();

                    try
                    {
                        string[] arr = s.Substring(0, 11).Split(':');
                        if (arr.Length == 4)
                        {
                            p.StartTime = DecodeTimeCodeFramesFourParts(arr);
                            string text = s.Substring(11).Trim();
                            p.Text = text;
                            if (text.Length > 1 && Utilities.IsInteger(text.Substring(0, 2)))
                                _errorCount++;
                        }
                    }
                    catch
                    {
                        _errorCount++;
                    }
                }
                else if (s.Length > 0)
                {
                    _errorCount++;
                }
            }
            if (p != null && !string.IsNullOrEmpty(p.Text))
                subtitle.Paragraphs.Add(p);

            int index = 1;
            foreach (Paragraph paragraph in subtitle.Paragraphs)
            {
                paragraph.Text = paragraph.Text.Replace("\\M", "♪");

                Paragraph next = subtitle.GetParagraphOrDefault(index);
                if (next != null)
                {
                    paragraph.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
                }
                else
                {
                    paragraph.EndTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(paragraph.Text);
                }
                index++;
            }
            subtitle.RemoveEmptyLines();
        }
开发者ID:ARASHz4,项目名称:subtitleedit,代码行数:56,代码来源:UnknownSubtitle53.cs

示例10: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            Paragraph p = null;
            foreach (string line in lines)
            {
                string s = line.Trim();
                string[] arr = line.Split();
                var timeCode = arr[arr.Length - 1];
                if (regexTimeCodesAM.Match(timeCode).Success || regexTimeCodesPM.Match(timeCode).Success)
                {
                    try
                    {
                        arr = timeCode.Substring(0, 10).Split(':');
                        if (arr.Length == 4)
                        {
                            int hours = int.Parse(arr[0]);
                            int minutes = int.Parse(arr[1]);
                            int seconds = int.Parse(arr[2]);
                            int frames = int.Parse(arr[3]);
                            p = new Paragraph();
                            p.StartTime = new TimeCode(hours, minutes, seconds, FramesToMillisecondsMax999(frames));
                            p.Text = s.Substring(0, s.IndexOf(timeCode, StringComparison.Ordinal)).Trim();
                            subtitle.Paragraphs.Add(p);
                        }
                    }
                    catch
                    {
                        _errorCount++;
                    }
                }
                else if (s.Length > 0)
                {
                    _errorCount++;
                }
            }

            int index = 1;
            foreach (Paragraph paragraph in subtitle.Paragraphs)
            {
                Paragraph next = subtitle.GetParagraphOrDefault(index);
                if (next != null)
                {
                    paragraph.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
                }
                if (paragraph.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
                {
                    paragraph.EndTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(p.Text);
                }
                index++;
            }

            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
开发者ID:socialpercon,项目名称:subtitleedit,代码行数:55,代码来源:UnknownSubtitle46.cs

示例11: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            var paragraph = new Paragraph();
            _errorCount = 0;
            subtitle.Paragraphs.Clear();
            for (int i = 0; i < lines.Count; i++)
            {
                string line = lines[i].TrimEnd();
                string next = string.Empty;
                if (i + 1 < lines.Count)
                    next = lines[i + 1];

                if (line.Contains(':') && !next.Contains(':') && RegexTimeCodes.IsMatch(line) && !RegexTimeCodes.IsMatch(next))
                {
                    paragraph = new Paragraph();
                    if (TryReadTimeCodesLine(line, paragraph))
                    {
                        paragraph.Text = next;
                        if (!string.IsNullOrWhiteSpace(paragraph.Text))
                            subtitle.Paragraphs.Add(paragraph);
                    }
                    else if (!string.IsNullOrWhiteSpace(line))
                    {
                        _errorCount++;
                    }
                }
                else
                {
                    _errorCount++;
                }
            }

            foreach (Paragraph p in subtitle.Paragraphs)
                p.Text = p.Text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);

            int index = 0;
            foreach (Paragraph p in subtitle.Paragraphs)
            {
                index++;
                Paragraph nextParagraph = subtitle.GetParagraphOrDefault(index);
                if (nextParagraph != null)
                    p.EndTime.TotalMilliseconds = nextParagraph.StartTime.TotalMilliseconds - 1;
                else
                    p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + 2500;
                p.Text = p.Text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
            }

            subtitle.Renumber();
        }
开发者ID:ARASHz4,项目名称:subtitleedit,代码行数:49,代码来源:UnknownSubtitle8.cs

示例12: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            foreach (string line in lines)
            {
                string s = line.Trim();
                if (RegexTimeCodes.Match(s).Success)
                {
                    try
                    {
                        var arr = s.Substring(0, 10).Split(':');
                        if (arr.Length == 4)
                        {
                            var p = new Paragraph();
                            p.StartTime = DecodeTimeCodeFramesFourParts(arr);
                            p.Text = s.Remove(0, 10).Trim();
                            subtitle.Paragraphs.Add(p);
                        }
                    }
                    catch
                    {
                        _errorCount++;
                    }
                }
                else if (s.Length > 0)
                {
                    _errorCount++;
                }
            }

            int index = 1;
            foreach (Paragraph paragraph in subtitle.Paragraphs)
            {
                Paragraph next = subtitle.GetParagraphOrDefault(index);
                if (next != null)
                {
                    paragraph.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
                }
                if (paragraph.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
                {
                    paragraph.EndTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(paragraph.Text);
                }
                index++;
            }

            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
开发者ID:ARASHz4,项目名称:subtitleedit,代码行数:48,代码来源:UnknownSubtitle47.cs

示例13: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            var sb = new StringBuilder();
            lines.ForEach(line => sb.AppendLine(line));
            var xmlAsText = sb.ToString().Trim();
            if (!xmlAsText.Contains("</dl>") || !xmlAsText.Contains(" data-time"))
            {
                return;
            }

            try
            {
                var xml = new XmlDocument { XmlResolver = null };
                xml.LoadXml(xmlAsText);
                foreach (XmlNode node in xml.DocumentElement.SelectNodes("dd/span"))
                {
                    try
                    {
                        var timeCodeIn = new TimeCode(Convert.ToDouble(node.Attributes["data-time"].InnerText));
                        var timeCodeOut = new TimeCode(timeCodeIn.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(node.InnerText));
                        var p = new Paragraph(timeCodeIn, timeCodeOut, Utilities.AutoBreakLine(node.InnerText));
                        subtitle.Paragraphs.Add(p);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                        _errorCount++;
                    }
                }
                subtitle.Sort(SubtitleSortCriteria.StartTime);
                for (int index = 0; index < subtitle.Paragraphs.Count - 1; index++)
                {
                    var paragraph = subtitle.Paragraphs[index];
                    var next = subtitle.GetParagraphOrDefault(index + 1);
                    if (next.StartTime.TotalMilliseconds <= paragraph.EndTime.TotalMilliseconds)
                        paragraph.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
                }
                subtitle.Renumber();
            }
            catch (Exception)
            {
                _errorCount++;
            }
        }
开发者ID:LeonCheung,项目名称:subtitleedit,代码行数:45,代码来源:DlDd.cs

示例14: 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:ItsJustSean,项目名称:subtitleedit,代码行数:19,代码来源:ChangeSpeedInPercent.cs

示例15: Fix

        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixFirstLetterToUppercaseAfterParagraph;
            int fixedStartWithUppercaseLetterAfterParagraphTicked = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                Paragraph prev = subtitle.GetParagraphOrDefault(i - 1);

                string oldText = p.Text;
                string fixedText = DoFix(new Paragraph(p), prev, callbacks.Encoding, callbacks.Language);

                if (oldText != fixedText && callbacks.AllowFix(p, fixAction))
                {
                    p.Text = fixedText;
                    fixedStartWithUppercaseLetterAfterParagraphTicked++;
                    callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            callbacks.UpdateFixStatus(fixedStartWithUppercaseLetterAfterParagraphTicked, language.StartWithUppercaseLetterAfterParagraph, fixedStartWithUppercaseLetterAfterParagraphTicked.ToString(CultureInfo.InvariantCulture));
        }
开发者ID:ItsJustSean,项目名称:subtitleedit,代码行数:22,代码来源:FixStartWithUppercaseLetterAfterParagraph.cs


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