From 265d67b1f9d453e1a976c6a38ea5aa4e229d975b Mon Sep 17 00:00:00 2001 From: niksedk Date: Tue, 22 Aug 2023 19:35:14 +0200 Subject: [PATCH] Add auto dl of ffprobe --- SubtitleEdit.sln.DotSettings | 2 ++ src/ui/Forms/AddWaveform.cs | 2 +- src/ui/Forms/AddWaveformBatch.cs | 4 +-- .../BeautifyTimeCodes.Designer.cs | 2 +- .../BeautifyTimeCodes/BeautifyTimeCodes.cs | 34 +++++++++++++++---- src/ui/Forms/DownloadFfmpeg.cs | 12 +++++-- src/ui/Forms/ImportCdg.cs | 2 +- src/ui/Forms/Main.cs | 13 ++++++- src/ui/Forms/Options/Settings.cs | 2 +- src/ui/Forms/ShotChanges/ImportShotChanges.cs | 2 +- 10 files changed, 58 insertions(+), 17 deletions(-) diff --git a/SubtitleEdit.sln.DotSettings b/SubtitleEdit.sln.DotSettings index 4ca162d2b..f3316cae4 100644 --- a/SubtitleEdit.sln.DotSettings +++ b/SubtitleEdit.sln.DotSettings @@ -24,7 +24,9 @@ True True True + True True + True True True True diff --git a/src/ui/Forms/AddWaveform.cs b/src/ui/Forms/AddWaveform.cs index 88c79a509..fa37fa373 100644 --- a/src/ui/Forms/AddWaveform.cs +++ b/src/ui/Forms/AddWaveform.cs @@ -169,7 +169,7 @@ namespace Nikse.SubtitleEdit.Forms return; } - using (var form = new DownloadFfmpeg { AutoClose = true }) + using (var form = new DownloadFfmpeg("FFmpeg") { AutoClose = true }) { if (form.ShowDialog(this) == DialogResult.OK && !string.IsNullOrEmpty(form.FFmpegPath)) { diff --git a/src/ui/Forms/AddWaveformBatch.cs b/src/ui/Forms/AddWaveformBatch.cs index fa3ee47ce..eb1c1ec5e 100644 --- a/src/ui/Forms/AddWaveformBatch.cs +++ b/src/ui/Forms/AddWaveformBatch.cs @@ -53,7 +53,7 @@ namespace Nikse.SubtitleEdit.Forms checkBoxExtractTimeCodes.Text = LanguageSettings.Current.AddWaveformBatch.ExtractTimeCodes; checkBoxExtractTimeCodes.Left = checkBoxGenerateShotChanges.Left - checkBoxExtractTimeCodes.Width - 20; - checkBoxExtractTimeCodes.Visible = BeautifyTimeCodes.BeautifyTimeCodes.IsFfProbeAvailable(); + checkBoxExtractTimeCodes.Visible = BeautifyTimeCodes.BeautifyTimeCodes.IsFfProbeAvailable(this); if (checkBoxExtractTimeCodes.Visible) { @@ -308,7 +308,7 @@ namespace Nikse.SubtitleEdit.Forms return; } - using (var form = new DownloadFfmpeg()) + using (var form = new DownloadFfmpeg("FFmpeg")) { if (form.ShowDialog(this) == DialogResult.OK && !string.IsNullOrEmpty(form.FFmpegPath)) { diff --git a/src/ui/Forms/BeautifyTimeCodes/BeautifyTimeCodes.Designer.cs b/src/ui/Forms/BeautifyTimeCodes/BeautifyTimeCodes.Designer.cs index 57e9f4d84..0969ae6d2 100644 --- a/src/ui/Forms/BeautifyTimeCodes/BeautifyTimeCodes.Designer.cs +++ b/src/ui/Forms/BeautifyTimeCodes/BeautifyTimeCodes.Designer.cs @@ -128,11 +128,11 @@ namespace Nikse.SubtitleEdit.Forms.BeautifyTimeCodes // // panelExtractTimeCodes // - this.panelExtractTimeCodes.Controls.Add(this.buttonCancelTimeCodes); this.panelExtractTimeCodes.Controls.Add(this.labelExtractTimeCodesProgress); this.panelExtractTimeCodes.Controls.Add(this.progressBarExtractTimeCodes); this.panelExtractTimeCodes.Controls.Add(this.buttonExtractTimeCodes); this.panelExtractTimeCodes.Controls.Add(this.labelTimeCodesStatus); + this.panelExtractTimeCodes.Controls.Add(this.buttonCancelTimeCodes); this.panelExtractTimeCodes.Location = new System.Drawing.Point(0, 27); this.panelExtractTimeCodes.Name = "panelExtractTimeCodes"; this.panelExtractTimeCodes.Size = new System.Drawing.Size(546, 78); diff --git a/src/ui/Forms/BeautifyTimeCodes/BeautifyTimeCodes.cs b/src/ui/Forms/BeautifyTimeCodes/BeautifyTimeCodes.cs index c17637018..6991dbe60 100644 --- a/src/ui/Forms/BeautifyTimeCodes/BeautifyTimeCodes.cs +++ b/src/ui/Forms/BeautifyTimeCodes/BeautifyTimeCodes.cs @@ -85,7 +85,7 @@ namespace Nikse.SubtitleEdit.Forms.BeautifyTimeCodes _shotChanges = shotChanges; // Check if ffprobe is available - if (!IsFfProbeAvailable()) + if (!IsFfProbeAvailable(this)) { checkBoxExtractExactTimeCodes.Enabled = false; checkBoxExtractExactTimeCodes.Checked = false; @@ -322,12 +322,34 @@ namespace Nikse.SubtitleEdit.Forms.BeautifyTimeCodes _abortTimeCodes = true; } - public static bool IsFfProbeAvailable() + public static bool IsFfProbeAvailable(Form parentForm) { - return !Configuration.IsRunningOnWindows || ( - !string.IsNullOrWhiteSpace(Configuration.Settings.General.FFmpegLocation) - && File.Exists(Path.Combine(Path.GetDirectoryName(Configuration.Settings.General.FFmpegLocation), "ffprobe.exe")) - ); + if (!Configuration.IsRunningOnWindows) + { + return true; + } + + var ffprobeExists = !string.IsNullOrWhiteSpace(Configuration.Settings.General.FFmpegLocation) + && File.Exists(Path.Combine(Path.GetDirectoryName(Configuration.Settings.General.FFmpegLocation), "ffprobe.exe")); + + if (!ffprobeExists) + { + if (MessageBox.Show(string.Format(LanguageSettings.Current.Settings.DownloadX, "ffprobe"), "Subtitle Edit", MessageBoxButtons.YesNoCancel) != DialogResult.Yes) + { + return false; + } + + using (var form = new DownloadFfmpeg("ffprobe")) + { + if (form.ShowDialog(parentForm) == DialogResult.OK) + { + return !string.IsNullOrWhiteSpace(Configuration.Settings.General.FFmpegLocation) + && File.Exists(Path.Combine(Path.GetDirectoryName(Configuration.Settings.General.FFmpegLocation), "ffprobe.exe")); + } + } + } + + return ffprobeExists; } } } \ No newline at end of file diff --git a/src/ui/Forms/DownloadFfmpeg.cs b/src/ui/Forms/DownloadFfmpeg.cs index eecdbe008..37256b171 100644 --- a/src/ui/Forms/DownloadFfmpeg.cs +++ b/src/ui/Forms/DownloadFfmpeg.cs @@ -14,13 +14,15 @@ namespace Nikse.SubtitleEdit.Forms public string FFmpegPath { get; internal set; } public bool AutoClose { get; internal set; } private readonly CancellationTokenSource _cancellationTokenSource; + private readonly string _title; - public DownloadFfmpeg() + public DownloadFfmpeg(string title) { UiUtil.PreInitialize(this); InitializeComponent(); UiUtil.FixFonts(this); - Text = string.Format(LanguageSettings.Current.Settings.DownloadX, "FFmpeg"); + _title = title; + Text = string.Format(LanguageSettings.Current.Settings.DownloadX, title); buttonOK.Text = LanguageSettings.Current.General.Ok; buttonCancel.Text = LanguageSettings.Current.General.Cancel; UiUtil.FixLargeFonts(this, buttonOK); @@ -49,6 +51,10 @@ namespace Nikse.SubtitleEdit.Forms private void DownloadFfmpeg_Shown(object sender, EventArgs e) { var url = "https://github.com/SubtitleEdit/support-files/raw/master/ffpmeg/ffmpeg-" + IntPtr.Size * 8 + ".zip"; + if (_title.Contains("ffprobe", StringComparison.OrdinalIgnoreCase)) + { + url = "https://github.com/SubtitleEdit/support-files/releases/download/ffprove-6.0/ffprobe.zip"; + } try { @@ -133,7 +139,7 @@ namespace Nikse.SubtitleEdit.Forms } buttonOK.Enabled = true; - labelPleaseWait.Text = string.Format(LanguageSettings.Current.SettingsFfmpeg.XDownloadOk, "ffmpeg"); + labelPleaseWait.Text = string.Format(LanguageSettings.Current.SettingsFfmpeg.XDownloadOk, _title); } } } diff --git a/src/ui/Forms/ImportCdg.cs b/src/ui/Forms/ImportCdg.cs index 769ed9576..dbf4700ac 100644 --- a/src/ui/Forms/ImportCdg.cs +++ b/src/ui/Forms/ImportCdg.cs @@ -377,7 +377,7 @@ namespace Nikse.SubtitleEdit.Forms private void buttonDownloadFfmpeg_Click(object sender, EventArgs e) { - using (var form = new DownloadFfmpeg()) + using (var form = new DownloadFfmpeg("FFmpeg")) { if (form.ShowDialog(this) == DialogResult.OK && !string.IsNullOrEmpty(form.FFmpegPath)) { diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index f862dd5c8..e0c9ebac1 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -35198,7 +35198,7 @@ namespace Nikse.SubtitleEdit.Forms return false; } - using (var form = new DownloadFfmpeg()) + using (var form = new DownloadFfmpeg("FFmpeg")) { if (form.ShowDialog(this) == DialogResult.OK && !string.IsNullOrEmpty(form.FFmpegPath)) { @@ -35672,6 +35672,17 @@ namespace Nikse.SubtitleEdit.Forms return; } + if (string.IsNullOrEmpty(_videoFileName)) + { + MessageBox.Show(LanguageSettings.Current.General.NoVideoLoaded); + return; + } + + if (!RequireFfmpegOk()) + { + return; + } + if (onlySelectedLines) { var selectedIndices = SubtitleListview1.GetSelectedIndices(); diff --git a/src/ui/Forms/Options/Settings.cs b/src/ui/Forms/Options/Settings.cs index 9313b2f43..716388c8f 100644 --- a/src/ui/Forms/Options/Settings.cs +++ b/src/ui/Forms/Options/Settings.cs @@ -3046,7 +3046,7 @@ namespace Nikse.SubtitleEdit.Forms.Options private void buttonDownloadFfmpeg_Click(object sender, EventArgs e) { - using (var form = new DownloadFfmpeg()) + using (var form = new DownloadFfmpeg("FFmpeg")) { if (form.ShowDialog(this) == DialogResult.OK && !string.IsNullOrEmpty(form.FFmpegPath)) { diff --git a/src/ui/Forms/ShotChanges/ImportShotChanges.cs b/src/ui/Forms/ShotChanges/ImportShotChanges.cs index 4800c663e..b868d1516 100644 --- a/src/ui/Forms/ShotChanges/ImportShotChanges.cs +++ b/src/ui/Forms/ShotChanges/ImportShotChanges.cs @@ -419,7 +419,7 @@ namespace Nikse.SubtitleEdit.Forms.ShotChanges private void buttonDownloadFfmpeg_Click(object sender, EventArgs e) { - using (var form = new DownloadFfmpeg()) + using (var form = new DownloadFfmpeg("FFmpeg")) { if (form.ShowDialog(this) == DialogResult.OK && !string.IsNullOrEmpty(form.FFmpegPath)) {