本文整理汇总了C#中Subtitle.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# Subtitle.Sort方法的具体用法?C# Subtitle.Sort怎么用?C# Subtitle.Sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subtitle
的用法示例。
在下文中一共展示了Subtitle.Sort方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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++;
}
}
示例2: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
var sb = new StringBuilder();
lines.ForEach(line => sb.AppendLine(line));
if (!sb.ToString().Contains("</annotations>") || !sb.ToString().Contains("</TEXT>"))
return;
var xml = new XmlDocument { XmlResolver = null };
try
{
string xmlText = sb.ToString();
xml.LoadXml(xmlText);
var styles = new List<string> { "speech" };
if (_promtForStyles)
{
var stylesWithCount = new Dictionary<string, int>();
foreach (XmlNode node in xml.SelectNodes("//annotation"))
{
try
{
if (node.Attributes["style"] != null && node.Attributes["style"].Value != null)
{
string style = node.Attributes["style"].Value;
XmlNode textNode = node.SelectSingleNode("TEXT");
XmlNodeList regions = node.SelectNodes("segment/movingRegion/anchoredRegion");
if (regions.Count != 2)
regions = node.SelectNodes("segment/movingRegion/rectRegion");
if (textNode != null && regions.Count == 2)
{
if (stylesWithCount.ContainsKey(style))
stylesWithCount[style]++;
else
stylesWithCount.Add(style, 1);
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
if (stylesWithCount.Count > 1 && GetYouTubeAnnotationStyles != null)
{
styles = GetYouTubeAnnotationStyles.GetYouTubeAnnotationStyles(stylesWithCount);
}
else
{
styles.Clear();
foreach (var k in stylesWithCount.Keys)
styles.Add(k);
}
}
else
{
styles.Add("popup");
styles.Add("anchored");
}
foreach (XmlNode node in xml.SelectNodes("//annotation"))
{
try
{
if (node.Attributes["style"] != null && styles.Contains(node.Attributes["style"].Value))
{
XmlNode textNode = node.SelectSingleNode("TEXT");
XmlNodeList regions = node.SelectNodes("segment/movingRegion/anchoredRegion");
if (regions.Count != 2)
regions = node.SelectNodes("segment/movingRegion/rectRegion");
if (textNode != null && regions.Count == 2)
{
string startTime = regions[0].Attributes["t"].Value;
string endTime = regions[1].Attributes["t"].Value;
var p = new Paragraph();
p.StartTime = DecodeTimeCode(startTime);
p.EndTime = DecodeTimeCode(endTime);
p.Text = textNode.InnerText;
subtitle.Paragraphs.Add(p);
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
_errorCount++;
}
}
subtitle.Sort(SubtitleSortCriteria.StartTime); // force order by start time
subtitle.Renumber();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
_errorCount = 1;
//.........这里部分代码省略.........
示例3: LoadSubtitle
//.........这里部分代码省略.........
if (subtitle.Paragraphs.Count < 1)
header.AppendLine(line);
}
else if (line.StartsWith("[al:", StringComparison.Ordinal)) // [al:Album where the song is from]
{
if (subtitle.Paragraphs.Count < 1)
header.AppendLine(line);
}
else if (line.StartsWith("[ti:", StringComparison.Ordinal)) // [ti:Lyrics (song) title]
{
if (subtitle.Paragraphs.Count < 1)
header.AppendLine(line);
}
else if (line.StartsWith("[au:", StringComparison.Ordinal)) // [au:Creator of the Songtext]
{
if (subtitle.Paragraphs.Count < 1)
header.AppendLine(line);
}
else if (line.StartsWith("[length:", StringComparison.Ordinal)) // [length:How long the song is]
{
if (subtitle.Paragraphs.Count < 1)
header.AppendLine(line);
}
else if (line.StartsWith("[by:", StringComparison.Ordinal)) // [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 (RegexTimeCodes.Match(p.Text).Success)
{
string s = p.Text.Substring(1, 8);
p.Text = p.Text.Remove(0, 10).Trim();
string[] parts = s.Split(splitChars, 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(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();
}