Fix crash in "Batch convert" w add after sort - thx Siamak

This commit is contained in:
niksedk 2022-01-03 12:50:26 +01:00
parent 9e19faf5cb
commit cd5548f7a4
6 changed files with 387 additions and 2 deletions

View File

@ -45,6 +45,7 @@
* Fix new-line-char in Bilibili format - thx Kuju29
* Fix "Close video" shortcut - thx OmrSi
* Fix double space issue for output file name in sub burn-in - thx Leon
* Fix crash in "Batch convert" w add after sort - thx Siamak
3.6.4 (3rd December 2021)

View File

@ -0,0 +1,112 @@
namespace Nikse.SubtitleEdit.Forms
{
sealed partial class AudioToTextModelDownload
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.labelPleaseWait = new System.Windows.Forms.Label();
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// labelPleaseWait
//
this.labelPleaseWait.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.labelPleaseWait.AutoSize = true;
this.labelPleaseWait.Location = new System.Drawing.Point(12, 134);
this.labelPleaseWait.Name = "labelPleaseWait";
this.labelPleaseWait.Size = new System.Drawing.Size(70, 13);
this.labelPleaseWait.TabIndex = 17;
this.labelPleaseWait.Text = "Please wait...";
//
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonOK.Location = new System.Drawing.Point(258, 56);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(145, 23);
this.buttonOK.TabIndex = 15;
this.buttonOK.Text = "Download";
this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCancel.Location = new System.Drawing.Point(328, 129);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 16;
this.buttonCancel.Text = "C&ancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(15, 58);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(237, 21);
this.comboBox1.TabIndex = 18;
//
// AudioToTextModelDownload
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(415, 162);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.labelPleaseWait);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.buttonCancel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AudioToTextModelDownload";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "DownloadFfmpeg";
this.Shown += new System.EventHandler(this.DownloadFfmpeg_Shown);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.DownloadFfmpeg_KeyDown);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label labelPleaseWait;
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.ComboBox comboBox1;
}
}

View File

@ -0,0 +1,143 @@
using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Logic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Forms
{
public sealed partial class AudioToTextModelDownload : Form
{
public string FFmpegPath { get; internal set; }
public bool AutoClose { get; internal set; }
public class DownloadModel
{
}
private string[] _modelLinks = new []
{
"https://alphacephei.com/vosk/models/vosk-model-en-us-0.22-lgraph.zip",
"https://alphacephei.com/vosk/models/vosk-model-cn-kaldi-multicn-2-lgraph.zip",
"https://alphacephei.com/vosk/models/vosk-model-small-fr-pguyot-0.3.zip",
"https://alphacephei.com/vosk/models/vosk-model-small-es-0.3.zip",
"https://alphacephei.com/vosk/models/vosk-model-small-de-0.15.zip",
"https://alphacephei.com/vosk/models/vosk-model-small-pt-0.3.zip",
"https://alphacephei.com/vosk/models/vosk-model-small-it-0.4.zip",
"https://alphacephei.com/vosk/models/vosk-model-nl-spraakherkenning-0.6-lgraph.zip",
"https://alphacephei.com/vosk/models/vosk-model-small-sv-rhasspy-0.15.zip",
"https://alphacephei.com/vosk/models/vosk-model-small-fa-0.5.zip",
"https://alphacephei.com/vosk/models/vosk-model-small-tr-0.3.zip",
"https://alphacephei.com/vosk/models/vosk-model-el-gr-0.7.zip",
"https://alphacephei.com/vosk/models/vosk-model-ar-mgb2-0.4.zip",
};
public AudioToTextModelDownload()
{
UiUtil.PreInitialize(this);
InitializeComponent();
UiUtil.FixFonts(this);
Text = string.Format(LanguageSettings.Current.SettingsFfmpeg.XDownload, "FFmpeg");
buttonOK.Text = LanguageSettings.Current.General.Ok;
buttonCancel.Text = LanguageSettings.Current.General.Cancel;
UiUtil.FixLargeFonts(this, buttonOK);
}
private void DownloadFfmpeg_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
private void buttonOK_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void DownloadFfmpeg_Shown(object sender, EventArgs e)
{
try
{
labelPleaseWait.Text = LanguageSettings.Current.General.PleaseWait;
buttonOK.Enabled = false;
Refresh();
Cursor = Cursors.WaitCursor;
string url = "https://github.com/SubtitleEdit/support-files/raw/master/ffpmeg/ffmpeg-" + IntPtr.Size * 8 + ".zip";
var wc = new WebClient { Proxy = Utilities.GetProxy() };
wc.DownloadDataCompleted += wc_DownloadDataCompleted;
wc.DownloadProgressChanged += (o, args) =>
{
labelPleaseWait.Text = LanguageSettings.Current.General.PleaseWait + " " + args.ProgressPercentage + "%";
};
wc.DownloadDataAsync(new Uri(url));
}
catch (Exception exception)
{
labelPleaseWait.Text = string.Empty;
buttonOK.Enabled = true;
Cursor = Cursors.Default;
MessageBox.Show(exception.Message + Environment.NewLine + Environment.NewLine + exception.StackTrace);
}
}
private void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
if (e.Error != null)
{
labelPleaseWait.Text = string.Format(LanguageSettings.Current.SettingsFfmpeg.XDownloadFailed, "ffmpeg");
buttonOK.Enabled = true;
Cursor = Cursors.Default;
return;
}
string folder = Path.Combine(Configuration.DataDirectory, "ffmpeg");
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
using (var ms = new MemoryStream(e.Result))
using (ZipExtractor zip = ZipExtractor.Open(ms))
{
List<ZipExtractor.ZipFileEntry> dir = zip.ReadCentralDir();
foreach (ZipExtractor.ZipFileEntry entry in dir)
{
string fileName = Path.GetFileName(entry.FilenameInZip);
if (fileName != null)
{
string path = Path.Combine(folder, fileName);
if (fileName.EndsWith("ffmpeg.exe", StringComparison.OrdinalIgnoreCase))
{
FFmpegPath = path;
}
zip.ExtractFile(entry, path);
}
}
}
Cursor = Cursors.Default;
labelPleaseWait.Text = string.Empty;
if (AutoClose)
{
DialogResult = DialogResult.OK;
return;
}
buttonOK.Enabled = true;
labelPleaseWait.Text = string.Format(LanguageSettings.Current.SettingsFfmpeg.XDownloadOk, "ffmpeg");
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -610,7 +610,7 @@ namespace Nikse.SubtitleEdit.Forms
Cursor = Cursors.WaitCursor;
labelStatus.Text = LanguageSettings.Current.General.PleaseWait;
listViewInputFiles.BeginUpdate();
foreach (string fileName in openFileDialog1.FileNames)
foreach (var fileName in openFileDialog1.FileNames)
{
AddInputFile(fileName);
Application.DoEvents();
@ -787,9 +787,9 @@ namespace Nikse.SubtitleEdit.Forms
item = new ListViewItem(fileName);
item.SubItems.Add(Utilities.FormatBytesToDisplayFileSize(fi.Length));
listViewInputFiles.Items.Add(item);
item.SubItems.Add($"Matroska/{mkvSubFormat.Key} - {lang}");
item.SubItems.Add("-");
listViewInputFiles.Items.Add(item);
}
}
}

View File

@ -237,6 +237,12 @@
<Compile Include="Forms\AddWaveformBatch.Designer.cs">
<DependentUpon>AddWaveformBatch.cs</DependentUpon>
</Compile>
<Compile Include="Forms\AudioToTextModelDownload.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\AudioToTextModelDownload.Designer.cs">
<DependentUpon>AudioToTextModelDownload.cs</DependentUpon>
</Compile>
<Compile Include="Forms\DownloadVosk.cs">
<SubType>Form</SubType>
</Compile>
@ -1408,6 +1414,9 @@
<EmbeddedResource Include="Forms\AddWaveformBatch.resx">
<DependentUpon>AddWaveformBatch.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\AudioToTextModelDownload.resx">
<DependentUpon>AudioToTextModelDownload.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\DownloadVosk.resx">
<DependentUpon>DownloadVosk.cs</DependentUpon>
</EmbeddedResource>