Batch convert - can now scan a folder incl. subfolders for subtitles + can overwriter original files

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1723 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2013-03-12 18:01:10 +00:00
parent 6ca754a8cc
commit 8f4b7ead24
2 changed files with 213 additions and 38 deletions

View File

@ -32,6 +32,7 @@
this.buttonConvert = new System.Windows.Forms.Button(); this.buttonConvert = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxConvertOptions = new System.Windows.Forms.GroupBox(); this.groupBoxConvertOptions = new System.Windows.Forms.GroupBox();
this.checkBoxAutoBalance = new System.Windows.Forms.CheckBox();
this.buttonMultipleReplaceSettings = new System.Windows.Forms.Button(); this.buttonMultipleReplaceSettings = new System.Windows.Forms.Button();
this.checkBoxMultipleReplace = new System.Windows.Forms.CheckBox(); this.checkBoxMultipleReplace = new System.Windows.Forms.CheckBox();
this.checkBoxFixCommonErrors = new System.Windows.Forms.CheckBox(); this.checkBoxFixCommonErrors = new System.Windows.Forms.CheckBox();
@ -50,6 +51,7 @@
this.checkBoxRemoveTextForHI = new System.Windows.Forms.CheckBox(); this.checkBoxRemoveTextForHI = new System.Windows.Forms.CheckBox();
this.checkBoxRemoveFormatting = new System.Windows.Forms.CheckBox(); this.checkBoxRemoveFormatting = new System.Windows.Forms.CheckBox();
this.groupBoxOutput = new System.Windows.Forms.GroupBox(); this.groupBoxOutput = new System.Windows.Forms.GroupBox();
this.checkBoxOverwriteOriginalFiles = new System.Windows.Forms.CheckBox();
this.linkLabelOpenOutputFolder = new System.Windows.Forms.LinkLabel(); this.linkLabelOpenOutputFolder = new System.Windows.Forms.LinkLabel();
this.buttonStyles = new System.Windows.Forms.Button(); this.buttonStyles = new System.Windows.Forms.Button();
this.checkBoxOverwrite = new System.Windows.Forms.CheckBox(); this.checkBoxOverwrite = new System.Windows.Forms.CheckBox();
@ -61,6 +63,7 @@
this.buttonChooseFolder = new System.Windows.Forms.Button(); this.buttonChooseFolder = new System.Windows.Forms.Button();
this.textBoxOutputFolder = new System.Windows.Forms.TextBox(); this.textBoxOutputFolder = new System.Windows.Forms.TextBox();
this.groupBoxInput = new System.Windows.Forms.GroupBox(); this.groupBoxInput = new System.Windows.Forms.GroupBox();
this.buttonSearchFolder = new System.Windows.Forms.Button();
this.buttonInputBrowse = new System.Windows.Forms.Button(); this.buttonInputBrowse = new System.Windows.Forms.Button();
this.labelChooseInputFiles = new System.Windows.Forms.Label(); this.labelChooseInputFiles = new System.Windows.Forms.Label();
this.listViewInputFiles = new System.Windows.Forms.ListView(); this.listViewInputFiles = new System.Windows.Forms.ListView();
@ -75,7 +78,7 @@
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.labelStatus = new System.Windows.Forms.Label(); this.labelStatus = new System.Windows.Forms.Label();
this.checkBoxAutoBalance = new System.Windows.Forms.CheckBox(); this.checkBoxSetMinimumDisplayTimeBetweenSubs = new System.Windows.Forms.CheckBox();
this.groupBoxConvertOptions.SuspendLayout(); this.groupBoxConvertOptions.SuspendLayout();
this.groupBoxChangeFrameRate.SuspendLayout(); this.groupBoxChangeFrameRate.SuspendLayout();
this.groupBoxOffsetTimeCodes.SuspendLayout(); this.groupBoxOffsetTimeCodes.SuspendLayout();
@ -112,6 +115,7 @@
// //
this.groupBoxConvertOptions.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.groupBoxConvertOptions.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxConvertOptions.Controls.Add(this.checkBoxSetMinimumDisplayTimeBetweenSubs);
this.groupBoxConvertOptions.Controls.Add(this.checkBoxAutoBalance); this.groupBoxConvertOptions.Controls.Add(this.checkBoxAutoBalance);
this.groupBoxConvertOptions.Controls.Add(this.buttonMultipleReplaceSettings); this.groupBoxConvertOptions.Controls.Add(this.buttonMultipleReplaceSettings);
this.groupBoxConvertOptions.Controls.Add(this.checkBoxMultipleReplace); this.groupBoxConvertOptions.Controls.Add(this.checkBoxMultipleReplace);
@ -129,6 +133,16 @@
this.groupBoxConvertOptions.TabStop = false; this.groupBoxConvertOptions.TabStop = false;
this.groupBoxConvertOptions.Text = "Convert options"; this.groupBoxConvertOptions.Text = "Convert options";
// //
// checkBoxAutoBalance
//
this.checkBoxAutoBalance.AutoSize = true;
this.checkBoxAutoBalance.Location = new System.Drawing.Point(16, 145);
this.checkBoxAutoBalance.Name = "checkBoxAutoBalance";
this.checkBoxAutoBalance.Size = new System.Drawing.Size(113, 17);
this.checkBoxAutoBalance.TabIndex = 9;
this.checkBoxAutoBalance.Text = "Auto balance lines";
this.checkBoxAutoBalance.UseVisualStyleBackColor = true;
//
// buttonMultipleReplaceSettings // buttonMultipleReplaceSettings
// //
this.buttonMultipleReplaceSettings.ImeMode = System.Windows.Forms.ImeMode.NoControl; this.buttonMultipleReplaceSettings.ImeMode = System.Windows.Forms.ImeMode.NoControl;
@ -306,6 +320,7 @@
// //
this.groupBoxOutput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) this.groupBoxOutput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxOutput.Controls.Add(this.checkBoxOverwriteOriginalFiles);
this.groupBoxOutput.Controls.Add(this.linkLabelOpenOutputFolder); this.groupBoxOutput.Controls.Add(this.linkLabelOpenOutputFolder);
this.groupBoxOutput.Controls.Add(this.buttonStyles); this.groupBoxOutput.Controls.Add(this.buttonStyles);
this.groupBoxOutput.Controls.Add(this.checkBoxOverwrite); this.groupBoxOutput.Controls.Add(this.checkBoxOverwrite);
@ -324,10 +339,21 @@
this.groupBoxOutput.TabStop = false; this.groupBoxOutput.TabStop = false;
this.groupBoxOutput.Text = "Output"; this.groupBoxOutput.Text = "Output";
// //
// checkBoxOverwriteOriginalFiles
//
this.checkBoxOverwriteOriginalFiles.AutoSize = true;
this.checkBoxOverwriteOriginalFiles.Location = new System.Drawing.Point(9, 19);
this.checkBoxOverwriteOriginalFiles.Name = "checkBoxOverwriteOriginalFiles";
this.checkBoxOverwriteOriginalFiles.Size = new System.Drawing.Size(300, 17);
this.checkBoxOverwriteOriginalFiles.TabIndex = 11;
this.checkBoxOverwriteOriginalFiles.Text = "Overwrite original files (new extension if format is changed)";
this.checkBoxOverwriteOriginalFiles.UseVisualStyleBackColor = true;
this.checkBoxOverwriteOriginalFiles.CheckedChanged += new System.EventHandler(this.checkBoxOverwriteOriginalFiles_CheckedChanged);
//
// linkLabelOpenOutputFolder // linkLabelOpenOutputFolder
// //
this.linkLabelOpenOutputFolder.AutoSize = true; this.linkLabelOpenOutputFolder.AutoSize = true;
this.linkLabelOpenOutputFolder.Location = new System.Drawing.Point(434, 44); this.linkLabelOpenOutputFolder.Location = new System.Drawing.Point(434, 74);
this.linkLabelOpenOutputFolder.Name = "linkLabelOpenOutputFolder"; this.linkLabelOpenOutputFolder.Name = "linkLabelOpenOutputFolder";
this.linkLabelOpenOutputFolder.Size = new System.Drawing.Size(42, 13); this.linkLabelOpenOutputFolder.Size = new System.Drawing.Size(42, 13);
this.linkLabelOpenOutputFolder.TabIndex = 3; this.linkLabelOpenOutputFolder.TabIndex = 3;
@ -337,7 +363,7 @@
// //
// buttonStyles // buttonStyles
// //
this.buttonStyles.Location = new System.Drawing.Point(311, 100); this.buttonStyles.Location = new System.Drawing.Point(311, 141);
this.buttonStyles.Name = "buttonStyles"; this.buttonStyles.Name = "buttonStyles";
this.buttonStyles.Size = new System.Drawing.Size(116, 23); this.buttonStyles.Size = new System.Drawing.Size(116, 23);
this.buttonStyles.TabIndex = 7; this.buttonStyles.TabIndex = 7;
@ -349,7 +375,7 @@
// checkBoxOverwrite // checkBoxOverwrite
// //
this.checkBoxOverwrite.AutoSize = true; this.checkBoxOverwrite.AutoSize = true;
this.checkBoxOverwrite.Location = new System.Drawing.Point(13, 67); this.checkBoxOverwrite.Location = new System.Drawing.Point(13, 97);
this.checkBoxOverwrite.Name = "checkBoxOverwrite"; this.checkBoxOverwrite.Name = "checkBoxOverwrite";
this.checkBoxOverwrite.Size = new System.Drawing.Size(130, 17); this.checkBoxOverwrite.Size = new System.Drawing.Size(130, 17);
this.checkBoxOverwrite.TabIndex = 4; this.checkBoxOverwrite.TabIndex = 4;
@ -360,7 +386,7 @@
// //
this.comboBoxSubtitleFormats.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSubtitleFormats.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSubtitleFormats.FormattingEnabled = true; this.comboBoxSubtitleFormats.FormattingEnabled = true;
this.comboBoxSubtitleFormats.Location = new System.Drawing.Point(80, 102); this.comboBoxSubtitleFormats.Location = new System.Drawing.Point(80, 143);
this.comboBoxSubtitleFormats.Name = "comboBoxSubtitleFormats"; this.comboBoxSubtitleFormats.Name = "comboBoxSubtitleFormats";
this.comboBoxSubtitleFormats.Size = new System.Drawing.Size(225, 21); this.comboBoxSubtitleFormats.Size = new System.Drawing.Size(225, 21);
this.comboBoxSubtitleFormats.TabIndex = 6; this.comboBoxSubtitleFormats.TabIndex = 6;
@ -369,7 +395,7 @@
// labelEncoding // labelEncoding
// //
this.labelEncoding.AutoSize = true; this.labelEncoding.AutoSize = true;
this.labelEncoding.Location = new System.Drawing.Point(10, 137); this.labelEncoding.Location = new System.Drawing.Point(10, 178);
this.labelEncoding.Name = "labelEncoding"; this.labelEncoding.Name = "labelEncoding";
this.labelEncoding.Size = new System.Drawing.Size(52, 13); this.labelEncoding.Size = new System.Drawing.Size(52, 13);
this.labelEncoding.TabIndex = 8; this.labelEncoding.TabIndex = 8;
@ -379,7 +405,7 @@
// //
this.comboBoxEncoding.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxEncoding.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxEncoding.FormattingEnabled = true; this.comboBoxEncoding.FormattingEnabled = true;
this.comboBoxEncoding.Location = new System.Drawing.Point(80, 134); this.comboBoxEncoding.Location = new System.Drawing.Point(80, 175);
this.comboBoxEncoding.Name = "comboBoxEncoding"; this.comboBoxEncoding.Name = "comboBoxEncoding";
this.comboBoxEncoding.Size = new System.Drawing.Size(225, 21); this.comboBoxEncoding.Size = new System.Drawing.Size(225, 21);
this.comboBoxEncoding.TabIndex = 9; this.comboBoxEncoding.TabIndex = 9;
@ -387,7 +413,7 @@
// labelOutputFormat // labelOutputFormat
// //
this.labelOutputFormat.AutoSize = true; this.labelOutputFormat.AutoSize = true;
this.labelOutputFormat.Location = new System.Drawing.Point(10, 105); this.labelOutputFormat.Location = new System.Drawing.Point(10, 146);
this.labelOutputFormat.Name = "labelOutputFormat"; this.labelOutputFormat.Name = "labelOutputFormat";
this.labelOutputFormat.Size = new System.Drawing.Size(39, 13); this.labelOutputFormat.Size = new System.Drawing.Size(39, 13);
this.labelOutputFormat.TabIndex = 5; this.labelOutputFormat.TabIndex = 5;
@ -396,7 +422,7 @@
// labelChooseOutputFolder // labelChooseOutputFolder
// //
this.labelChooseOutputFolder.AutoSize = true; this.labelChooseOutputFolder.AutoSize = true;
this.labelChooseOutputFolder.Location = new System.Drawing.Point(10, 25); this.labelChooseOutputFolder.Location = new System.Drawing.Point(10, 55);
this.labelChooseOutputFolder.Name = "labelChooseOutputFolder"; this.labelChooseOutputFolder.Name = "labelChooseOutputFolder";
this.labelChooseOutputFolder.Size = new System.Drawing.Size(105, 13); this.labelChooseOutputFolder.Size = new System.Drawing.Size(105, 13);
this.labelChooseOutputFolder.TabIndex = 0; this.labelChooseOutputFolder.TabIndex = 0;
@ -404,7 +430,7 @@
// //
// buttonChooseFolder // buttonChooseFolder
// //
this.buttonChooseFolder.Location = new System.Drawing.Point(402, 39); this.buttonChooseFolder.Location = new System.Drawing.Point(402, 69);
this.buttonChooseFolder.Name = "buttonChooseFolder"; this.buttonChooseFolder.Name = "buttonChooseFolder";
this.buttonChooseFolder.Size = new System.Drawing.Size(26, 23); this.buttonChooseFolder.Size = new System.Drawing.Size(26, 23);
this.buttonChooseFolder.TabIndex = 2; this.buttonChooseFolder.TabIndex = 2;
@ -414,7 +440,7 @@
// //
// textBoxOutputFolder // textBoxOutputFolder
// //
this.textBoxOutputFolder.Location = new System.Drawing.Point(11, 41); this.textBoxOutputFolder.Location = new System.Drawing.Point(11, 71);
this.textBoxOutputFolder.Name = "textBoxOutputFolder"; this.textBoxOutputFolder.Name = "textBoxOutputFolder";
this.textBoxOutputFolder.Size = new System.Drawing.Size(385, 20); this.textBoxOutputFolder.Size = new System.Drawing.Size(385, 20);
this.textBoxOutputFolder.TabIndex = 1; this.textBoxOutputFolder.TabIndex = 1;
@ -424,6 +450,7 @@
this.groupBoxInput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.groupBoxInput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxInput.Controls.Add(this.buttonSearchFolder);
this.groupBoxInput.Controls.Add(this.buttonInputBrowse); this.groupBoxInput.Controls.Add(this.buttonInputBrowse);
this.groupBoxInput.Controls.Add(this.labelChooseInputFiles); this.groupBoxInput.Controls.Add(this.labelChooseInputFiles);
this.groupBoxInput.Controls.Add(this.listViewInputFiles); this.groupBoxInput.Controls.Add(this.listViewInputFiles);
@ -434,6 +461,17 @@
this.groupBoxInput.TabStop = false; this.groupBoxInput.TabStop = false;
this.groupBoxInput.Text = "Input"; this.groupBoxInput.Text = "Input";
// //
// buttonSearchFolder
//
this.buttonSearchFolder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonSearchFolder.Location = new System.Drawing.Point(868, 12);
this.buttonSearchFolder.Name = "buttonSearchFolder";
this.buttonSearchFolder.Size = new System.Drawing.Size(116, 23);
this.buttonSearchFolder.TabIndex = 8;
this.buttonSearchFolder.Text = "Search folder...";
this.buttonSearchFolder.UseVisualStyleBackColor = true;
this.buttonSearchFolder.Click += new System.EventHandler(this.buttonSearchFolder_Click);
//
// buttonInputBrowse // buttonInputBrowse
// //
this.buttonInputBrowse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonInputBrowse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
@ -544,15 +582,15 @@
this.labelStatus.TabIndex = 9; this.labelStatus.TabIndex = 9;
this.labelStatus.Text = "labelStatus"; this.labelStatus.Text = "labelStatus";
// //
// checkBoxAutoBalance // checkBoxSetMinimumDisplayTimeBetweenSubs
// //
this.checkBoxAutoBalance.AutoSize = true; this.checkBoxSetMinimumDisplayTimeBetweenSubs.AutoSize = true;
this.checkBoxAutoBalance.Location = new System.Drawing.Point(16, 145); this.checkBoxSetMinimumDisplayTimeBetweenSubs.Location = new System.Drawing.Point(16, 169);
this.checkBoxAutoBalance.Name = "checkBoxAutoBalance"; this.checkBoxSetMinimumDisplayTimeBetweenSubs.Name = "checkBoxSetMinimumDisplayTimeBetweenSubs";
this.checkBoxAutoBalance.Size = new System.Drawing.Size(113, 17); this.checkBoxSetMinimumDisplayTimeBetweenSubs.Size = new System.Drawing.Size(190, 17);
this.checkBoxAutoBalance.TabIndex = 9; this.checkBoxSetMinimumDisplayTimeBetweenSubs.TabIndex = 10;
this.checkBoxAutoBalance.Text = "Auto balance lines"; this.checkBoxSetMinimumDisplayTimeBetweenSubs.Text = "Set min. millisecs between subtitles";
this.checkBoxAutoBalance.UseVisualStyleBackColor = true; this.checkBoxSetMinimumDisplayTimeBetweenSubs.UseVisualStyleBackColor = true;
// //
// BatchConvert // BatchConvert
// //
@ -572,6 +610,7 @@
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Batch convert"; this.Text = "Batch convert";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.BatchConvert_FormClosing); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.BatchConvert_FormClosing);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.BatchConvert_KeyDown);
this.groupBoxConvertOptions.ResumeLayout(false); this.groupBoxConvertOptions.ResumeLayout(false);
this.groupBoxConvertOptions.PerformLayout(); this.groupBoxConvertOptions.PerformLayout();
this.groupBoxChangeFrameRate.ResumeLayout(false); this.groupBoxChangeFrameRate.ResumeLayout(false);
@ -637,6 +676,9 @@
private System.Windows.Forms.Button buttonMultipleReplaceSettings; private System.Windows.Forms.Button buttonMultipleReplaceSettings;
private System.Windows.Forms.CheckBox checkBoxMultipleReplace; private System.Windows.Forms.CheckBox checkBoxMultipleReplace;
private System.Windows.Forms.CheckBox checkBoxAutoBalance; private System.Windows.Forms.CheckBox checkBoxAutoBalance;
private System.Windows.Forms.CheckBox checkBoxOverwriteOriginalFiles;
private System.Windows.Forms.Button buttonSearchFolder;
private System.Windows.Forms.CheckBox checkBoxSetMinimumDisplayTimeBetweenSubs;
} }
} }

View File

@ -18,6 +18,7 @@ namespace Nikse.SubtitleEdit.Forms
public bool FixCommonErrors { get; set; } public bool FixCommonErrors { get; set; }
public bool MultipleReplaceActive { get; set; } public bool MultipleReplaceActive { get; set; }
public bool AutoBalanceActive { get; set; } public bool AutoBalanceActive { get; set; }
public bool SetMinDisplayTimeBetweenSubtitles { get; set; }
public ListViewItem Item { get; set; } public ListViewItem Item { get; set; }
public Subtitle Subtitle { get; set; } public Subtitle Subtitle { get; set; }
public SubtitleFormat Format { get; set; } public SubtitleFormat Format { get; set; }
@ -28,11 +29,12 @@ namespace Nikse.SubtitleEdit.Forms
public string ToFormat { get; set; } public string ToFormat { get; set; }
public SubtitleFormat SourceFormat { get; set; } public SubtitleFormat SourceFormat { get; set; }
public ThreadDoWorkParameter(bool fixCommonErrors, bool multipleReplace, bool autoBalance, ListViewItem item, Subtitle subtitle, SubtitleFormat format, Encoding encoding, string language, string fileName, string toFormat, SubtitleFormat sourceFormat) public ThreadDoWorkParameter(bool fixCommonErrors, bool multipleReplace, bool autoBalance, bool setMinDisplayTimeBetweenSubtitles, ListViewItem item, Subtitle subtitle, SubtitleFormat format, Encoding encoding, string language, string fileName, string toFormat, SubtitleFormat sourceFormat)
{ {
FixCommonErrors = fixCommonErrors; FixCommonErrors = fixCommonErrors;
MultipleReplaceActive = multipleReplace; MultipleReplaceActive = multipleReplace;
AutoBalanceActive = autoBalance; AutoBalanceActive = autoBalance;
SetMinDisplayTimeBetweenSubtitles = setMinDisplayTimeBetweenSubtitles;
Item = item; Item = item;
Subtitle = subtitle; Subtitle = subtitle;
Format = format; Format = format;
@ -77,11 +79,13 @@ namespace Nikse.SubtitleEdit.Forms
checkBoxRemoveFormatting.Text = l.RemoveFormatting; checkBoxRemoveFormatting.Text = l.RemoveFormatting;
checkBoxFixCasing.Text = l.ReDoCasing; checkBoxFixCasing.Text = l.ReDoCasing;
checkBoxRemoveTextForHI.Text = l.RemoveTextForHI; checkBoxRemoveTextForHI.Text = l.RemoveTextForHI;
checkBoxOverwriteOriginalFiles.Text = l.OverwriteOriginalFiles;
columnHeaderFName.Text = Configuration.Settings.Language.JoinSubtitles.FileName; columnHeaderFName.Text = Configuration.Settings.Language.JoinSubtitles.FileName;
columnHeaderFormat.Text = Configuration.Settings.Language.Main.Controls.SubtitleFormat; columnHeaderFormat.Text = Configuration.Settings.Language.Main.Controls.SubtitleFormat;
columnHeaderSize.Text = Configuration.Settings.Language.General.Size; columnHeaderSize.Text = Configuration.Settings.Language.General.Size;
columnHeaderStatus.Text = l.Status; columnHeaderStatus.Text = l.Status;
linkLabelOpenOutputFolder.Text = Configuration.Settings.Language.Main.Menu.File.Open; linkLabelOpenOutputFolder.Text = Configuration.Settings.Language.Main.Menu.File.Open;
buttonSearchFolder.Text = l.ScanFolder;
buttonConvert.Text = l.Convert; buttonConvert.Text = l.Convert;
buttonCancel.Text = Configuration.Settings.Language.General.OK; buttonCancel.Text = Configuration.Settings.Language.General.OK;
@ -151,6 +155,7 @@ namespace Nikse.SubtitleEdit.Forms
checkBoxAutoBalance.Checked = Configuration.Settings.Tools.BatchConvertAutoBalance; checkBoxAutoBalance.Checked = Configuration.Settings.Tools.BatchConvertAutoBalance;
checkBoxRemoveFormatting.Checked = Configuration.Settings.Tools.BatchConvertRemoveFormatting; checkBoxRemoveFormatting.Checked = Configuration.Settings.Tools.BatchConvertRemoveFormatting;
checkBoxRemoveTextForHI.Checked = Configuration.Settings.Tools.BatchConvertRemoveTextForHI; checkBoxRemoveTextForHI.Checked = Configuration.Settings.Tools.BatchConvertRemoveTextForHI;
checkBoxSetMinimumDisplayTimeBetweenSubs.Checked = Configuration.Settings.Tools.BatchConvertSetMinDisplayTimeBetweenSubtitles;
if (!string.IsNullOrEmpty(Configuration.Settings.Language.BatchConvert.Settings)) if (!string.IsNullOrEmpty(Configuration.Settings.Language.BatchConvert.Settings))
buttonFixCommonErrorSettings.Text = Configuration.Settings.Language.BatchConvert.Settings; buttonFixCommonErrorSettings.Text = Configuration.Settings.Language.BatchConvert.Settings;
checkBoxFixCommonErrors.Text = Configuration.Settings.Language.FixCommonErrors.Title; checkBoxFixCommonErrors.Text = Configuration.Settings.Language.FixCommonErrors.Title;
@ -158,6 +163,13 @@ namespace Nikse.SubtitleEdit.Forms
checkBoxAutoBalance.Text = Configuration.Settings.Language.BatchConvert.AutoBalance; checkBoxAutoBalance.Text = Configuration.Settings.Language.BatchConvert.AutoBalance;
radioButtonShowEarlier.Text = Configuration.Settings.Language.ShowEarlierLater.ShowEarlier; radioButtonShowEarlier.Text = Configuration.Settings.Language.ShowEarlierLater.ShowEarlier;
radioButtonShowLater.Text = Configuration.Settings.Language.ShowEarlierLater.ShowLater; radioButtonShowLater.Text = Configuration.Settings.Language.ShowEarlierLater.ShowLater;
buttonSearchFolder.Visible = !string.IsNullOrEmpty(Configuration.Settings.Language.BatchConvert.ScanningFolder); //TODO: Remove in 3.4
if (string.IsNullOrEmpty(Configuration.Settings.Language.BatchConvert.OverwriteOriginalFiles)) //TODO: Remove in 3.4
{
checkBoxOverwriteOriginalFiles.Checked = false;
checkBoxOverwriteOriginalFiles.Visible = false;
}
} }
private void FixLargeFonts() private void FixLargeFonts()
@ -173,6 +185,7 @@ namespace Nikse.SubtitleEdit.Forms
private void buttonChooseFolder_Click(object sender, EventArgs e) private void buttonChooseFolder_Click(object sender, EventArgs e)
{ {
folderBrowserDialog1.ShowNewFolderButton = true;
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{ {
textBoxOutputFolder.Text = folderBrowserDialog1.SelectedPath; textBoxOutputFolder.Text = folderBrowserDialog1.SelectedPath;
@ -388,27 +401,32 @@ namespace Nikse.SubtitleEdit.Forms
MessageBox.Show(Configuration.Settings.Language.BatchConvert.NothingToConvert); MessageBox.Show(Configuration.Settings.Language.BatchConvert.NothingToConvert);
return; return;
} }
else if (textBoxOutputFolder.Text.Length < 2)
if (!checkBoxOverwriteOriginalFiles.Checked)
{ {
MessageBox.Show(Configuration.Settings.Language.BatchConvert.PleaseChooseOutputFolder); if (textBoxOutputFolder.Text.Length < 2)
return;
}
else if (!Directory.Exists(textBoxOutputFolder.Text))
{
try
{ {
Directory.CreateDirectory(textBoxOutputFolder.Text); MessageBox.Show(Configuration.Settings.Language.BatchConvert.PleaseChooseOutputFolder);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
return; return;
} }
else if (!Directory.Exists(textBoxOutputFolder.Text))
{
try
{
Directory.CreateDirectory(textBoxOutputFolder.Text);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
return;
}
}
} }
_converting = true; _converting = true;
buttonConvert.Enabled = false; buttonConvert.Enabled = false;
buttonCancel.Enabled = false; buttonCancel.Enabled = false;
progressBar1.Style = ProgressBarStyle.Blocks;
progressBar1.Maximum = listViewInputFiles.Items.Count; progressBar1.Maximum = listViewInputFiles.Items.Count;
progressBar1.Value = 0; progressBar1.Value = 0;
progressBar1.Visible = progressBar1.Maximum > 2; progressBar1.Visible = progressBar1.Maximum > 2;
@ -416,6 +434,7 @@ namespace Nikse.SubtitleEdit.Forms
groupBoxOutput.Enabled = false; groupBoxOutput.Enabled = false;
groupBoxConvertOptions.Enabled = false; groupBoxConvertOptions.Enabled = false;
buttonInputBrowse.Enabled = false; buttonInputBrowse.Enabled = false;
buttonSearchFolder.Enabled = false;
_count = 0; _count = 0;
_converted = 0; _converted = 0;
_errors = 0; _errors = 0;
@ -639,7 +658,7 @@ namespace Nikse.SubtitleEdit.Forms
System.Threading.Thread.Sleep(100); System.Threading.Thread.Sleep(100);
} }
ThreadDoWorkParameter parameter = new ThreadDoWorkParameter(checkBoxFixCommonErrors.Checked, checkBoxMultipleReplace.Checked, checkBoxAutoBalance.Checked, item, sub, GetCurrentSubtitleFormat(), GetCurrentEncoding(), Configuration.Settings.Tools.BatchConvertLanguage, fileName, toFormat, format); ThreadDoWorkParameter parameter = new ThreadDoWorkParameter(checkBoxFixCommonErrors.Checked, checkBoxMultipleReplace.Checked, checkBoxAutoBalance.Checked, checkBoxSetMinimumDisplayTimeBetweenSubs.Checked, item, sub, GetCurrentSubtitleFormat(), GetCurrentEncoding(), Configuration.Settings.Tools.BatchConvertLanguage, fileName, toFormat, format);
if (!worker1.IsBusy) if (!worker1.IsBusy)
worker1.RunWorkerAsync(parameter); worker1.RunWorkerAsync(parameter);
else if (!worker2.IsBusy) else if (!worker2.IsBusy)
@ -676,6 +695,7 @@ namespace Nikse.SubtitleEdit.Forms
groupBoxOutput.Enabled = true; groupBoxOutput.Enabled = true;
groupBoxConvertOptions.Enabled = true; groupBoxConvertOptions.Enabled = true;
buttonInputBrowse.Enabled = true; buttonInputBrowse.Enabled = true;
buttonSearchFolder.Enabled = true;
} }
void DoThreadWork(object sender, DoWorkEventArgs e) void DoThreadWork(object sender, DoWorkEventArgs e)
@ -719,12 +739,28 @@ namespace Nikse.SubtitleEdit.Forms
p.Error = "AutoBalance error: " + exception.Message; p.Error = "AutoBalance error: " + exception.Message;
} }
} }
if (p.SetMinDisplayTimeBetweenSubtitles)
{
double minumumMillisecondsBetweenLines = Configuration.Settings.General.MininumMillisecondsBetweenLines;
for (int i = 0; i < p.Subtitle.Paragraphs.Count - 1; i++)
{
Paragraph current = p.Subtitle.GetParagraphOrDefault(i);
Paragraph next = p.Subtitle.GetParagraphOrDefault(i + 1);
if (next.StartTime.TotalMilliseconds - current.EndTime.TotalMilliseconds < minumumMillisecondsBetweenLines)
current.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - minumumMillisecondsBetweenLines;
}
}
e.Result = p; e.Result = p;
} }
void ThreadWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) void ThreadWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{ {
ThreadDoWorkParameter p = (ThreadDoWorkParameter)e.Result; var p = (ThreadDoWorkParameter)e.Result;
if (p.Item.Index + 2 < listViewInputFiles.Items.Count)
listViewInputFiles.EnsureVisible(p.Item.Index + 2);
else
listViewInputFiles.EnsureVisible(p.Item.Index);
if (!string.IsNullOrEmpty(p.Error)) if (!string.IsNullOrEmpty(p.Error))
{ {
p.Item.SubItems[3].Text = p.Error; p.Item.SubItems[3].Text = p.Error;
@ -733,8 +769,16 @@ namespace Nikse.SubtitleEdit.Forms
{ {
if (p.SourceFormat == null) if (p.SourceFormat == null)
p.SourceFormat = new SubRip(); p.SourceFormat = new SubRip();
bool success;
if (checkBoxOverwriteOriginalFiles.Checked)
{
success = Main.BatchConvertSave(p.ToFormat, null, GetCurrentEncoding(), System.IO.Path.GetDirectoryName(p.FileName), _count, ref _converted, ref _errors, _allFormats, p.FileName, p.Subtitle, p.SourceFormat, true);
}
else
{
success = Main.BatchConvertSave(p.ToFormat, null, GetCurrentEncoding(), textBoxOutputFolder.Text, _count, ref _converted, ref _errors, _allFormats, p.FileName, p.Subtitle, p.SourceFormat, checkBoxOverwrite.Checked);
}
bool success = Main.BatchConvertSave(p.ToFormat, null, GetCurrentEncoding(), textBoxOutputFolder.Text, _count, ref _converted, ref _errors, _allFormats, p.FileName, p.Subtitle, p.SourceFormat, checkBoxOverwrite.Checked);
if (success) if (success)
{ {
p.Item.SubItems[3].Text = Configuration.Settings.Language.BatchConvert.Converted; p.Item.SubItems[3].Text = Configuration.Settings.Language.BatchConvert.Converted;
@ -831,8 +875,6 @@ namespace Nikse.SubtitleEdit.Forms
{ {
if (e.KeyCode == Keys.Delete) if (e.KeyCode == Keys.Delete)
RemoveSelectedFiles(); RemoveSelectedFiles();
if (e.KeyCode == Keys.Escape)
_abort = true;
} }
private void buttonFixCommonErrorSettings_Click(object sender, EventArgs e) private void buttonFixCommonErrorSettings_Click(object sender, EventArgs e)
@ -855,6 +897,7 @@ namespace Nikse.SubtitleEdit.Forms
Configuration.Settings.Tools.BatchConvertFixCommonErrors = checkBoxFixCommonErrors.Checked; Configuration.Settings.Tools.BatchConvertFixCommonErrors = checkBoxFixCommonErrors.Checked;
Configuration.Settings.Tools.BatchConvertRemoveFormatting = checkBoxRemoveFormatting.Checked; Configuration.Settings.Tools.BatchConvertRemoveFormatting = checkBoxRemoveFormatting.Checked;
Configuration.Settings.Tools.BatchConvertRemoveTextForHI = checkBoxRemoveTextForHI.Checked; Configuration.Settings.Tools.BatchConvertRemoveTextForHI = checkBoxRemoveTextForHI.Checked;
Configuration.Settings.Tools.BatchConvertSetMinDisplayTimeBetweenSubtitles = checkBoxSetMinimumDisplayTimeBetweenSubs.Checked;
} }
private void buttonMultipleReplaceSettings_Click(object sender, EventArgs e) private void buttonMultipleReplaceSettings_Click(object sender, EventArgs e)
@ -864,6 +907,96 @@ namespace Nikse.SubtitleEdit.Forms
form.ShowDialog(this); form.ShowDialog(this);
} }
private void checkBoxOverwriteOriginalFiles_CheckedChanged(object sender, EventArgs e)
{
labelChooseOutputFolder.Enabled = !checkBoxOverwriteOriginalFiles.Checked;
textBoxOutputFolder.Enabled = !checkBoxOverwriteOriginalFiles.Checked;
checkBoxOverwrite.Enabled = !checkBoxOverwriteOriginalFiles.Checked;
buttonChooseFolder.Enabled = !checkBoxOverwriteOriginalFiles.Checked;
}
private void buttonSearchFolder_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowNewFolderButton = false;
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
listViewInputFiles.BeginUpdate();
buttonConvert.Enabled = false;
buttonCancel.Enabled = false;
progressBar1.Style = ProgressBarStyle.Marquee;
progressBar1.Visible = true;
groupBoxOutput.Enabled = false;
groupBoxConvertOptions.Enabled = false;
buttonInputBrowse.Enabled = false;
buttonSearchFolder.Enabled = false;
labelStatus.Text = string.Format(Configuration.Settings.Language.BatchConvert.ScanningFolder, folderBrowserDialog1.SelectedPath);
_abort = false;
SearchFolder(folderBrowserDialog1.SelectedPath);
labelStatus.Text = string.Empty;
buttonConvert.Enabled = true;
buttonCancel.Enabled = true;
progressBar1.Style = ProgressBarStyle.Continuous;
progressBar1.Visible = true;
groupBoxOutput.Enabled = true;
groupBoxConvertOptions.Enabled = true;
buttonInputBrowse.Enabled = true;
buttonSearchFolder.Enabled = true;
listViewInputFiles.EndUpdate();
}
}
private void SearchFolder(string path)
{
foreach (string fileName in Directory.GetFiles(path))
{
try
{
string ext = Path.GetExtension(fileName).ToLower();
if (ext != ".png" && ext != ".jpg" && ext != ".dll" && ext != ".exe" && ext != ".zip")
{
var fi = new FileInfo(fileName);
if (fi.Length < 1024 * 1024) // max 1 mb
{
Encoding encoding;
var sub = new Subtitle();
SubtitleFormat format = sub.LoadSubtitle(fileName, out encoding, null);
if (format != null)
{
var item = new ListViewItem(fileName);
item.SubItems.Add(Utilities.FormatBytesToDisplayFileSize(fi.Length));
item.SubItems.Add(format.Name);
item.SubItems.Add("-");
listViewInputFiles.Items.Add(item);
}
}
progressBar1.Refresh();
Application.DoEvents();
if (_abort)
return;
}
}
catch
{
}
}
foreach (string directory in Directory.GetDirectories(path))
{
if (directory != "." && directory != "..")
SearchFolder(directory);
if (_abort)
return;
}
}
private void BatchConvert_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
_abort = true;
}
} }
} }