本文整理汇总了C#中Nikse.SubtitleEdit.Logic.Subtitle.CalculateTimeCodesFromFrameNumbers方法的典型用法代码示例。如果您正苦于以下问题:C# Subtitle.CalculateTimeCodesFromFrameNumbers方法的具体用法?C# Subtitle.CalculateTimeCodesFromFrameNumbers怎么用?C# Subtitle.CalculateTimeCodesFromFrameNumbers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nikse.SubtitleEdit.Logic.Subtitle
的用法示例。
在下文中一共展示了Subtitle.CalculateTimeCodesFromFrameNumbers方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendTextVisuallyToolStripMenuItemClick
private void AppendTextVisuallyToolStripMenuItemClick(object sender, EventArgs e)
{
if (IsSubtitleLoaded)
{
ReloadFromSourceView();
if (MessageBox.Show(_language.SubtitleAppendPrompt, _language.SubtitleAppendPromptTitle, MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
{
openFileDialog1.Title = _language.OpenSubtitleToAppend;
openFileDialog1.FileName = string.Empty;
openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
bool success = false;
string fileName = openFileDialog1.FileName;
if (File.Exists(fileName))
{
var subtitleToAppend = new Subtitle();
Encoding encoding;
SubtitleFormat format = null;
// do not allow blu-ray/vobsub
string extension = Path.GetExtension(fileName).ToLower();
if (extension == ".sub" && (IsVobSubFile(fileName, false) || IsSpDvdSupFile(fileName)))
{
format = null;
}
else if (extension == ".sup" && IsBluRaySupFile(fileName))
{
format = null;
}
else
{
format = subtitleToAppend.LoadSubtitle(fileName, out encoding, null);
if (GetCurrentSubtitleFormat().IsFrameBased)
subtitleToAppend.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
else
subtitleToAppend.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
}
if (format != null)
{
if (subtitleToAppend != null && subtitleToAppend.Paragraphs.Count > 1)
{
var visualSync = new VisualSync();
visualSync.Initialize(toolStripButtonVisualSync.Image as Bitmap, subtitleToAppend, _fileName, _language.AppendViaVisualSyncTitle, CurrentFrameRate);
visualSync.ShowDialog(this);
if (visualSync.OKPressed)
{
if (MessageBox.Show(_language.AppendSynchronizedSubtitlePrompt, _language.SubtitleAppendPromptTitle, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
int start = _subtitle.Paragraphs.Count +1;
var fr = CurrentFrameRate;
MakeHistoryForUndo(_language.BeforeAppend);
foreach (Paragraph p in visualSync.Paragraphs)
{
if (format.IsFrameBased)
p.CalculateFrameNumbersFromTimeCodes(fr);
_subtitle.Paragraphs.Add(new Paragraph(p));
}
if (format.GetType() == typeof(AdvancedSubStationAlpha) && GetCurrentSubtitleFormat().GetType() == typeof(AdvancedSubStationAlpha))
{
List<string> currentStyles = new List<string>();
if (_subtitle.Header != null)
currentStyles = AdvancedSubStationAlpha.GetStylesFromHeader(_subtitle.Header);
foreach (string styleName in AdvancedSubStationAlpha.GetStylesFromHeader(subtitleToAppend.Header))
{
bool alreadyExists = false;
foreach (string currentStyleName in currentStyles)
{
if (currentStyleName.ToLower().Trim() == styleName.ToLower().Trim())
alreadyExists = true;
}
if (!alreadyExists)
{
var newStyle = AdvancedSubStationAlpha.GetSsaStyle(styleName, subtitleToAppend.Header);
_subtitle.Header = AdvancedSubStationAlpha.AddSsaStyle(newStyle, _subtitle.Header);
}
}
}
_subtitle.Renumber(1);
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
// select appended lines
for (int i = start; i < _subtitle.Paragraphs.Count; i++)
SubtitleListview1.Items[i].Selected = true;
SubtitleListview1.EnsureVisible(start);
ShowStatus(string.Format(_language.SubtitleAppendedX, fileName));
success = true;
}
}
visualSync.Dispose();
}
}
}
if (!success)
//.........这里部分代码省略.........
示例2: BatchConvertSave
internal static bool BatchConvertSave(string toFormat, string offset, Encoding targetEncoding, string outputFolder, int count, ref int converted, ref int errors, IList<SubtitleFormat> formats, string fileName, Subtitle sub, SubtitleFormat format, bool overwrite, string pacCodePage)
{
// adjust offset
if (!string.IsNullOrEmpty(offset) && (offset.StartsWith("/offset:") || offset.StartsWith("offset:")))
{
string[] parts = offset.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 5)
{
try
{
TimeSpan ts = new TimeSpan(0, int.Parse(parts[1].TrimStart('-')), int.Parse(parts[2]), int.Parse(parts[3]), int.Parse(parts[4]));
if (parts[1].StartsWith("-"))
sub.AddTimeToAllParagraphs(ts.Negate());
else
sub.AddTimeToAllParagraphs(ts);
}
catch
{
Console.Write(" (unable to read offset " + offset + ")");
}
}
}
bool targetFormatFound = false;
string outputFileName;
foreach (SubtitleFormat sf in formats)
{
if (sf.Name.ToLower().Replace(" ", string.Empty) == toFormat.ToLower() || sf.Name.ToLower().Replace(" ", string.Empty) == toFormat.Replace(" ", string.Empty).ToLower())
{
targetFormatFound = true;
sf.BatchMode = true;
outputFileName = FormatOutputFileNameForBatchConvert(fileName, sf.Extension, outputFolder, overwrite);
Console.Write(string.Format("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName));
if (sf.IsFrameBased && !sub.WasLoadedWithFrameNumbers)
sub.CalculateFrameNumbersFromTimeCodesNoCheck(Configuration.Settings.General.CurrentFrameRate);
else if (sf.IsTimeBased && sub.WasLoadedWithFrameNumbers)
sub.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);
File.WriteAllText(outputFileName, sub.ToText(sf), targetEncoding);
if (format.GetType() == typeof(Sami) || format.GetType() == typeof(SamiModern))
{
var sami = (Sami)format;
foreach (string className in Sami.GetStylesFromHeader(sub.Header))
{
var newSub = new Subtitle();
foreach (Paragraph p in sub.Paragraphs)
{
if (p.Extra != null && p.Extra.ToLower().Trim() == className.ToLower().Trim())
newSub.Paragraphs.Add(p);
}
if (newSub.Paragraphs.Count > 0 && newSub.Paragraphs.Count < sub.Paragraphs.Count)
{
string s = fileName;
if (s.LastIndexOf('.') > 0)
s = s.Insert(s.LastIndexOf('.'), "_" + className);
else
s += "_" + className + format.Extension;
outputFileName = FormatOutputFileNameForBatchConvert(s, sf.Extension, outputFolder, overwrite);
File.WriteAllText(outputFileName, newSub.ToText(sf), targetEncoding);
}
}
}
Console.WriteLine(" done.");
}
}
if (!targetFormatFound)
{
var ebu = new Ebu();
if (ebu.Name.ToLower().Replace(" ", string.Empty) == toFormat.ToLower())
{
targetFormatFound = true;
outputFileName = FormatOutputFileNameForBatchConvert(fileName, ebu.Extension, outputFolder, overwrite);
Console.Write(string.Format("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName));
ebu.Save(outputFileName, sub);
Console.WriteLine(" done.");
}
}
if (!targetFormatFound)
{
var pac = new Pac();
if (pac.Name.ToLower().Replace(" ", string.Empty) == toFormat.ToLower() || toFormat.ToLower() == "pac" || toFormat.ToLower() == ".pac")
{
pac.BatchMode = true;
if (!string.IsNullOrEmpty(pacCodePage) && Utilities.IsInteger(pacCodePage))
pac.CodePage = Convert.ToInt32(pacCodePage);
targetFormatFound = true;
outputFileName = FormatOutputFileNameForBatchConvert(fileName, pac.Extension, outputFolder, overwrite);
Console.Write(string.Format("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName));
pac.Save(outputFileName, sub);
Console.WriteLine(" done.");
}
}
if (!targetFormatFound)
{
var cavena890 = new Cavena890();
if (cavena890.Name.ToLower().Replace(" ", string.Empty) == toFormat.ToLower())
{
targetFormatFound = true;
outputFileName = FormatOutputFileNameForBatchConvert(fileName, cavena890.Extension, outputFolder, overwrite);
Console.Write(string.Format("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName));
cavena890.Save(outputFileName, sub);
//.........这里部分代码省略.........
示例3: ToolStripMenuItemInsertSubtitleClick
private void ToolStripMenuItemInsertSubtitleClick(object sender, EventArgs e)
{
openFileDialog1.Title = _languageGeneral.OpenSubtitle;
openFileDialog1.FileName = string.Empty;
openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
if (!File.Exists(openFileDialog1.FileName))
return;
var fi = new FileInfo(openFileDialog1.FileName);
if (fi.Length > 1024 * 1024 * 10) // max 10 mb
{
if (MessageBox.Show(string.Format(_language.FileXIsLargerThan10Mb + Environment.NewLine +
Environment.NewLine +
_language.ContinueAnyway,
openFileDialog1.FileName), Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
return;
}
MakeHistoryForUndo(string.Format(_language.BeforeInsertLine, openFileDialog1.FileName));
Encoding encoding = null;
var subtitle = new Subtitle();
SubtitleFormat format = subtitle.LoadSubtitle(openFileDialog1.FileName, out encoding, encoding);
if (format != null)
{
SaveSubtitleListviewIndexes();
if (format.IsFrameBased)
subtitle.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
else
subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
if (Configuration.Settings.General.RemoveBlankLinesWhenOpening)
subtitle.RemoveEmptyLines();
int index = FirstSelectedIndex + 1;
if (index < 0)
index = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
_subtitle.Paragraphs.Insert(index, new Paragraph(p));
index++;
}
if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
{
index = FirstSelectedIndex;
if (index < 0)
index = 0;
Paragraph current = _subtitle.GetParagraphOrDefault(index);
if (current != null)
{
Paragraph original = Utilities.GetOriginalParagraph(index, current, _subtitleAlternate.Paragraphs);
if (original != null)
{
index = _subtitleAlternate.GetIndex(original);
foreach (Paragraph p in subtitle.Paragraphs)
{
_subtitleAlternate.Paragraphs.Insert(index, new Paragraph(p));
index++;
}
if (subtitle.Paragraphs.Count > 0)
_subtitleAlternate.Renumber(1);
}
}
}
_subtitle.Renumber(1);
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
RestoreSubtitleListviewIndexes();
}
}
}
示例4: toolStripMenuItemInsertTextFromSub_Click
private void toolStripMenuItemInsertTextFromSub_Click(object sender, EventArgs e)
{
openFileDialog1.Title = _languageGeneral.OpenSubtitle;
openFileDialog1.FileName = string.Empty;
openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
if (!File.Exists(openFileDialog1.FileName))
return;
var fi = new FileInfo(openFileDialog1.FileName);
if (fi.Length > 1024 * 1024 * 10) // max 10 mb
{
if (MessageBox.Show(string.Format(_language.FileXIsLargerThan10Mb + Environment.NewLine +
Environment.NewLine +
_language.ContinueAnyway,
openFileDialog1.FileName), Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
return;
}
Encoding encoding = null;
var tmp = new Subtitle();
SubtitleFormat format = tmp.LoadSubtitle(openFileDialog1.FileName, out encoding, encoding);
if (format != null)
{
if (format.IsFrameBased)
tmp.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
else
tmp.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
if (Configuration.Settings.General.RemoveBlankLinesWhenOpening)
tmp.RemoveEmptyLines();
if (SubtitleListview1.SelectedIndices.Count < 1)
return;
MakeHistoryForUndo(_language.BeforeColumnShiftCellsDown);
int index = FirstSelectedIndex;
for (int i = 0; i < tmp.Paragraphs.Count; i++)
{
{
for (int k = _subtitle.Paragraphs.Count - 2; k > index; k--)
{
_subtitle.Paragraphs[k + 1].Text = _subtitle.Paragraphs[k].Text;
}
}
}
for (int i = 0; i + index < _subtitle.Paragraphs.Count && i < tmp.Paragraphs.Count; i++)
_subtitle.Paragraphs[index + i].Text = tmp.Paragraphs[i].Text;
if (IsFramesRelevant && CurrentFrameRate > 0)
_subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate);
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
SubtitleListview1.SelectIndexAndEnsureVisible(index, true);
RefreshSelectedParagraph();
}
}
}
示例5: LoadAlternateSubtitleFile
//.........这里部分代码省略.........
{
pac.BatchMode = true;
pac.LoadSubtitle(_subtitleAlternate, null, fileName);
format = pac;
}
}
if (format == null)
{
var cavena890 = new Cavena890();
if (cavena890.IsMine(null, fileName))
{
cavena890.LoadSubtitle(_subtitleAlternate, null, fileName);
format = cavena890;
}
}
if (format == null)
{
var spt = new Spt();
if (spt.IsMine(null, fileName))
{
spt.LoadSubtitle(_subtitleAlternate, null, fileName);
format = spt;
}
}
if (format == null)
{
var cheetahCaption = new CheetahCaption();
if (cheetahCaption.IsMine(null, fileName))
{
cheetahCaption.LoadSubtitle(_subtitleAlternate, null, fileName);
format = cheetahCaption;
}
}
if (format == null)
{
var capMakerPlus = new CapMakerPlus();
if (capMakerPlus.IsMine(null, fileName))
{
capMakerPlus.LoadSubtitle(_subtitleAlternate, null, fileName);
format = capMakerPlus;
}
}
if (format == null)
{
var captionate = new Captionate();
if (captionate.IsMine(null, fileName))
{
captionate.LoadSubtitle(_subtitleAlternate, null, fileName);
format = captionate;
}
}
if (format == null)
{
var ultech130 = new Ultech130();
if (ultech130.IsMine(null, fileName))
{
ultech130.LoadSubtitle(_subtitleAlternate, null, fileName);
format = ultech130;
}
}
if (format == null)
{
var nciCaption = new NciCaption();
if (nciCaption.IsMine(null, fileName))
{
nciCaption.LoadSubtitle(_subtitleAlternate, null, fileName);
format = nciCaption;
}
}
if (format == null)
{
var tsb4 = new TSB4();
if (tsb4.IsMine(null, fileName))
{
tsb4.LoadSubtitle(_subtitleAlternate, null, fileName);
format = tsb4;
}
}
if (format == null)
{
var avidStl = new AvidStl();
if (avidStl.IsMine(null, fileName))
{
avidStl.LoadSubtitle(_subtitleAlternate, null, fileName);
format = avidStl;
}
}
if (format == null)
return false;
if (format.IsFrameBased)
_subtitleAlternate.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
else
_subtitleAlternate.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
SetupAlternateEdit();
return true;
}
示例6: toolStripMenuItemImportTimeCodes_Click
private void toolStripMenuItemImportTimeCodes_Click(object sender, EventArgs e)
{
if (_subtitle.Paragraphs.Count < 1)
{
MessageBox.Show(_language.NoSubtitleLoaded, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
openFileDialog1.Title = _languageGeneral.OpenSubtitle;
openFileDialog1.FileName = string.Empty;
openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
Encoding encoding = null;
Subtitle timeCodeSubtitle = new Subtitle();
SubtitleFormat format = timeCodeSubtitle.LoadSubtitle(openFileDialog1.FileName, out encoding, encoding);
if (format == null)
{
ShowUnknownSubtitle();
return;
}
if (timeCodeSubtitle.Paragraphs.Count != _subtitle.Paragraphs.Count && !string.IsNullOrEmpty(_language.ImportTimeCodesDifferentNumberOfLinesWarning))
{
if (MessageBox.Show(string.Format(_language.ImportTimeCodesDifferentNumberOfLinesWarning, timeCodeSubtitle.Paragraphs.Count, _subtitle.Paragraphs.Count), _title, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
return;
}
MakeHistoryForUndo(_language.BeforeTimeCodeImport);
if (GetCurrentSubtitleFormat().IsFrameBased)
timeCodeSubtitle.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
else
timeCodeSubtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
int count = 0;
for (int i = 0; i < timeCodeSubtitle.Paragraphs.Count; i++)
{
Paragraph existing = _subtitle.GetParagraphOrDefault(i);
Paragraph newTimeCode = timeCodeSubtitle.GetParagraphOrDefault(i);
if (existing == null || newTimeCode == null)
break;
existing.StartTime.TotalMilliseconds = newTimeCode.StartTime.TotalMilliseconds;
existing.EndTime.TotalMilliseconds = newTimeCode.EndTime.TotalMilliseconds;
existing.StartFrame = newTimeCode.StartFrame;
existing.EndFrame = newTimeCode.EndFrame;
count++;
}
ShowStatus(string.Format(_language.TimeCodeImportedFromXY, Path.GetFileName(openFileDialog1.FileName), count));
SaveSubtitleListviewIndexes();
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
RestoreSubtitleListviewIndexes();
}
}
示例7: ImportTimeCodesInFramesOnSameSeperateLine
private Subtitle ImportTimeCodesInFramesOnSameSeperateLine(string[] lines)
{
Paragraph paragraph = null;
var subtitle = new Subtitle();
var sb = new StringBuilder();
foreach (string t in lines)
{
string line = t;
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)
{
if (!char.IsDigit(c))
{
allNumbers = false;
}
}
if (allNumbers && lineWithPerhapsOnlyNumbers.Length > 2)
{
string[] arr = line
.Replace("-", " ")
.Replace(">", " ")
.Replace("{", " ")
.Replace("}", " ")
.Replace("[", " ")
.Replace("]", " ")
.Trim()
.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length == 2)
{
string[] start = arr[0].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
string[] end = arr[0].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
if (start.Length == 1 && end.Length == 1)
{
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[0]);
paragraph.EndFrame = int.Parse(end[0]);
paragraph.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);
}
else
{
paragraph.StartTime.TotalMilliseconds = double.Parse(start[0]);
paragraph.EndTime.TotalMilliseconds = double.Parse(end[0]);
}
}
catch
{
paragraph = null;
}
}
}
else if (arr.Length == 3)
{
string[] start = arr[0].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
string[] end = arr[0].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
string[] duration = arr[0].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
if (end.Length == 1 && duration.Length == 1)
{
start = end;
end = duration;
}
if (start.Length == 1 && end.Length == 1)
{
if (paragraph != null)
{
paragraph.Text = sb.ToString().Trim();
subtitle.Paragraphs.Add(paragraph);
}
paragraph = new Paragraph();
sb = new StringBuilder();
try
//.........这里部分代码省略.........
示例8: ImportTimeCodesInFramesOnSameSeperateLine
private Subtitle ImportTimeCodesInFramesOnSameSeperateLine(string[] lines)
{
Paragraph p = 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)
{
if (!"0123456789".Contains(c.ToString()))
allNumbers = false;
}
if (allNumbers && lineWithPerhapsOnlyNumbers.Length > 2)
{
string[] arr = line.Replace("-", " ").Replace(">", " ").Replace("{", " ").Replace("}", " ").Replace("[", " ").Replace("]", " ").Trim().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (arr.Length == 2)
{
string[] start = arr[0].Trim().Split(".,;:".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string[] end = arr[0].Trim().Split(".,;:".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (start.Length == 1 && end.Length == 1)
{
if (p != null)
{
p.Text = sb.ToString().Trim();
subtitle.Paragraphs.Add(p);
}
p = new Paragraph();
sb = new StringBuilder();
try
{
if (UseFrames)
{
p.StartFrame = int.Parse(start[0]);
p.EndFrame = int.Parse(end[0]);
p.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);
}
else
{
p.StartTime.TotalMilliseconds = double.Parse(start[0]);
p.EndTime.TotalMilliseconds = double.Parse(end[0]);
}
}
catch
{
p = null;
}
}
}
else if (arr.Length == 3)
{
string[] start = arr[0].Trim().Split(".,;:".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string[] end = arr[0].Trim().Split(".,;:".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string[] duration = arr[0].Trim().Split(".,;:".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (end.Length == 1 && duration.Length == 1)
{
start = end;
end = duration;
}
if (start.Length == 1 && end.Length == 1)
{
if (p != null)
{
p.Text = sb.ToString().Trim();
subtitle.Paragraphs.Add(p);
}
p = new Paragraph();
sb = new StringBuilder();
try
{
if (UseFrames)
{
p.StartFrame = int.Parse(start[0]);
p.EndFrame = int.Parse(end[0]);
p.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);
}
else
{
p.StartTime.TotalMilliseconds = double.Parse(start[0]);
p.EndTime.TotalMilliseconds = double.Parse(end[0]);
}
}
catch
{
p = null;
}
}
}
}
if (p != null && !allNumbers && line.Length > 1)
{
line = line.Trim();
if (line.StartsWith("}{}") || line.StartsWith("][]"))
line = line.Remove(0, 3);
sb.AppendLine(line.Trim());
}
//.........这里部分代码省略.........
示例9: BatchConvertSave
internal static bool BatchConvertSave(string toFormat, string offset, Encoding targetEncoding, string outputFolder, int count, ref int converted, ref int errors, IList<SubtitleFormat> formats, string fileName, Subtitle sub, SubtitleFormat format, bool overwrite, string pacCodePage, double? targetFrameRate)
{
double oldFrameRate = Configuration.Settings.General.CurrentFrameRate;
try
{
// adjust offset
AdjustOffset(offset, sub);
// adjust frame rate
if (targetFrameRate.HasValue)
{
sub.ChangeFrameRate(Configuration.Settings.General.CurrentFrameRate, targetFrameRate.Value);
Configuration.Settings.General.CurrentFrameRate = targetFrameRate.Value;
}
bool targetFormatFound = false;
string outputFileName;
foreach (SubtitleFormat subtitleFormat in formats)
{
if (subtitleFormat.IsTextBased && (
subtitleFormat.Name.Replace(" ", string.Empty).Equals(toFormat, StringComparison.OrdinalIgnoreCase) ||
subtitleFormat.Name.Replace(" ", string.Empty).Equals(toFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase)))
{
targetFormatFound = true;
subtitleFormat.BatchMode = true;
outputFileName = FormatOutputFileNameForBatchConvert(fileName, subtitleFormat.Extension, outputFolder, overwrite);
Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
if (subtitleFormat.IsFrameBased && !sub.WasLoadedWithFrameNumbers)
{
sub.CalculateFrameNumbersFromTimeCodesNoCheck(Configuration.Settings.General.CurrentFrameRate);
}
else if (subtitleFormat.IsTimeBased && sub.WasLoadedWithFrameNumbers)
{
sub.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);
}
if ((subtitleFormat.GetType() == typeof(WebVTT) || subtitleFormat.GetType() == typeof(WebVTTFileWithLineNumber)))
{
targetEncoding = Encoding.UTF8;
}
if (subtitleFormat.GetType() == typeof(ItunesTimedText) || subtitleFormat.GetType() == typeof(ScenaristClosedCaptions) || subtitleFormat.GetType() == typeof(ScenaristClosedCaptionsDropFrame))
{
Encoding outputEnc = new UTF8Encoding(false);
using (var file = new StreamWriter(outputFileName, false, outputEnc))
{
file.Write(sub.ToText(subtitleFormat));
}
}
else if (targetEncoding == Encoding.UTF8 && (format.GetType() == typeof(TmpegEncAW5) || format.GetType() == typeof(TmpegEncXml)))
{
Encoding outputEnc = new UTF8Encoding(false);
using (var file = new StreamWriter(outputFileName, false, outputEnc))
{
file.Write(sub.ToText(subtitleFormat));
}
}
else
{
try
{
File.WriteAllText(outputFileName, sub.ToText(subtitleFormat), targetEncoding);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
errors++;
return false;
}
}
if (format.GetType() == typeof(Sami) || format.GetType() == typeof(SamiModern))
{
//var sami = (Sami)format;
foreach (string className in Sami.GetStylesFromHeader(sub.Header))
{
var newSub = new Subtitle();
foreach (Paragraph p in sub.Paragraphs)
{
if (p.Extra != null && p.Extra.Trim().Equals(className.Trim(), StringComparison.OrdinalIgnoreCase))
{
newSub.Paragraphs.Add(p);
}
}
if (newSub.Paragraphs.Count > 0 && newSub.Paragraphs.Count < sub.Paragraphs.Count)
{
string s = fileName;
if (s.LastIndexOf('.') > 0)
{
s = s.Insert(s.LastIndexOf('.'), "_" + className);
}
else
{
s += "_" + className + format.Extension;
}
outputFileName = FormatOutputFileNameForBatchConvert(s, subtitleFormat.Extension, outputFolder, overwrite);
//.........这里部分代码省略.........