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


C# Subtitle.Sort方法代码示例

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


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

示例1: 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


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