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


C# Subtitle.RemoveEmptyLines方法代码示例

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


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

示例1: CleanUp

 private static void CleanUp(Subtitle subtitle)
 {
     foreach (Paragraph p in subtitle.Paragraphs)
     {
         p.Text = p.Text.Replace("<html>", string.Empty);
         p.Text = p.Text.Replace("</html>", string.Empty);
         p.Text = p.Text.Replace("<div>", string.Empty);
         p.Text = p.Text.Replace("</div>", string.Empty);
         p.Text = p.Text.Replace("<body>", string.Empty);
         p.Text = p.Text.Replace("</body>", string.Empty);
         p.Text = p.Text.Replace("<tt>", string.Empty);
         p.Text = p.Text.Replace("</tt>", string.Empty);
         p.Text = p.Text.Replace("<tr>", string.Empty);
         p.Text = p.Text.Replace("</tr>", string.Empty);
         p.Text = p.Text.Replace("<td>", string.Empty);
         p.Text = p.Text.Replace("</td>", string.Empty);
         p.Text = p.Text.Replace("<table>", string.Empty);
         p.Text = p.Text.Replace("</table>", string.Empty);
         p.Text = p.Text.Replace("<br>", Environment.NewLine);
         p.Text = p.Text.Replace("<br/>", Environment.NewLine);
         p.Text = p.Text.Replace("<br />", Environment.NewLine);
         p.Text = p.Text.Replace("&lt;", "<");
         p.Text = p.Text.Replace("&gt;", ">");
         p.Text = p.Text.Replace("  ", " ");
         p.Text = p.Text.Replace("  ", " ");
         p.Text = p.Text.Replace("  ", " ");
         p.Text = p.Text.Replace("|", Environment.NewLine).Replace("<p>", Environment.NewLine).Replace("</p>", Environment.NewLine).Trim();
         p.Text = p.Text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine).Trim();
         p.Text = p.Text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine).Trim();
     }
     subtitle.RemoveEmptyLines();
 }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:32,代码来源:UknownFormatImporter.cs

示例2: OkPressed

        public void OkPressed(Subtitle subtitle)
        {
            WasOkPressed = true;

            FixedSubtitle = new Subtitle(_subtitle, false);
            foreach (var fix in Window.GetFixes())
            {
                var p = FixedSubtitle.GetParagraphOrDefaultById(fix.Id);
                if (p != null)
                {
                    p.Text = fix.After;
                }
            }
            FixedSubtitle.RemoveEmptyLines();
        }
开发者ID:SubtitleEdit,项目名称:subtitleedit-mac,代码行数:15,代码来源:RemoveTextForHearingImpairedController.cs

示例3: TestRemoveEmptyLines

        public void TestRemoveEmptyLines()
        {
            var sub = new Subtitle();
            var p1 = new Paragraph("1", 0, 1000);
            var p2 = new Paragraph(" ", 1000, 2000);
            var p3 = new Paragraph("3", 2000, 3000);
            sub.Paragraphs.Add(p1);
            sub.Paragraphs.Add(p2);
            sub.Paragraphs.Add(p3);

            int removedCount = sub.RemoveEmptyLines();
            Assert.AreEqual(removedCount, 1);
            Assert.AreEqual(sub.Paragraphs.Count, 2);
            Assert.AreEqual(sub.Paragraphs[0], p1);
            Assert.AreEqual(sub.Paragraphs[1], p3);
        }
开发者ID:ARASHz4,项目名称:subtitleedit,代码行数:16,代码来源:SubtitleTest.cs

示例4: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();
            foreach (string s in lines)
                sb.Append(s);

            string allText = sb.ToString();
            if (!allText.Contains("text_tees"))
                return;

            var times = Json.ReadArray(allText, "text_tees");
            var texts = Json.ReadArray(allText, "text_content");

            for (int i = 0; i < Math.Min(times.Count, texts.Count); i++)
            {
                try
                {

                    string text = texts[i];
                    if (text.StartsWith('['))
                    {
                        var textLines = Json.ReadArray("{\"text\":" + texts[i] + "}", "text");
                        var textSb = new StringBuilder();
                        foreach (string line in textLines)
                        {
                            string t = Json.DecodeJsonText(line);
                            if (t.StartsWith("[\"", StringComparison.Ordinal) && t.EndsWith("\"]", StringComparison.Ordinal))
                            {
                                var innerSb = new StringBuilder();
                                var innerTextLines = Json.ReadArray("{\"text\":" + t + "}", "text");
                                foreach (string innerLine in innerTextLines)
                                {
                                    innerSb.Append(' ');
                                    innerSb.Append(innerLine);
                                }
                                textSb.AppendLine(innerSb.ToString().Trim());
                            }
                            else
                            {
                                textSb.AppendLine(t);
                            }
                        }
                        text = textSb.ToString().Trim();
                        text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
                    }
                    var p = new Paragraph(text, int.Parse(times[i]), 0);
                    if (i + 1 < times.Count)
                        p.EndTime.TotalMilliseconds = int.Parse(times[i + 1]);
                    subtitle.Paragraphs.Add(p);
                }
                catch
                {
                    _errorCount++;
                }
            }
            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
开发者ID:socialpercon,项目名称:subtitleedit,代码行数:60,代码来源:JsonType5.cs

示例5: LoadSubtitle

        /// <summary>
        /// The load subtitle.
        /// </summary>
        /// <param name="subtitle">
        /// The subtitle.
        /// </param>
        /// <param name="lines">
        /// The lines.
        /// </param>
        /// <param name="fileName">
        /// The file name.
        /// </param>
        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            bool expectStartTime = true;
            Paragraph p = new Paragraph();
            subtitle.Paragraphs.Clear();
            this._errorCount = 0;
            foreach (string line in lines)
            {
                string s = line.Trim();
                Match match = regexTimeCodes1.Match(s);
                if (match.Success)
                {
                    string[] parts = s.Split(':');
                    if (parts.Length == 4)
                    {
                        try
                        {
                            if (expectStartTime)
                            {
                                p.StartTime = DecodeTimeCode(parts);
                                expectStartTime = false;
                            }
                            else
                            {
                                if (p.EndTime.TotalMilliseconds < 0.01)
                                {
                                    this._errorCount++;
                                }

                                p.EndTime = DecodeTimeCode(parts);
                            }
                        }
                        catch (Exception exception)
                        {
                            this._errorCount++;
                            Debug.WriteLine(exception.Message);
                        }
                    }
                }
                else if (string.IsNullOrWhiteSpace(line))
                {
                    if (p.StartTime.TotalMilliseconds == 0 && p.EndTime.TotalMilliseconds == 0)
                    {
                        this._errorCount++;
                    }
                    else
                    {
                        subtitle.Paragraphs.Add(p);
                    }

                    p = new Paragraph();
                }
                else
                {
                    expectStartTime = true;
                    p.Text = (p.Text + Environment.NewLine + line).Trim();
                    if (p.Text.Length > 500)
                    {
                        this._errorCount += 10;
                        return;
                    }
                }
            }

            if (p.EndTime.TotalMilliseconds > 0)
            {
                subtitle.Paragraphs.Add(p);
            }

            bool allNullEndTime = true;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                if (subtitle.Paragraphs[i].EndTime.TotalMilliseconds != 0)
                {
                    allNullEndTime = false;
                }
            }

            if (allNullEndTime)
            {
                subtitle.Paragraphs.Clear();
            }

            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:98,代码来源:QubeMasterImport.cs

示例6: LoadSubtitle

 public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
 {
     _errorCount = 0;
     Paragraph p = null;
     bool started = false;
     var header = new StringBuilder();
     var text = new StringBuilder();
     foreach (string line in lines)
     {
         try
         {
             if (RegexTimeCodes.Match(line).Success)
             {
                 started = true;
                 if (p != null)
                     p.Text = text.ToString().Trim();
                 text = new StringBuilder();
                 string start = line.Substring(7, 11);
                 string end = line.Substring(19, 11);
                 p = new Paragraph(GetTimeCode(start), GetTimeCode(end), string.Empty);
                 subtitle.Paragraphs.Add(p);
             }
             else if (!started)
             {
                 header.AppendLine(line);
             }
             else if (p != null && p.Text.Length < 200)
             {
                 text.AppendLine(line);
             }
             else
             {
                 _errorCount++;
             }
         }
         catch
         {
             _errorCount++;
         }
     }
     if (p != null)
         p.Text = text.ToString().Trim();
     subtitle.Header = header.ToString();
     subtitle.RemoveEmptyLines();
     subtitle.Renumber();
 }
开发者ID:Team-Vengeance,项目名称:SubtitleEdit,代码行数:46,代码来源:UnknownSubtitle52.cs

示例7: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            var sb = new StringBuilder();
            foreach (string line in lines)
                sb.AppendLine(line);

            string rtf = sb.ToString().Trim();
            if (!rtf.StartsWith("{\\rtf"))
                return;

            string[] arr = null;
            var rtBox = new System.Windows.Forms.RichTextBox();
            try
            {
                rtBox.Rtf = rtf;
                arr = rtBox.Text.Replace("\r", "").Split('\n');
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.Message);
                return;
            }
            finally
            {
                rtBox.Dispose();
            }

            var p = new Paragraph();
            subtitle.Paragraphs.Clear();
            foreach (string line in arr)
            {
                string s = line.Trim();
                if (s.StartsWith('[') && s.EndsWith('>') && s.Length > 13 && s[12] == ']')
                    s = s.Substring(0, 13);

                var match = regexTimeCodes.Match(s);
                if (match.Success)
                {
                    string[] parts = s.Replace("[", string.Empty).Replace("]", string.Empty).Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length == 1)
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(p.Text))
                            {
                                p.EndTime = DecodeTimeCode(parts[0]);
                                subtitle.Paragraphs.Add(p);
                                p = new Paragraph();
                            }
                            else
                            {
                                p.StartTime = DecodeTimeCode(parts[0]);
                            }
                        }
                        catch (Exception exception)
                        {
                            _errorCount++;
                            System.Diagnostics.Debug.WriteLine(exception.Message);
                        }
                    }
                }
                else if (string.IsNullOrWhiteSpace(line))
                {
                }
                else
                {
                    p.Text = (p.Text + Environment.NewLine + line).Trim();
                    if (p.Text.Length > 500)
                    {
                        _errorCount += 10;
                        return;
                    }
                    while (p.Text.Contains(Environment.NewLine + " "))
                        p.Text = p.Text.Replace(Environment.NewLine + " ", Environment.NewLine);
                }
            }
            if (!string.IsNullOrEmpty(p.Text))
                subtitle.Paragraphs.Add(p);

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

示例8: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            subtitle.Paragraphs.Clear();
            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            byte[] array;
            try
            {
                array = FileUtil.ReadAllBytesShared(fileName);
            }
            catch
            {
                _errorCount++;
                return;
            }
            if (array.Length < 100 || array[0] != 84 || array[1] != 83 || array[2] != 66 || array[3] != 52)
            {
                return;
            }
            for (int i = 0; i < array.Length - 20; i++)
            {
                if (array[i] == 84 && array[i + 1] == 73 && array[i + 2] == 84 && array[i + 3] == 76 && array[i + 8] == 84 && array[i + 9] == 73 && array[i + 10] == 77 && array[i + 11] == 69) // TITL + TIME
                {
                    int endOfText = array[i + 4];

                    int start = array[i + 16] + array[i + 17] * 256;
                    if (array[i + 18] != 32)
                        start += array[i + 18] * 256 * 256;

                    int end = array[i + 20] + array[i + 21] * 256;
                    if (array[i + 22] != 32)
                        end += array[i + 22] * 256 * 256;

                    int textStart = i;
                    while (textStart < i + endOfText && !(array[textStart] == 0x4C && array[textStart + 1] == 0x49 && array[textStart + 2] == 0x4E && array[textStart + 3] == 0x45)) // LINE
                    {
                        textStart++;
                    }
                    int length = i + endOfText - textStart - 2;
                    textStart += 8;

                    string text = Encoding.Default.GetString(array, textStart, length);
                    // text = Encoding.Default.GetString(array, i + 53, endOfText - 47);
                    text = text.Trim('\0').Replace("\0", " ").Trim();
                    var item = new Paragraph(text, FramesToMilliseconds(start), FramesToMilliseconds(end));
                    subtitle.Paragraphs.Add(item);
                    i += endOfText + 5;
                }
            }
            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
开发者ID:aisam97,项目名称:subtitleedit,代码行数:55,代码来源:TSB4.cs

示例9: LoadSubtitle


//.........这里部分代码省略.........
                    }

                    if (text.EndsWith('"'))
                    {
                        text = text.Remove(text.Length - 1, 1);
                    }

                    long number;
                    if (long.TryParse(milliseconds, out number))
                    {
                        subtitle.Paragraphs.Add(new Paragraph(text, number, number));
                    }
                    else
                    {
                        this._errorCount++;
                    }
                }
            }

            sb = new StringBuilder();
            Subtitle sub = new Subtitle();
            double startMilliseconds = 0;
            if (subtitle.Paragraphs.Count > 0)
            {
                startMilliseconds = subtitle.Paragraphs[0].StartTime.TotalMilliseconds;
            }

            for (int i = 0; i < subtitle.Paragraphs.Count - 1; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                Paragraph next = subtitle.Paragraphs[i + 1];
                Paragraph prev = subtitle.GetParagraphOrDefault(i - 1);
                if (sb.Length + p.Text.Length > (Configuration.Settings.General.SubtitleLineMaximumLength * 2) - 15)
                {
                    // text too big
                    Paragraph newParagraph = new Paragraph(sb.ToString(), startMilliseconds, prev.EndTime.TotalMilliseconds);
                    sub.Paragraphs.Add(newParagraph);
                    sb = new StringBuilder();
                    if (!string.IsNullOrWhiteSpace(p.Text))
                    {
                        sb.Append(p.Text);
                        startMilliseconds = p.StartTime.TotalMilliseconds;
                    }
                }
                else if (next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds > 2000)
                {
                    // long time to next sub
                    if (!string.IsNullOrWhiteSpace(p.Text))
                    {
                        sb.Append(' ');
                        sb.Append(p.Text);
                    }

                    Paragraph newParagraph = new Paragraph(sb.ToString(), startMilliseconds, next.StartTime.TotalMilliseconds);
                    sub.Paragraphs.Add(newParagraph);
                    sb = new StringBuilder();
                    startMilliseconds = next.StartTime.TotalMilliseconds;
                }
                else if (string.IsNullOrWhiteSpace(p.Text))
                {
                    // empty text line
                    if (string.IsNullOrWhiteSpace(next.Text) && sb.Length > 0)
                    {
                        Paragraph newParagraph = new Paragraph(sb.ToString(), startMilliseconds, next.StartTime.TotalMilliseconds);
                        sub.Paragraphs.Add(newParagraph);
                        sb = new StringBuilder();
                    }
                }
                else
                {
                    // just add word to current sub
                    if (sb.Length == 0)
                    {
                        startMilliseconds = p.StartTime.TotalMilliseconds;
                    }

                    if (!string.IsNullOrWhiteSpace(p.Text))
                    {
                        sb.Append(' ');
                        sb.Append(p.Text);
                    }
                }
            }

            if (sb.Length > 0)
            {
                Paragraph newParagraph = new Paragraph(sb.ToString().Trim(), startMilliseconds, Utilities.GetOptimalDisplayMilliseconds(sb.ToString()));
                sub.Paragraphs.Add(newParagraph);
            }

            subtitle.Paragraphs.Clear();
            foreach (Paragraph p in sub.Paragraphs)
            {
                p.Text = Utilities.AutoBreakLine(p.Text);
                subtitle.Paragraphs.Add(new Paragraph(p));
            }

            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:101,代码来源:JsonType6.cs

示例10: LoadSubtitle


//.........这里部分代码省略.........
                                        if (innerInnerNode.Name == "br")
                                        {
                                            pText.AppendLine();
                                        }
                                        else
                                        {
                                            pText.Append(innerInnerNode.InnerText);
                                        }
                                    }
                                }
                                else
                                {
                                    pText.Append(innerNode.InnerText);
                                }

                                if (italic)
                                {
                                    pText.Append("</i>");
                                }

                                break;
                            case "i":
                                pText.Append("<i>" + innerNode.InnerText + "</i>");
                                break;
                            case "b":
                                pText.Append("<b>" + innerNode.InnerText + "</b>");
                                break;
                            default:
                                pText.Append(innerNode.InnerText);
                                break;
                        }
                    }

                    string start = null; // = node.Attributes["begin"].InnerText;
                    string end = null; // = node.Attributes["begin"].InnerText;
                    string dur = null; // = node.Attributes["begin"].InnerText;
                    foreach (XmlAttribute attr in node.Attributes)
                    {
                        if (attr.Name.EndsWith("begin", StringComparison.Ordinal))
                        {
                            start = attr.InnerText;
                        }
                        else if (attr.Name.EndsWith("end", StringComparison.Ordinal))
                        {
                            end = attr.InnerText;
                        }
                        else if (attr.Name.EndsWith("duration", StringComparison.Ordinal))
                        {
                            dur = attr.InnerText;
                        }
                    }

                    // string start = node.Attributes["begin"].InnerText;
                    string text = pText.ToString();
                    text = text.Replace(Environment.NewLine + "</i>", "</i>" + Environment.NewLine);
                    text = text.Replace("<i></i>", string.Empty).Trim();
                    if (end != null)
                    {
                        // string end = node.Attributes["end"].InnerText;
                        double dBegin, dEnd;
                        if (!start.Contains(':') && Utilities.CountTagInText(start, '.') == 1 && !end.Contains(':') && Utilities.CountTagInText(end, '.') == 1 && double.TryParse(start, out dBegin) && double.TryParse(end, out dEnd))
                        {
                            subtitle.Paragraphs.Add(new Paragraph(text, dBegin * TimeCode.BaseUnit, dEnd * TimeCode.BaseUnit));
                        }
                        else
                        {
                            if (start.Length == 8 && start[2] == ':' && start[5] == ':' && end.Length == 8 && end[2] == ':' && end[5] == ':')
                            {
                                Paragraph p = new Paragraph();
                                string[] parts = start.Split(':');
                                p.StartTime = new TimeCode(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), 0);
                                parts = end.Split(':');
                                p.EndTime = new TimeCode(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), 0);
                                p.Text = text;
                                subtitle.Paragraphs.Add(p);
                            }
                            else
                            {
                                subtitle.Paragraphs.Add(new Paragraph(TimedText10.GetTimeCode(start, false), TimedText10.GetTimeCode(end, false), text));
                            }
                        }
                    }
                    else if (dur != null)
                    {
                        TimeCode duration = TimedText10.GetTimeCode(dur, false);
                        TimeCode startTime = TimedText10.GetTimeCode(start, false);
                        TimeCode endTime = new TimeCode(startTime.TotalMilliseconds + duration.TotalMilliseconds);
                        subtitle.Paragraphs.Add(new Paragraph(startTime, endTime, text));
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    this._errorCount++;
                }
            }

            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:101,代码来源:TimedText.cs

示例11: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            this._errorCount = 0;
            Paragraph p = null;
            foreach (string line in lines)
            {
                if (line.StartsWith("# SUBTITLE"))
                {
                    if (p != null)
                    {
                        subtitle.Paragraphs.Add(p);
                    }

                    p = new Paragraph();
                }
                else if (p != null && line.StartsWith("# TIMEIN"))
                {
                    string timeCode = line.Remove(0, 8).Trim();
                    if (timeCode != "--:--:--:--" && !GetTimeCode(p.StartTime, timeCode))
                    {
                        this._errorCount++;
                    }
                }
                else if (p != null && line.StartsWith("# DURATION"))
                {
                    // # DURATION 01:17 AUTO
                    string timecode = line.Remove(0, 10).Replace("AUTO", string.Empty).Trim();
                    if (timecode != "--:--")
                    {
                        string[] arr = timecode.Split(':', ' ');
                        if (arr.Length > 1)
                        {
                            int sec;
                            int frame;
                            if (int.TryParse(arr[0], out sec) && int.TryParse(arr[1], out frame))
                            {
                                p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + FramesToMillisecondsMax999(frame);
                                p.EndTime.TotalSeconds += sec;
                            }
                        }
                    }
                }
                else if (p != null && line.StartsWith("# TIMEOUT"))
                {
                    string timeCode = line.Remove(0, 9).Trim();
                    if (timeCode != "--:--:--:--" && !GetTimeCode(p.EndTime, timeCode))
                    {
                        this._errorCount++;
                    }
                }
                else if (p != null && !line.StartsWith('#'))
                {
                    if (p.Text.Length > 500)
                    {
                        this._errorCount += 10;
                        return;
                    }

                    p.Text = (p.Text + Environment.NewLine + line).Trim();
                }
            }

            if (p != null)
            {
                subtitle.Paragraphs.Add(p);
            }

            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:70,代码来源:SwiftInterchange2.cs

示例12: LoadSubtitle


//.........这里部分代码省略.........
                    if (subtitle.Paragraphs.Count < 1)
                        header.AppendLine(line);
                }
                else if (line.StartsWith("[al:")) // [al:Album where the song is from]
                {
                    if (subtitle.Paragraphs.Count < 1)
                        header.AppendLine(line);
                }
                else if (line.StartsWith("[ti:")) // [ti:Lyrics (song) title]
                {
                    if (subtitle.Paragraphs.Count < 1)
                        header.AppendLine(line);
                }
                else if (line.StartsWith("[au:")) // [au:Creator of the Songtext]
                {
                    if (subtitle.Paragraphs.Count < 1)
                        header.AppendLine(line);
                }
                else if (line.StartsWith("[length:")) // [length:How long the song is]
                {
                    if (subtitle.Paragraphs.Count < 1)
                        header.AppendLine(line);
                }
                else if (line.StartsWith("[by:")) // [by:Creator of the LRC file]
                {
                    if (subtitle.Paragraphs.Count < 1)
                        header.AppendLine(line);
                }
                else if (!string.IsNullOrWhiteSpace(line))
                {
                    if (subtitle.Paragraphs.Count < 1)
                        header.AppendLine(line);
                    _errorCount++;
                }
                else if (subtitle.Paragraphs.Count < 1)
                {
                    header.AppendLine(line);
                }
            }
            subtitle.Header = header.ToString();

            int max = subtitle.Paragraphs.Count;
            for (int i = 0; i < max; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                while (_timeCode.Match(p.Text).Success)
                {
                    string s = p.Text.Substring(1, 8);
                    p.Text = p.Text.Remove(0, 10).Trim();
                    string[] parts = s.Split(new[] { ':', '.' }, StringSplitOptions.RemoveEmptyEntries);
                    try
                    {
                        int minutes = int.Parse(parts[0]);
                        int seconds = int.Parse(parts[1]);
                        int milliseconds = int.Parse(parts[2]) * 10;
                        string text = GetTextAfterTimeCodes(p.Text);
                        var start = new TimeCode(0, minutes, seconds, milliseconds);
                        var newParagraph = new Paragraph(start, new TimeCode(0, 0, 0, 0), text);
                        subtitle.Paragraphs.Add(newParagraph);
                    }
                    catch
                    {
                        _errorCount++;
                    }
                }
            }

            subtitle.Sort(Enums.SubtitleSortCriteria.StartTime);

            int index = 0;
            foreach (Paragraph p in subtitle.Paragraphs)
            {
                p.Text = Utilities.AutoBreakLine(p.Text);
                Paragraph next = subtitle.GetParagraphOrDefault(index + 1);
                if (next != null)
                {
                    if (string.IsNullOrEmpty(next.Text))
                    {
                        p.EndTime = new TimeCode(next.StartTime.TotalMilliseconds);
                    }
                    else
                    {
                        p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
                    }
                    if (p.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
                    {
                        double duration = Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
                        p.EndTime = new TimeCode(p.StartTime.TotalMilliseconds + duration);
                    }
                }
                else
                {
                    double duration = Utilities.GetOptimalDisplayMilliseconds(p.Text, 16) + 1500;
                    p.EndTime = new TimeCode(p.StartTime.TotalMilliseconds + duration);
                }
                index++;
            }
            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
开发者ID:socialpercon,项目名称:subtitleedit,代码行数:101,代码来源:Lrc.cs

示例13: 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 && !UnknownSubtitle59.RegexTimeCodes.IsMatch(s))
                {
                    if (p != null && !string.IsNullOrEmpty(p.Text))
                        subtitle.Paragraphs.Add(p);
                    p = new Paragraph();

                    try
                    {
                        string[] arr = s.Substring(0, 8).Split(':');
                        if (arr.Length == 3)
                        {
                            int hours = int.Parse(arr[0]);
                            int minutes = int.Parse(arr[1]);
                            int seconds = int.Parse(arr[2]);
                            p.StartTime = new TimeCode(hours, minutes, seconds, 0);
                            string text = s.Remove(0, 8).Trim();
                            p.Text = text;
                            if (text.Length > 1 && Utilities.IsInteger(text.Substring(0, 2)))
                                _errorCount++;
                        }
                    }
                    catch
                    {
                        _errorCount++;
                    }
                }
                else if (line.StartsWith("\t") && p != null)
                {
                    if (p.Text.Length > 1000)
                    {
                        _errorCount += 100;
                        return;
                    }
                    p.Text = (p.Text + Environment.NewLine + s).Trim();
                }
                else if (s.Length > 0 && !Utilities.IsInteger(s))
                {
                    _errorCount++;
                }
            }
            if (p != null && !string.IsNullOrEmpty(p.Text))
                subtitle.Paragraphs.Add(p);

            int index = 1;
            foreach (Paragraph paragraph in subtitle.Paragraphs)
            {
                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:Team-Vengeance,项目名称:SubtitleEdit,代码行数:67,代码来源:UnknownSubtitle34.cs

示例14: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            bool expectStartTime = true;
            bool expectActor = false;
            var p = new Paragraph();
            subtitle.Paragraphs.Clear();
            foreach (string line in lines)
            {
                string s = line.Trim();
                var match = regexTimeCodes1.Match(s);
                if (match.Success && s.Length == 11)
                {
                    if (p.StartTime.TotalMilliseconds > 0)
                    {
                        subtitle.Paragraphs.Add(p);
                        if (string.IsNullOrEmpty(p.Text))
                            _errorCount++;
                    }

                    p = new Paragraph();
                    string[] parts = s.Split(':');
                    if (parts.Length == 4)
                    {
                        try
                        {
                            p.StartTime = DecodeTimeCode(parts);
                            expectActor = true;
                            expectStartTime = false;
                        }
                        catch (Exception exception)
                        {
                            _errorCount++;
                            System.Diagnostics.Debug.WriteLine(exception.Message);
                            expectStartTime = true;
                        }
                    }
                }
                else if (!string.IsNullOrWhiteSpace(line) && expectActor)
                {
                    if (line == line.ToUpper())
                        p.Actor = line;
                    else
                        _errorCount++;
                    expectActor = false;
                }
                else if (!string.IsNullOrWhiteSpace(line) && !expectActor && !expectStartTime)
                {
                    p.Text = (p.Text + Environment.NewLine + line).Trim();
                    if (p.Text.Length > 5000)
                    {
                        _errorCount += 10;
                        return;
                    }
                }
            }
            if (p.StartTime.TotalMilliseconds > 0)
                subtitle.Paragraphs.Add(p);

            bool allNullEndTime = true;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                p = subtitle.Paragraphs[i];
                if (p.EndTime.TotalMilliseconds != 0)
                    allNullEndTime = false;

                p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(p.Text);
                if (i < subtitle.Paragraphs.Count - 2 && p.EndTime.TotalMilliseconds >= subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds)
                    p.EndTime.TotalMilliseconds = subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
            }
            if (!allNullEndTime)
                subtitle.Paragraphs.Clear();

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

示例15: LoadSubtitle


//.........这里部分代码省略.........
            else
            {
                i = 230;
                int countTimecodes = 0;
                int start = i;
                int lastNumber = -1;
                while (i < buffer.Length - 66)
                {
                    if (buffer[i] == 0xff && buffer[i + 1] == 0xff && buffer[i + 2] == 0xff && buffer[i + 3] == 0xff)
                    {
                        int length = i - start - 2;
                        if (length >= 10)
                        {
                            int count = length / 14;
                            if (length % 14 == 10)
                            {
                                count++;
                            }
                            else
                            {
                                // System.Windows.Forms.MessageBox.Show("Problem at with a length of " + length.ToString() + " at file position " + (i + 2) + " which gives remainer: " + (length % 14));
                                if (length % 14 == 8)
                                {
                                    count++;
                                }
                            }

                            for (int k = 0; k < count; k++)
                            {
                                int index = start + 2 + (14 * k);
                                int number = buffer[index] + buffer[index + 1] * 256;
                                if (number != lastNumber + 1)
                                {
                                    int tempNumber = buffer[index - 2] + buffer[index - 1] * 256;
                                    if (tempNumber == lastNumber + 1)
                                    {
                                        index -= 2;
                                        number = tempNumber;
                                    }
                                }

                                if (number > lastNumber)
                                {
                                    lastNumber = number;
                                    Paragraph p = subtitle.GetParagraphOrDefault(number);
                                    if (p != null)
                                    {
                                        if (k < count - 1)
                                        {
                                            p.StartTime = DecodeTimeCode(buffer, index + 6);
                                            p.EndTime = DecodeTimeCode(buffer, index + 10);
                                        }
                                        else
                                        {
                                            p.StartTime = DecodeTimeCode(buffer, index + 6);
                                        }

                                        countTimecodes++;
                                    }
                                }
                            }
                        }

                        start = i + 2;
                        i += 5;
                    }

                    i++;
                }
            }

            for (i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.GetParagraphOrDefault(i);
                Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
                if (next != null && p.EndTime.TotalMilliseconds == 0)
                {
                    p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
                }
            }

            for (i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.GetParagraphOrDefault(i);
                Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
                if (p.Duration.TotalMilliseconds <= 0 && next != null)
                {
                    p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
                }
            }

            subtitle.RemoveEmptyLines();
            Paragraph last = subtitle.GetParagraphOrDefault(subtitle.Paragraphs.Count - 1);
            if (last != null)
            {
                last.EndTime.TotalMilliseconds = last.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(last.Text);
            }

            subtitle.Renumber();
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:101,代码来源:NciCaption.cs


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