本文整理汇总了C#中Subtitle.LoadSubtitle方法的典型用法代码示例。如果您正苦于以下问题:C# Subtitle.LoadSubtitle方法的具体用法?C# Subtitle.LoadSubtitle怎么用?C# Subtitle.LoadSubtitle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subtitle
的用法示例。
在下文中一共展示了Subtitle.LoadSubtitle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadAlternateSubtitleFile
private bool LoadAlternateSubtitleFile(string fileName)
{
if (!File.Exists(fileName))
return false;
var file = new FileInfo(fileName);
if (file.Extension.Equals(".sub", StringComparison.OrdinalIgnoreCase) && IsVobSubFile(fileName, false))
return false;
if (file.Length > 1024 * 1024 * 10) // max 10 mb
{
var text = string.Format(_language.FileXIsLargerThan10MB + Environment.NewLine + Environment.NewLine + _language.ContinueAnyway, fileName);
if (MessageBox.Show(this, text, Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
return false;
}
Encoding encoding;
_subtitleAlternate = new Subtitle();
_subtitleAlternateFileName = fileName;
SubtitleFormat format = _subtitleAlternate.LoadSubtitle(fileName, out encoding, null);
if (format == null)
{
var ebu = new Ebu();
if (ebu.IsMine(null, fileName))
{
ebu.LoadSubtitle(_subtitleAlternate, null, fileName);
format = ebu;
}
}
if (format == null)
{
var pac = new Pac();
if (pac.IsMine(null, fileName))
{
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))
{
//.........这里部分代码省略.........
示例2: 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
{
var text = string.Format(_language.FileXIsLargerThan10MB + Environment.NewLine + Environment.NewLine + _language.ContinueAnyway, openFileDialog1.FileName);
if (MessageBox.Show(this, text, Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
return;
}
MakeHistoryForUndo(string.Format(_language.BeforeInsertLine, openFileDialog1.FileName));
Encoding encoding;
var subtitle = new Subtitle();
SubtitleFormat format = subtitle.LoadSubtitle(openFileDialog1.FileName, out encoding, null);
if (format != null)
{
SaveSubtitleListviewIndices();
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 (var 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;
var current = _subtitle.GetParagraphOrDefault(index);
if (current != null)
{
var original = Utilities.GetOriginalParagraph(index, current, _subtitleAlternate.Paragraphs);
if (original != null)
{
index = _subtitleAlternate.GetIndex(original);
foreach (var p in subtitle.Paragraphs)
{
_subtitleAlternate.Paragraphs.Insert(index, new Paragraph(p));
index++;
}
if (subtitle.Paragraphs.Count > 0)
_subtitleAlternate.Renumber();
}
}
}
_subtitle.Renumber();
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
RestoreSubtitleListviewIndices();
}
}
}
示例3: pointSyncViaOtherSubtitleToolStripMenuItem_Click
//.........这里部分代码省略.........
var subtitleList = matroska.GetTracks(true);
if (subtitleList.Count > 1)
{
using (var 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], matroska);
}
}
}
else if (subtitleList.Count > 0)
{
sub = LoadMatroskaSubtitleForSync(subtitleList[0], matroska);
}
else
{
MessageBox.Show(_language.NoSubtitlesFound);
return;
}
}
}
}
if (extension == ".divx" || extension == ".avi")
{
MessageBox.Show(_language.NoSupportHereDivx);
return;
}
if ((extension == ".mp4" || extension == ".m4v" || extension == ".3gp") && file.Length > 10000)
{
var mp4Parser = new MP4Parser(fileName);
var mp4SubtitleTracks = mp4Parser.GetSubtitleTracks();
if (mp4SubtitleTracks.Count == 0)
{
MessageBox.Show(_language.NoSubtitlesFound);
return;
}
else if (mp4SubtitleTracks.Count == 1)
{
sub = LoadMp4SubtitleForSync(mp4SubtitleTracks[0]);
}
else
{
using (var subtitleChooser = new MatroskaSubtitleChooser())
{
subtitleChooser.Initialize(mp4SubtitleTracks);
if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
{
sub = LoadMp4SubtitleForSync(mp4SubtitleTracks[0]);
}
}
}
}
if (file.Length > 1024 * 1024 * 10 && sub.Paragraphs.Count == 0) // max 10 mb
{
var text = string.Format(_language.FileXIsLargerThan10MB + Environment.NewLine + Environment.NewLine + _language.ContinueAnyway, fileName);
if (MessageBox.Show(this, text, Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
return;
}
sub.Renumber();
if (sub.Paragraphs.Count == 0)
{
Encoding enc;
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 (var p in pointSync.FixedSubtitle.Paragraphs)
_subtitle.Paragraphs.Add(p);
_subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate);
ShowStatus(_language.PointSynchronizationDone);
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
}
_videoFileName = pointSync.VideoFileName;
}
}
}
示例4: toolStripMenuItemImportTimeCodes_Click
private void toolStripMenuItemImportTimeCodes_Click(object sender, EventArgs e)
{
if (_subtitle.Paragraphs.Count < 1)
{
DisplaySubtitleNotLoadedMessage();
return;
}
openFileDialog1.Title = _languageGeneral.OpenSubtitle;
openFileDialog1.FileName = string.Empty;
openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
Encoding encoding;
var timeCodeSubtitle = new Subtitle();
SubtitleFormat format = timeCodeSubtitle.LoadSubtitle(openFileDialog1.FileName, out encoding, null);
if (format == null)
{
ShowUnknownSubtitle();
return;
}
if (timeCodeSubtitle.Paragraphs.Count != _subtitle.Paragraphs.Count)
{
var text = string.Format(_language.ImportTimeCodesDifferentNumberOfLinesWarning, timeCodeSubtitle.Paragraphs.Count, _subtitle.Paragraphs.Count);
if (MessageBox.Show(this, text, _title, MessageBoxButtons.YesNo) == 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++)
{
var existing = _subtitle.GetParagraphOrDefault(i);
var 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));
SaveSubtitleListviewIndices();
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
RestoreSubtitleListviewIndices();
}
}
示例5: 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)
{
var ebu = new Ebu();
if (ebu.IsMine(null, fileName))
{
ebu.LoadSubtitle(sub, null, fileName);
format = ebu;
}
}
if (format == null)
{
var pac = new Pac();
if (pac.IsMine(null, fileName))
{
pac.LoadSubtitle(sub, null, fileName);
format = pac;
}
}
if (format == null)
{
var cavena890 = new Cavena890();
if (cavena890.IsMine(null, fileName))
{
cavena890.LoadSubtitle(sub, null, fileName);
format = cavena890;
}
}
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)
{
var 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());
}
//.........这里部分代码省略.........
示例6: buttonConvert_Click
private void buttonConvert_Click(object sender, EventArgs e)
{
if (listViewInputFiles.Items.Count == 0)
{
MessageBox.Show(Configuration.Settings.Language.BatchConvert.NothingToConvert);
return;
}
if (!checkBoxOverwriteOriginalFiles.Checked)
{
if (textBoxOutputFolder.Text.Length < 2)
{
MessageBox.Show(Configuration.Settings.Language.BatchConvert.PleaseChooseOutputFolder);
return;
}
if (!Directory.Exists(textBoxOutputFolder.Text))
{
try
{
Directory.CreateDirectory(textBoxOutputFolder.Text);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
return;
}
}
}
_converting = true;
buttonConvert.Enabled = false;
buttonCancel.Enabled = false;
progressBar1.Style = ProgressBarStyle.Blocks;
progressBar1.Maximum = listViewInputFiles.Items.Count;
progressBar1.Value = 0;
progressBar1.Visible = progressBar1.Maximum > 2;
string toFormat = comboBoxSubtitleFormats.Text;
groupBoxOutput.Enabled = false;
groupBoxConvertOptions.Enabled = false;
buttonInputBrowse.Enabled = false;
buttonSearchFolder.Enabled = false;
comboBoxFilter.Enabled = false;
textBoxFilter.Enabled = false;
_count = 0;
_converted = 0;
_errors = 0;
_abort = false;
var worker1 = new BackgroundWorker();
var worker2 = new BackgroundWorker();
var worker3 = new BackgroundWorker();
worker1.DoWork += DoThreadWork;
worker1.RunWorkerCompleted += ThreadWorkerCompleted;
worker2.DoWork += DoThreadWork;
worker2.RunWorkerCompleted += ThreadWorkerCompleted;
worker3.DoWork += DoThreadWork;
worker3.RunWorkerCompleted += ThreadWorkerCompleted;
listViewInputFiles.BeginUpdate();
foreach (ListViewItem item in listViewInputFiles.Items)
item.SubItems[3].Text = "-";
listViewInputFiles.EndUpdate();
Refresh();
int index = 0;
while (index < listViewInputFiles.Items.Count && _abort == false)
{
ListViewItem item = listViewInputFiles.Items[index];
string fileName = item.Text;
try
{
SubtitleFormat format = null;
var sub = new Subtitle();
var fi = new FileInfo(fileName);
if (fi.Length < 1024 * 1024) // max 1 mb
{
Encoding encoding;
format = sub.LoadSubtitle(fileName, out encoding, null);
if (format == null)
{
var ebu = new Ebu();
if (ebu.IsMine(null, fileName))
{
ebu.LoadSubtitle(sub, null, fileName);
format = ebu;
}
}
if (format == null)
{
var pac = new Pac();
if (pac.IsMine(null, fileName))
{
pac.BatchMode = true;
pac.LoadSubtitle(sub, null, fileName);
format = pac;
}
}
if (format == null)
{
var cavena890 = new Cavena890();
if (cavena890.IsMine(null, fileName))
{
cavena890.LoadSubtitle(sub, null, fileName);
format = cavena890;
}
//.........这里部分代码省略.........
示例7: buttonImport_Click
private void buttonImport_Click(object sender, EventArgs e)
{
openFileDialogImport.Title = Configuration.Settings.Language.SubStationAlphaStyles.ImportStyleFromFile;
openFileDialogImport.InitialDirectory = Configuration.DataDirectory;
if (_isSubStationAlpha)
{
openFileDialogImport.Filter = SubStationAlpha.NameOfFormat + "|*.ssa|" + Configuration.Settings.Language.General.AllFiles + "|*.*";
saveFileDialogStyle.FileName = "my_styles.ssa";
}
else
{
openFileDialogImport.Filter = AdvancedSubStationAlpha.NameOfFormat + "|*.ass|" + Configuration.Settings.Language.General.AllFiles + "|*.*";
saveFileDialogStyle.FileName = "my_styles.ass";
}
if (openFileDialogImport.ShowDialog(this) == DialogResult.OK)
{
Encoding encoding = null;
var s = new Subtitle();
var format = s.LoadSubtitle(openFileDialogImport.FileName, out encoding, null);
if (format != null && format.HasStyleSupport)
{
var styles = AdvancedSubStationAlpha.GetStylesFromHeader(s.Header);
if (styles.Count > 0)
{
var cs = new ChooseStyle(s, format.GetType() == typeof(SubStationAlpha));
if (cs.ShowDialog(this) == DialogResult.OK && cs.SelectedStyleName != null)
{
SsaStyle style = AdvancedSubStationAlpha.GetSsaStyle(cs.SelectedStyleName, s.Header);
if (GetSsaStyle(style.Name).LoadedFromHeader)
{
int count = 2;
bool doRepeat = GetSsaStyle(style.Name + count).LoadedFromHeader;
while (doRepeat)
{
doRepeat = GetSsaStyle(style.Name + count).LoadedFromHeader;
count++;
}
style.RawLine = style.RawLine.Replace(" " + style.Name + ",", " " + style.Name + count + ",");
style.Name = style.Name + count;
}
_doUpdate = false;
AddStyle(listViewStyles, style, Subtitle, _isSubStationAlpha);
SsaStyle oldStyle = GetSsaStyle(listViewStyles.Items[0].Text);
_header = _header.Trim();
if (_header.EndsWith("[Events]"))
{
_header = _header.Substring(0, _header.Length - "[Events]".Length).Trim();
_header += Environment.NewLine + style.RawLine;
_header += Environment.NewLine + Environment.NewLine + "[Events]" + Environment.NewLine;
}
else
{
_header = _header.Trim() + Environment.NewLine + style.RawLine + Environment.NewLine;
}
listViewStyles.Items[listViewStyles.Items.Count - 1].Selected = true;
listViewStyles.Items[listViewStyles.Items.Count - 1].EnsureVisible();
listViewStyles.Items[listViewStyles.Items.Count - 1].Focused = true;
textBoxStyleName.Text = style.Name;
textBoxStyleName.Focus();
_doUpdate = true;
SetControlsFromStyle(style);
listViewStyles_SelectedIndexChanged(null, null);
labelStatus.Text = string.Format(Configuration.Settings.Language.SubStationAlphaStyles.StyleXImportedFromFileY, style.Name, openFileDialogImport.FileName);
timerClearStatus.Start();
}
}
}
}
}
示例8: importNewTimeCodesToolStripMenuItem_Click
private void importNewTimeCodesToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.Title = Configuration.Settings.Language.General.OpenSubtitle;
openFileDialog1.FileName = string.Empty;
openFileDialog1.Filter = UiUtil.SubtitleExtensionFilter.Value;
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
string fileName = openFileDialog1.FileName;
if (!File.Exists(fileName))
return;
var fi = new FileInfo(fileName);
if (fi.Length > 1024 * 1024 * 10) // max 10 mb
{
if (MessageBox.Show(string.Format(Configuration.Settings.Language.Main.FileXIsLargerThan10MB + Environment.NewLine +
Environment.NewLine +
Configuration.Settings.Language.Main.ContinueAnyway,
fileName), Text, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
return;
}
Subtitle sub = new Subtitle();
Encoding encoding;
SubtitleFormat format = sub.LoadSubtitle(fileName, out encoding, null);
if (format == null)
return;
int index = 0;
foreach (Paragraph p in sub.Paragraphs)
{
if (index < _subtitle.Paragraphs.Count)
{
Paragraph currentP = _subtitle.Paragraphs[index];
currentP.StartTime.TotalMilliseconds = p.StartTime.TotalMilliseconds;
currentP.EndTime.TotalMilliseconds = p.EndTime.TotalMilliseconds;
subtitleListView1.SetStartTimeAndDuration(index, currentP);
}
index++;
}
}
}
示例9: VerifyDragDrop
private void VerifyDragDrop(ListView listView, DragEventArgs e)
{
var files = e.Data.GetData(DataFormats.FileDrop) as string[];
if (files == null)
{
return;
}
if (files.Length > 1)
{
MessageBox.Show(Configuration.Settings.Language.Main.DropOnlyOneFile,
string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
string filePath = files[0];
if (FileUtil.IsDirectory(filePath))
{
MessageBox.Show(Configuration.Settings.Language.Main.ErrorDirectoryDropNotAllowed,
string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var listExt = new List<string>();
foreach (var s in UiUtil.SubtitleExtensionFilter.Value.Split(new[] { '*' }, StringSplitOptions.RemoveEmptyEntries))
{
if (s.EndsWith(';'))
listExt.Add(s.Trim(';'));
}
if (!listExt.Contains(Path.GetExtension(filePath)))
return;
if (FileUtil.IsVobSub(filePath) || FileUtil.IsBluRaySup(filePath))
{
MessageBox.Show(Configuration.Settings.Language.CompareSubtitles.CannotCompareWithImageBasedSubtitles);
return;
}
Encoding encoding;
if (listView.Name == "subtitleListView1")
{
_subtitle1 = new Subtitle();
_subtitle1.LoadSubtitle(filePath, out encoding, null);
subtitleListView1.Fill(_subtitle1);
subtitleListView1.SelectIndexAndEnsureVisible(0);
subtitleListView2.SelectIndexAndEnsureVisible(0);
labelSubtitle1.Text = filePath;
_language1 = LanguageAutoDetect.AutoDetectGoogleLanguage(_subtitle1);
if (_subtitle1.Paragraphs.Count > 0)
CompareSubtitles();
}
else
{
_subtitle2 = new Subtitle();
_subtitle2.LoadSubtitle(filePath, out encoding, null);
subtitleListView2.Fill(_subtitle2);
subtitleListView1.SelectIndexAndEnsureVisible(0);
subtitleListView2.SelectIndexAndEnsureVisible(0);
labelSubtitle2.Text = filePath;
if (_subtitle2.Paragraphs.Count > 0)
CompareSubtitles();
}
}
示例10: buttonExport_Click
private void buttonExport_Click(object sender, EventArgs e)
{
if (listViewStyles.SelectedItems.Count != 1)
return;
string styleName = listViewStyles.SelectedItems[0].Text;
saveFileDialogStyle.Title = Configuration.Settings.Language.SubStationAlphaStyles.ExportStyleToFile;
saveFileDialogStyle.InitialDirectory = Configuration.DataDirectory;
if (_isSubStationAlpha)
{
saveFileDialogStyle.Filter = SubStationAlpha.NameOfFormat + "|*.ssa|" + Configuration.Settings.Language.General.AllFiles + "|*.*";
saveFileDialogStyle.FileName = "my_styles.ssa";
}
else
{
saveFileDialogStyle.Filter = AdvancedSubStationAlpha.NameOfFormat + "|*.ass|" + Configuration.Settings.Language.General.AllFiles + "|*.*";
saveFileDialogStyle.FileName = "my_styles.ass";
}
if (saveFileDialogStyle.ShowDialog(this) == DialogResult.OK)
{
if (File.Exists(saveFileDialogStyle.FileName))
{
Encoding encoding = null;
var s = new Subtitle();
var format = s.LoadSubtitle(saveFileDialogStyle.FileName, out encoding, null);
if (format == null)
{
MessageBox.Show("Not subtitle format: " + _format.Name);
return;
}
else if (format.Name != _format.Name)
{
MessageBox.Show(string.Format("Cannot save {1} style in {0} file!", format.Name, _format.Name));
return;
}
else
{
var sb = new StringBuilder();
bool stylesOn = false;
bool done = false;
string styleFormat = "Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding";
foreach (string line in File.ReadAllLines(saveFileDialogStyle.FileName))
{
if (line.StartsWith("format:", StringComparison.OrdinalIgnoreCase))
{
styleFormat = line;
}
else if (line.StartsWith("style:", StringComparison.OrdinalIgnoreCase))
{
stylesOn = true;
}
else if (stylesOn && !done)
{
done = true;
SsaStyle style = GetSsaStyle(styleName);
if (_isSubStationAlpha)
{
sb.AppendLine(style.ToRawSsa(styleFormat));
}
else
{
sb.AppendLine(style.ToRawAss(styleFormat));
}
}
sb.AppendLine(line);
if (stylesOn && line.Replace(" ", string.Empty).TrimStart().StartsWith("style:" + styleName.Replace(" ", string.Empty).Trim() + ",", StringComparison.OrdinalIgnoreCase))
{
MessageBox.Show(string.Format(Configuration.Settings.Language.SubStationAlphaStyles.StyleAlreadyExits, styleName));
return;
}
}
File.WriteAllText(saveFileDialogStyle.FileName, sb.ToString(), Encoding.UTF8);
}
}
else
{
var sb = new StringBuilder();
foreach (var line in _header.Replace(Environment.NewLine, "\n").Split('\n'))
{
if (line.StartsWith("style:", StringComparison.OrdinalIgnoreCase))
{
if (line.ToLower().Replace(" ", string.Empty).StartsWith("style:" + styleName.ToLower().Trim()))
sb.AppendLine(line);
}
else
{
sb.AppendLine(line);
}
}
string content = sb.ToString();
if (content.TrimEnd().EndsWith("[Events]"))
{
content = content.Trim() + Environment.NewLine +
"Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text" + Environment.NewLine +
"Dialogue: 0,0:00:31.91,0:00:33.91,Default,,0,0,0,,My Styles :)";
}
File.WriteAllText(saveFileDialogStyle.FileName, content, Encoding.UTF8);
}
//.........这里部分代码省略.........
示例11: ButtonOpenSubtitle2Click
private void ButtonOpenSubtitle2Click(object sender, EventArgs e)
{
openFileDialog1.FileName = string.Empty;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if (FileUtil.IsVobSub(openFileDialog1.FileName) || FileUtil.IsBluRaySup(openFileDialog1.FileName))
{
MessageBox.Show(Configuration.Settings.Language.CompareSubtitles.CannotCompareWithImageBasedSubtitles);
return;
}
_subtitle2 = new Subtitle();
Encoding encoding;
var format = _subtitle2.LoadSubtitle(openFileDialog1.FileName, out encoding, null);
if (format == null)
{
var pac = new Pac();
if (pac.IsMine(null, openFileDialog1.FileName))
{
pac.BatchMode = true;
pac.LoadSubtitle(_subtitle2, null, openFileDialog1.FileName);
format = pac;
}
}
if (format == null)
{
var cavena890 = new Cavena890();
if (cavena890.IsMine(null, openFileDialog1.FileName))
{
cavena890.LoadSubtitle(_subtitle2, null, openFileDialog1.FileName);
}
}
subtitleListView2.Fill(_subtitle2);
subtitleListView1.SelectIndexAndEnsureVisible(0);
subtitleListView2.SelectIndexAndEnsureVisible(0);
labelSubtitle2.Text = openFileDialog1.FileName;
if (_subtitle2.Paragraphs.Count > 0 && _subtitle1?.Paragraphs.Count > 0)
CompareSubtitles();
}
}
示例12: ButtonOpenSubtitle1Click
private void ButtonOpenSubtitle1Click(object sender, EventArgs e)
{
openFileDialog1.FileName = string.Empty;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if (FileUtil.IsVobSub(openFileDialog1.FileName) || FileUtil.IsBluRaySup(openFileDialog1.FileName))
{
MessageBox.Show(Configuration.Settings.Language.CompareSubtitles.CannotCompareWithImageBasedSubtitles);
return;
}
_subtitle1 = new Subtitle();
Encoding encoding;
var format = _subtitle1.LoadSubtitle(openFileDialog1.FileName, out encoding, null);
if (format == null)
{
var pac = new Pac();
if (pac.IsMine(null, openFileDialog1.FileName))
{
pac.BatchMode = true;
pac.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName);
format = pac;
}
}
if (format == null)
{
var cavena890 = new Cavena890();
if (cavena890.IsMine(null, openFileDialog1.FileName))
{
cavena890.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName);
}
}
if (format == null)
{
var spt = new Spt();
if (spt.IsMine(null, openFileDialog1.FileName))
{
spt.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName);
}
}
if (format == null)
{
var cheetahCaption = new CheetahCaption();
if (cheetahCaption.IsMine(null, openFileDialog1.FileName))
{
cheetahCaption.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName);
}
}
if (format == null)
{
var chk = new Chk();
if (chk.IsMine(null, openFileDialog1.FileName))
{
chk.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName);
}
}
if (format == null)
{
var asc = new TimeLineAscii();
if (asc.IsMine(null, openFileDialog1.FileName))
{
asc.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName);
}
}
if (format == null)
{
var asc = new TimeLineFootageAscii();
if (asc.IsMine(null, openFileDialog1.FileName))
{
asc.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName);
}
}
subtitleListView1.Fill(_subtitle1);
subtitleListView1.SelectIndexAndEnsureVisible(0);
subtitleListView2.SelectIndexAndEnsureVisible(0);
labelSubtitle1.Text = openFileDialog1.FileName;
_language1 = LanguageAutoDetect.AutoDetectGoogleLanguage(_subtitle1);
if (_subtitle1.Paragraphs.Count > 0 && _subtitle2?.Paragraphs.Count > 0)
CompareSubtitles();
}
}
示例13: Convert
//.........这里部分代码省略.........
format.RemoveNativeFormatting(sub, sf);
break;
}
}
}
}
BatchConvertSave(toFormat, offset, targetEncoding, outputFolder, count, ref converted, ref errors, formats, newFileName, sub, format, overwrite, pacCodePage, targetFrameRate);
done = true;
}
}
}
}
}
}
if (FileUtil.IsBluRaySup(fileName))
{
Console.WriteLine("Found Blu-Ray subtitle format");
ConvertBluRaySubtitle(fileName, toFormat, offset, targetEncoding, outputFolder, count, ref converted, ref errors, formats, overwrite, pacCodePage, targetFrameRate);
done = true;
}
if (!done && FileUtil.IsVobSub(fileName))
{
Console.WriteLine("Found VobSub subtitle format");
ConvertVobSubSubtitle(fileName, toFormat, offset, targetEncoding, outputFolder, count, ref converted, ref errors, formats, overwrite, pacCodePage, targetFrameRate);
done = true;
}
var fi = new FileInfo(fileName);
if (fi.Length < 10 * 1024 * 1024 && !done) // max 10 mb
{
Encoding encoding;
format = sub.LoadSubtitle(fileName, out encoding, null, true);
if (format == null || format.GetType() == typeof(Ebu))
{
var ebu = new Ebu();
if (ebu.IsMine(null, fileName))
{
ebu.LoadSubtitle(sub, null, fileName);
format = ebu;
}
}
if (format == null)
{
var pac = new Pac();
if (pac.IsMine(null, fileName))
{
pac.BatchMode = true;
if (!string.IsNullOrEmpty(pacCodePage) && Utilities.IsInteger(pacCodePage))
pac.CodePage = int.Parse(pacCodePage);
else
pac.CodePage = -1;
pac.LoadSubtitle(sub, null, fileName);
format = pac;
}
}
if (format == null)
{
var cavena890 = new Cavena890();
if (cavena890.IsMine(null, fileName))
{
cavena890.LoadSubtitle(sub, null, fileName);
示例14: 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
{
var text = string.Format(_language.FileXIsLargerThan10MB + Environment.NewLine + Environment.NewLine + _language.ContinueAnyway, openFileDialog1.FileName);
if (MessageBox.Show(this, text, Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
return;
}
Encoding encoding;
var tmp = new Subtitle();
SubtitleFormat format = tmp.LoadSubtitle(openFileDialog1.FileName, out encoding, null);
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();
}
}
}
示例15: SearchFolder
private void SearchFolder(string path)
{
foreach (string fileName in Directory.GetFiles(path))
{
try
{
string ext = Path.GetExtension(fileName).ToLowerInvariant();
if (ext != ".png" && ext != ".jpg" && ext != ".dll" && ext != ".exe" && ext != ".zip")
{
var fi = new FileInfo(fileName);
if (ext == ".sub" && FileUtil.IsVobSub(fileName))
{
AddFromSearch(fileName, fi, "VobSub");
}
else if (ext == ".sup" && FileUtil.IsBluRaySup(fileName))
{
AddFromSearch(fileName, fi, "Blu-ray");
}
else
{
if (fi.Length < 1024 * 1024) // max 1 mb
{
Encoding encoding;
var sub = new Subtitle();
var format = sub.LoadSubtitle(fileName, out encoding, null);
if (format == null)
{
var ebu = new Ebu();
if (ebu.IsMine(null, fileName))
format = ebu;
}
if (format == null)
{
var pac = new Pac();
if (pac.IsMine(null, fileName))
format = pac;
}
if (format == null)
{
var cavena890 = new Cavena890();
if (cavena890.IsMine(null, fileName))
format = cavena890;
}
if (format == null)
{
var spt = new Spt();
if (spt.IsMine(null, fileName))
format = spt;
}
if (format == null)
{
var cheetahCaption = new CheetahCaption();
if (cheetahCaption.IsMine(null, fileName))
format = cheetahCaption;
}
if (format == null)
{
var capMakerPlus = new CapMakerPlus();
if (capMakerPlus.IsMine(null, fileName))
format = capMakerPlus;
}
if (format == null)
{
var captionate = new Captionate();
if (captionate.IsMine(null, fileName))
format = captionate;
}
if (format == null)
{
var ultech130 = new Ultech130();
if (ultech130.IsMine(null, fileName))
format = ultech130;
}
if (format == null)
{
var nciCaption = new NciCaption();
if (nciCaption.IsMine(null, fileName))
format = nciCaption;
}
if (format == null)
{
var avidStl = new AvidStl();
if (avidStl.IsMine(null, fileName))
format = avidStl;
}
if (format != null)
{
AddFromSearch(fileName, fi, format.Name);
}
}
}
progressBar1.Refresh();
Application.DoEvents();
if (_abort)
return;
}
}
catch
{
//.........这里部分代码省略.........