本文整理汇总了C#中Nikse.SubtitleEdit.Logic.Subtitle.Renumber方法的典型用法代码示例。如果您正苦于以下问题:C# Subtitle.Renumber方法的具体用法?C# Subtitle.Renumber怎么用?C# Subtitle.Renumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nikse.SubtitleEdit.Logic.Subtitle
的用法示例。
在下文中一共展示了Subtitle.Renumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public void Initialize(Subtitle subtitle)
{
if (subtitle.Paragraphs.Count > 0)
subtitle.Renumber(subtitle.Paragraphs[0].Number);
Text = Configuration.Settings.Language.MergeDoubleLines.Title;
if (!string.IsNullOrEmpty(Configuration.Settings.Language.MergeDoubleLines.MaxMillisecondsBetweenLines)) //TODO: Remove in SE 3.3.4
{
labelMaxMillisecondsBetweenLines.Text = Configuration.Settings.Language.MergeDoubleLines.MaxMillisecondsBetweenLines;
checkBoxIncludeIncrementing.Text = Configuration.Settings.Language.MergeDoubleLines.IncludeIncrementing;
numericUpDownMaxMillisecondsBetweenLines.Left = labelMaxMillisecondsBetweenLines.Left + labelMaxMillisecondsBetweenLines.Width + 3;
checkBoxIncludeIncrementing.Left = numericUpDownMaxMillisecondsBetweenLines.Left + numericUpDownMaxMillisecondsBetweenLines.Width + 10;
}
listViewFixes.Columns[0].Text = Configuration.Settings.Language.General.Apply;
listViewFixes.Columns[1].Text = Configuration.Settings.Language.General.LineNumber;
listViewFixes.Columns[2].Text = Configuration.Settings.Language.MergedShortLines.MergedText;
buttonOK.Text = Configuration.Settings.Language.General.OK;
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
SubtitleListview1.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings);
Utilities.InitializeSubtitleFont(SubtitleListview1);
SubtitleListview1.AutoSizeAllColumns(this);
NumberOfMerges = 0;
_subtitle = subtitle;
MergeDoubleLines_ResizeEnd(null, null);
}
示例2: Initialize
public void Initialize(Subtitle subtitle)
{
if (subtitle.Paragraphs.Count > 0)
subtitle.Renumber(subtitle.Paragraphs[0].Number);
Text = Configuration.Settings.Language.MergeTextWithSameTimeCodes.Title;
labelMaxDifferenceMS.Text = Configuration.Settings.Language.MergeTextWithSameTimeCodes.MaxDifferenceMilliseconds;
checkBoxAutoBreakOn.Text = Configuration.Settings.Language.MergeTextWithSameTimeCodes.ReBreakLines;
listViewFixes.Columns[0].Text = Configuration.Settings.Language.General.Apply;
listViewFixes.Columns[1].Text = Configuration.Settings.Language.General.LineNumber;
listViewFixes.Columns[2].Text = Configuration.Settings.Language.MergeTextWithSameTimeCodes.MergedText;
buttonOK.Text = Configuration.Settings.Language.General.Ok;
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
SubtitleListview1.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings);
Utilities.InitializeSubtitleFont(SubtitleListview1);
SubtitleListview1.AutoSizeAllColumns(this);
NumberOfMerges = 0;
_subtitle = subtitle;
MergeTextWithSameTimeCodes_ResizeEnd(null, null);
_language = Utilities.AutoDetectGoogleLanguage(subtitle);
}
示例3: Initialize
public void Initialize(Subtitle subtitle)
{
if (subtitle.Paragraphs.Count > 0)
subtitle.Renumber(subtitle.Paragraphs[0].Number);
Text = Configuration.Settings.Language.SplitLongLines.Title;
labelSingleLineMaxLength.Text = Configuration.Settings.Language.SplitLongLines.SingleLineMaximumLength;
labelLineMaxLength.Text = Configuration.Settings.Language.SplitLongLines.LineMaximumLength;
labelLineContinuationBeginEnd.Text = Configuration.Settings.Language.SplitLongLines.LineContinuationBeginEndStrings;
listViewFixes.Columns[0].Text = Configuration.Settings.Language.General.Apply;
listViewFixes.Columns[1].Text = Configuration.Settings.Language.General.LineNumber;
listViewFixes.Columns[2].Text = Configuration.Settings.Language.General.Text;
buttonOK.Text = Configuration.Settings.Language.General.Ok;
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
SubtitleListview1.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings);
Utilities.InitializeSubtitleFont(SubtitleListview1);
SubtitleListview1.AutoSizeAllColumns(this);
NumberOfSplits = 0;
numericUpDownSingleLineMaxCharacters.Value = Configuration.Settings.General.SubtitleLineMaximumLength;
_subtitle = subtitle;
}
示例4: Initialize
public void Initialize(Subtitle subtitle)
{
if (subtitle.Paragraphs.Count > 0)
subtitle.Renumber(subtitle.Paragraphs[0].Number);
Text = Configuration.Settings.Language.MergedShortLines.Title;
labelMaxCharacters.Text = Configuration.Settings.Language.MergedShortLines.MaximumCharacters;
labelMaxMillisecondsBetweenLines.Text = Configuration.Settings.Language.MergedShortLines.MaximumMillisecondsBetween;
checkBoxOnlyContinuationLines.Text = Configuration.Settings.Language.MergedShortLines.OnlyMergeContinuationLines;
listViewFixes.Columns[0].Text = Configuration.Settings.Language.General.Apply;
listViewFixes.Columns[1].Text = Configuration.Settings.Language.General.LineNumber;
listViewFixes.Columns[2].Text = Configuration.Settings.Language.MergedShortLines.MergedText;
buttonOK.Text = Configuration.Settings.Language.General.Ok;
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
SubtitleListview1.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings);
Utilities.InitializeSubtitleFont(SubtitleListview1);
SubtitleListview1.AutoSizeAllColumns(this);
NumberOfMerges = 0;
numericUpDownMaxCharacters.Value = Configuration.Settings.General.SubtitleLineMaximumLength;
_subtitle = subtitle;
}
示例5: InsertMissingParagraphs
private void InsertMissingParagraphs(Subtitle masterSubtitle, Subtitle insertIntoSubtitle)
{
int index = 0;
foreach (Paragraph p in masterSubtitle.Paragraphs)
{
Paragraph insertParagraph = Utilities.GetOriginalParagraph(index, p, insertIntoSubtitle.Paragraphs);
if (insertParagraph == null)
{
insertParagraph = new Paragraph(p);
insertParagraph.Text = string.Empty;
insertIntoSubtitle.InsertParagraphInCorrectTimeOrder(insertParagraph);
}
index++;
}
insertIntoSubtitle.Renumber(1);
}
示例6: pointSyncViaOtherSubtitleToolStripMenuItem_Click
//.........这里部分代码省略.........
{
MessageBox.Show(_language.NoSubtitlesFound);
return;
}
else
{
if (subtitleList.Count > 1)
{
MatroskaSubtitleChooser subtitleChooser = new MatroskaSubtitleChooser();
subtitleChooser.Initialize(subtitleList);
if (_loading)
{
subtitleChooser.Icon = (Icon)this.Icon.Clone();
subtitleChooser.ShowInTaskbar = true;
subtitleChooser.ShowIcon = true;
}
if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
{
sub = LoadMatroskaSubtitleForSync(subtitleList[subtitleChooser.SelectedIndex], fileName);
}
}
else
{
sub = LoadMatroskaSubtitleForSync(subtitleList[0], fileName);
}
}
}
}
}
if (Path.GetExtension(fileName).ToLower() == ".divx" || Path.GetExtension(fileName).ToLower() == ".avi")
{
MessageBox.Show("Divx files not supported here");
return;
}
var fi = new FileInfo(fileName);
if ((Path.GetExtension(fileName).ToLower() == ".mp4" || Path.GetExtension(fileName).ToLower() == ".m4v" || Path.GetExtension(fileName).ToLower() == ".3gp")
&& fi.Length > 10000)
{
var mp4Parser = new Logic.Mp4.Mp4Parser(fileName);
var mp4SubtitleTracks = mp4Parser.GetSubtitleTracks();
if (mp4SubtitleTracks.Count == 0)
{
MessageBox.Show(_language.NoSubtitlesFound);
return;
}
else if (mp4SubtitleTracks.Count == 1)
{
sub = LoadMp4SubtitleForSync(fileName, mp4SubtitleTracks[0]);
}
else
{
var subtitleChooser = new MatroskaSubtitleChooser();
subtitleChooser.Initialize(mp4SubtitleTracks);
if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
{
sub = LoadMp4SubtitleForSync(fileName, mp4SubtitleTracks[0]);
}
}
}
if (fi.Length > 1024 * 1024 * 10 && sub.Paragraphs.Count == 0) // max 10 mb
{
if (MessageBox.Show(this, string.Format(_language.FileXIsLargerThan10Mb + Environment.NewLine +
Environment.NewLine +
_language.ContinueAnyway,
fileName), Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
return;
}
sub.Renumber(1);
if (sub.Paragraphs.Count == 0)
{
SubtitleFormat f = sub.LoadSubtitle(fileName, out enc, null);
if (f == null)
{
ShowUnknownSubtitle();
return;
}
}
pointSync.Initialize(_subtitle, _fileName, _videoFileName, _videoAudioTrackNumber, fileName, sub);
mediaPlayer.Pause();
if (pointSync.ShowDialog(this) == DialogResult.OK)
{
_subtitleListViewIndex = -1;
MakeHistoryForUndo(_language.BeforePointSynchronization);
_subtitle.Paragraphs.Clear();
foreach (Paragraph p in pointSync.FixedSubtitle.Paragraphs)
_subtitle.Paragraphs.Add(p);
_subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate);
ShowStatus(_language.PointSynchronizationDone);
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
}
_videoFileName = pointSync.VideoFileName;
}
}
示例7: GeneratePreviewReal
private void GeneratePreviewReal()
{
_subtitle = new Subtitle();
if (checkBoxMultipleFiles.Visible && checkBoxMultipleFiles.Checked)
ImportMultipleFiles(listViewInputFiles.Items);
else if (radioButtonLineMode.Checked)
ImportLineMode(textBoxText.Lines);
else if (radioButtonAutoSplit.Checked)
ImportAutoSplit(textBoxText.Lines);
else
ImportSplitAtBlankLine(textBoxText.Lines);
if (checkBoxMergeShortLines.Checked)
MergeLinesWithContinuation();
_subtitle.Renumber(1);
if (checkBoxGenerateTimeCodes.Checked)
{
FixDurations();
MakePseudoStartTime();
}
else
{
foreach (Paragraph p in _subtitle.Paragraphs)
{
p.StartTime.TotalMilliseconds = TimeCode.MaxTime.TotalMilliseconds;
p.EndTime.TotalMilliseconds = TimeCode.MaxTime.TotalMilliseconds;
}
}
groupBoxImportResult.Text = string.Format(Configuration.Settings.Language.ImportText.PreviewLinesModifiedX, _subtitle.Paragraphs.Count);
SubtitleListview1.Fill(_subtitle);
SubtitleListview1.SelectIndexAndEnsureVisible(0);
}
示例8: SortAndLoad
private void SortAndLoad()
{
JoinedFormat = new SubRip(); // default subtitle format
string header = null;
SubtitleFormat lastFormat = null;
var subtitles = new List<Subtitle>();
for (int k = 0; k < _fileNamesToJoin.Count; k++)
{
string fileName = _fileNamesToJoin[k];
try
{
var sub = new Subtitle();
Encoding encoding;
var format = sub.LoadSubtitle(fileName, out encoding, null);
if (format == null)
{
for (int j = k; j < _fileNamesToJoin.Count; j++)
_fileNamesToJoin.RemoveAt(j);
MessageBox.Show("Unkown subtitle format: " + fileName);
return;
}
if (sub.Header != null)
header = sub.Header;
if (lastFormat == null || lastFormat.FriendlyName == format.FriendlyName)
lastFormat = format;
else
lastFormat = new SubRip(); // default subtitle format
subtitles.Add(sub);
}
catch (Exception exception)
{
for (int j = k; j < _fileNamesToJoin.Count; j++)
_fileNamesToJoin.RemoveAt(j);
MessageBox.Show(exception.Message);
return;
}
}
JoinedFormat = lastFormat;
for (int outer = 0; outer < subtitles.Count; outer++)
{
for (int inner = 1; inner < subtitles.Count; inner++)
{
var a = subtitles[inner - 1];
var b = subtitles[inner];
if (a.Paragraphs.Count > 0 && b.Paragraphs.Count > 0 && a.Paragraphs[0].StartTime.TotalMilliseconds > b.Paragraphs[0].StartTime.TotalMilliseconds)
{
string t1 = _fileNamesToJoin[inner - 1];
_fileNamesToJoin[inner - 1] = _fileNamesToJoin[inner];
_fileNamesToJoin[inner] = t1;
var t2 = subtitles[inner - 1];
subtitles[inner - 1] = subtitles[inner];
subtitles[inner] = t2;
}
}
}
listViewParts.BeginUpdate();
listViewParts.Items.Clear();
int i = 0;
foreach (string fileName in _fileNamesToJoin)
{
Subtitle sub = subtitles[i];
var lvi = new ListViewItem(string.Format("{0:#,###,###}", sub.Paragraphs.Count));
if (sub.Paragraphs.Count > 0)
{
lvi.SubItems.Add(sub.Paragraphs[0].StartTime.ToString());
lvi.SubItems.Add(sub.Paragraphs[sub.Paragraphs.Count - 1].StartTime.ToString());
}
else
{
lvi.SubItems.Add("-");
lvi.SubItems.Add("-");
}
lvi.SubItems.Add(fileName);
listViewParts.Items.Add(lvi);
i++;
}
listViewParts.EndUpdate();
JoinedSubtitle = new Subtitle();
if (JoinedFormat.FriendlyName != SubRip.NameOfFormat)
JoinedSubtitle.Header = header;
foreach (Subtitle sub in subtitles)
{
foreach (Paragraph p in sub.Paragraphs)
{
JoinedSubtitle.Paragraphs.Add(p);
}
}
JoinedSubtitle.Renumber();
labelTotalLines.Text = string.Format(Configuration.Settings.Language.JoinSubtitles.TotalNumberOfLinesX, JoinedSubtitle.Paragraphs.Count);
}
示例9: SplitLongLinesInSubtitle
//.........这里部分代码省略.........
{
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;
}
splittedSubtitle.Paragraphs.Add(newParagraph1);
splittedSubtitle.Paragraphs.Add(newParagraph2);
added = true;
numberOfSplits++;
}
}
}
}
}
if (!added)
splittedSubtitle.Paragraphs.Add(new Paragraph(p));
}
listViewFixes.ItemChecked += listViewFixes_ItemChecked;
splittedSubtitle.Renumber(1);
return splittedSubtitle;
}
示例10: 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;
}
示例11: LoadBluRaySup
private void LoadBluRaySup()
{
_subtitle = new Subtitle();
_bluRaySubtitles = new List<Nikse.SubtitleEdit.Logic.BluRaySup.BluRaySupParser.PcsData>();
int max = _bluRaySubtitlesOriginal.Count;
for (int i = 0; i < max; i++)
{
var x = _bluRaySubtitlesOriginal[i];
if ((checkBoxShowOnlyForced.Checked && x.IsForced) ||
checkBoxShowOnlyForced.Checked == false)
{
_bluRaySubtitles.Add(x);
Paragraph p = new Paragraph();
p.StartTime = new TimeCode(TimeSpan.FromMilliseconds((x.StartTime + 45) / 90.0));
p.EndTime = new TimeCode(TimeSpan.FromMilliseconds((x.EndTime + 45) / 90.0));
_subtitle.Paragraphs.Add(p);
}
}
_subtitle.Renumber(1);
FixShortDisplayTimes(_subtitle);
subtitleListView1.Fill(_subtitle);
subtitleListView1.SelectIndexAndEnsureVisible(0);
numericUpDownStartNumber.Maximum = max;
if (numericUpDownStartNumber.Maximum > 0 && numericUpDownStartNumber.Minimum <= 1)
numericUpDownStartNumber.Value = 1;
buttonOK.Enabled = true;
buttonCancel.Enabled = true;
buttonStartOcr.Enabled = true;
buttonStop.Enabled = false;
buttonNewCharacterDatabase.Enabled = true;
buttonEditCharacterDatabase.Enabled = true;
buttonStartOcr.Focus();
}
示例12: ImportTimeCodesInFramesAndTextOnSameLine
private Subtitle ImportTimeCodesInFramesAndTextOnSameLine(string[] lines)
{
var regexTimeCodes1 = new Regex(@"\d+", RegexOptions.Compiled);
Paragraph paragraph = null;
var subtitle = new Subtitle();
var sb = new StringBuilder();
foreach (string t in lines)
{
string line = t;
var matches = regexTimeCodes1.Matches(line);
if (matches.Count >= 2)
{
string start = matches[0].ToString();
string end = matches[1].ToString();
if (paragraph != null)
{
paragraph.Text = sb.ToString().Trim();
subtitle.Paragraphs.Add(paragraph);
}
paragraph = new Paragraph();
sb = new StringBuilder();
try
{
if (UseFrames)
{
paragraph.StartFrame = int.Parse(start);
paragraph.EndFrame = int.Parse(end);
paragraph.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);
}
else
{
paragraph.StartTime.TotalMilliseconds = double.Parse(start);
paragraph.EndTime.TotalMilliseconds = double.Parse(end);
}
}
catch
{
paragraph = null;
}
if (matches[0].Index < 9)
{
line = line.Remove(0, matches[0].Index);
}
line = line.Replace(matches[0].ToString(), string.Empty);
line = line.Replace(matches[1].ToString(), string.Empty);
line = line.Trim();
if (line.StartsWith("}{}") || line.StartsWith("][]"))
{
line = line.Remove(0, 3);
}
line = line.Trim();
}
if (paragraph == null || line.Length <= 1)
{
continue;
}
sb.AppendLine(line.Trim());
if (sb.Length > 200)
{
return new Subtitle();
}
}
if (paragraph != null)
{
paragraph.Text = sb.ToString().Trim();
subtitle.Paragraphs.Add(paragraph);
}
subtitle.Renumber();
return subtitle;
}
示例13: ImportTimeCodesOnSameSeperateLineNoMilliseconds
//.........这里部分代码省略.........
.Replace("}", " ")
.Replace("[", " ")
.Replace("]", " ")
.Trim()
.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length == 2)
{
string[] start = arr[0].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
string[] end = arr[1].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
if ((start.Length == 3 || start.Length == 4) && (end.Length == 3 || end.Length == 4))
{
if (start.Length == 3)
{
start = (arr[0].Trim() + ".000").Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
}
if (end.Length == 3)
{
end = (arr[1].Trim() + ".000").Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
}
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 = (arr[0].Trim() + ".000").Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
}
if (end.Length == 3)
{
end = (arr[1].Trim() + ".000").Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
}
if (duration.Length == 3)
{
duration = (arr[2].Trim() + ".000").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);
}
subtitle.Renumber();
return subtitle;
}
示例14: 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;
}
示例15: ImportTimeCodesOnAloneLines
private static Subtitle ImportTimeCodesOnAloneLines(string[] lines)
{
Paragraph paragraph = null;
var subtitle = new Subtitle();
var sb = new StringBuilder();
for (int idx = 0; idx < lines.Length; idx++)
{
string line = lines[idx];
string lineWithPerhapsOnlyNumbers = line
.Replace(" ", string.Empty)
.Replace(".", string.Empty)
.Replace(",", string.Empty)
.Replace("\t", string.Empty)
.Replace(":", string.Empty)
.Replace(";", string.Empty)
.Replace("{", string.Empty)
.Replace("}", string.Empty)
.Replace("[", string.Empty)
.Replace("]", string.Empty)
.Replace("-", string.Empty)
.Replace(">", string.Empty)
.Replace("<", string.Empty);
bool allNumbers = lineWithPerhapsOnlyNumbers.Length > 0;
foreach (char c in lineWithPerhapsOnlyNumbers.Where(c => !char.IsDigit(c)))
{
allNumbers = false;
}
if (allNumbers && lineWithPerhapsOnlyNumbers.Length > 5)
{
string[] arr = line
.Replace("-", " ")
.Replace(">", " ")
.Replace("{", " ")
.Replace("}", " ")
.Replace("[", " ")
.Replace("]", " ")
.Trim()
.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length == 1)
{
string[] tc = arr[0].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
if (paragraph == null || Math.Abs(paragraph.EndTime.TotalMilliseconds) > 0.001)
{
if (paragraph != null)
{
paragraph.Text = sb.ToString().Trim();
subtitle.Paragraphs.Add(paragraph);
sb = new StringBuilder();
}
paragraph = new Paragraph { StartTime = DecodeTime(tc) };
}
else
{
paragraph.EndTime = DecodeTime(tc);
}
}
}
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);
}
subtitle.Renumber();
return subtitle;
}