From 2de242d8e4a4c6c488d1410965dd38719b5de0c9 Mon Sep 17 00:00:00 2001 From: feuster Date: Tue, 25 Apr 2023 17:53:58 +0200 Subject: [PATCH 1/3] Raised version to 2.4 - Raised version to 2.4 as preparation for the next release --- FFchapters2/FFchapters2.csproj | 4 ++-- FFchapters2/Program.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/FFchapters2/FFchapters2.csproj b/FFchapters2/FFchapters2.csproj index 685b3d2..767422f 100644 --- a/FFchapters2/FFchapters2.csproj +++ b/FFchapters2/FFchapters2.csproj @@ -6,8 +6,8 @@ enable enable none - 2.0.0.3 - 2.0.0.3 + 2.0.0.4 + 2.0.0.4 False FFchapters2 Feuster diff --git a/FFchapters2/Program.cs b/FFchapters2/Program.cs index 2ee88ee..d812cb8 100644 --- a/FFchapters2/Program.cs +++ b/FFchapters2/Program.cs @@ -36,7 +36,7 @@ bool ChapterStyle2 = false; bool OSLinux = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux); //GitVersion will be only be actualized/overwritten when using Cake build! -const string GitVersion = "git-d9cac16"; +const string GitVersion = "git-f0dd47e"; #endregion #region Title From 8b6616ee9bc6ad8b13e73190a21124cf52e02f3e Mon Sep 17 00:00:00 2001 From: feuster Date: Tue, 25 Apr 2023 20:31:07 +0200 Subject: [PATCH 2/3] Cake compression method set to best - Cake compression set to best compression level and method BZip2 method which saves ~2MB on Windows release package --- FFchapters2/Program.cs | 2 +- build.cake | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/FFchapters2/Program.cs b/FFchapters2/Program.cs index d812cb8..d9cbb8b 100644 --- a/FFchapters2/Program.cs +++ b/FFchapters2/Program.cs @@ -36,7 +36,7 @@ bool ChapterStyle2 = false; bool OSLinux = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux); //GitVersion will be only be actualized/overwritten when using Cake build! -const string GitVersion = "git-f0dd47e"; +const string GitVersion = "git-2de242d"; #endregion #region Title diff --git a/build.cake b/build.cake index 3bbb75a..5dd632e 100644 --- a/build.cake +++ b/build.cake @@ -177,11 +177,15 @@ Task("ZipRelease") Console.WriteLine("Found no ffmpeg.exe in root folder or missing license file. Zip will contain only FFchapters2"); } + SwitchCompressionMethod method = new SwitchCompressionMethod(); + method.Level = 9; + method.Method = "Bzip2"; SevenZip(new SevenZipSettings { Command = new AddCommand { Files = files, + CompressionMethod = method, Archive = new FilePath($"{WorkDir}/Release/FFchapters2_V{sAssemblyVersion}_{runtime}_{SGitVersion}.zip"), } }); From 1be161d3d17dc89ed64c7d5edb77180d03fbaf97 Mon Sep 17 00:00:00 2001 From: feuster Date: Thu, 9 Nov 2023 18:08:24 +0100 Subject: [PATCH 3/3] Changed spinner to progress bar -Changed spinner to progress bar -Removed fixed cake version for cake build --- .config/dotnet-tools.json | 2 +- Cake_Init_Restore.cmd | 3 +- FFchapters2/Program.cs | 93 +++++++++++++++++++++++++++++---------- 3 files changed, 72 insertions(+), 26 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 831d039..8f3a438 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "cake.tool": { - "version": "3.0.0", + "version": "3.1.0", "commands": [ "dotnet-cake" ] diff --git a/Cake_Init_Restore.cmd b/Cake_Init_Restore.cmd index e991506..fd3fb7a 100644 --- a/Cake_Init_Restore.cmd +++ b/Cake_Init_Restore.cmd @@ -18,6 +18,7 @@ if exist ".config/dotnet-tools.json" ( echo ======================================== echo. dotnet new tool-manifest - dotnet tool install Cake.Tool --version 3.0.0 + rem dotnet tool install Cake.Tool --version 3.0.0 + dotnet tool install Cake.Tool echo. ) diff --git a/FFchapters2/Program.cs b/FFchapters2/Program.cs index d9cbb8b..d64fff0 100644 --- a/FFchapters2/Program.cs +++ b/FFchapters2/Program.cs @@ -1,10 +1,8 @@ #region using using CommandLine; using Spectre.Console; -using System; using System.Diagnostics; using System.Globalization; -using System.Linq; using System.Reflection; using System.Text; using System.Text.RegularExpressions; @@ -13,15 +11,17 @@ #region Declarations //Declarations string buffer; -List ScenesRaw = new List(); -List ScenesAll = new List(); -List ScenesSelected = new List(); -List ChaptersRaw = new List(); -List MetaChaptersRaw = new List(); -List Chapters = new List(); -List MetaChapters = new List(); +List ScenesRaw = new(); +List ScenesAll = new(); +List ScenesSelected = new(); +List ChaptersRaw = new(); +List MetaChaptersRaw = new(); +List Chapters = new(); +List MetaChapters = new(); int ShortStringMaxLength = 80; int Length = 0; +int Duration = 0; +int Progress = 0; string ChapterTitle = ""; string ChapterFile = ""; string InputFile = ""; @@ -36,14 +36,14 @@ bool ChapterStyle2 = false; bool OSLinux = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux); //GitVersion will be only be actualized/overwritten when using Cake build! -const string GitVersion = "git-2de242d"; +const string GitVersion = "git-8b6616e"; #endregion #region Title //Title Console.OutputEncoding = Encoding.UTF8; Console.InputEncoding = Encoding.UTF8; -FigletText fText = new FigletText(FigletFont.Default, AppName == null ? "FFChapters2" : AppName).Centered().Color(Color.Blue); +FigletText fText = new FigletText(FigletFont.Default, AppName ?? "FFChapters2").Centered().Color(Color.Blue); #if DEBUG AppVersion += $" [red]Debug[/]"; #else @@ -294,7 +294,7 @@ if (o.ChapterLength > 0 && o.ChapterLength < 16) { Length = (int)o.ChapterLength; - AnsiConsole.MarkupLine($"[green]Chapter length: {Length.ToString()} (Minutes)[/]"); + AnsiConsole.MarkupLine($"[green]Chapter length: {Length} (Minutes)[/]"); } if (o.Close) @@ -348,7 +348,7 @@ prompt.AddChoice("1 minute"); for (int i = 2; i < 16; i++) { - prompt.AddChoice($"{i.ToString()} minutes"); + prompt.AddChoice($"{i} minutes"); } string selection = AnsiConsole.Prompt(prompt); AnsiConsole.Markup($"[green]{selection}[/]"); @@ -362,15 +362,29 @@ #region FFmpeg execution AnsiConsole.Write(new Rule("[blue]FFmpeg extract scene changes[/]")); AnsiConsole.WriteLine(""); -AnsiConsole.Status() - .Spinner(Spinner.Known.Material) - .SpinnerStyle(Style.Parse("green bold")) - .AutoRefresh(false) - .Start("[green]FFmpeg running[/]", ctx => +AnsiConsole + //.Status() + //.Spinner(Spinner.Known.Material) + //.SpinnerStyle(Style.Parse("green bold")) + //.AutoRefresh(false) + .Progress() + .AutoRefresh(true) + .HideCompleted(true) + .Columns(new ProgressColumn[] { + new TaskDescriptionColumn(), // Task description + new ProgressBarColumn(), // Progress bar + new PercentageColumn(), // Percentage + new RemainingTimeColumn(), // Remaining time + new SpinnerColumn(), // Spinner + }) + .Start(ctx => + { + var task = ctx.AddTask("[green]Extracting scene changes[/]"); try { - Process RunProcess = new Process(); + //Prepare FFmpeg process for chapter extraction + Process RunProcess = new(); if (OSLinux) { RunProcess.StartInfo.FileName = $"{@FFmpeg}"; @@ -395,25 +409,56 @@ void DataReadHandler(object sender, DataReceivedEventArgs e) { if (!String.IsNullOrEmpty(e.Data)) + { + //Add aoutput to raw list ScenesRaw.Add(e.Data); + + //Extract inputfile duration and actual progress + if (Duration == 0) + { + buffer = Regex.Match(string.Join("", ScenesRaw), @"Duration: \d\d:\d\d:\d\d.\d\d").Value.Trim().Replace("Duration: ", "", StringComparison.InvariantCultureIgnoreCase); + if (!string.IsNullOrEmpty(buffer)) + { + Duration = Convert.ToInt32(buffer.Substring(0, 2)) * 3600 + Convert.ToInt32(buffer.Substring(3, 2)) * 60 + Convert.ToInt32(buffer.Substring(6, 2)); + task.MaxValue = Duration; + } + } + else + { + buffer = Regex.Match(ScenesRaw.Last(), @" t:\d*\.\d* ").Value.Trim().Replace("t:", "", StringComparison.InvariantCultureIgnoreCase); + if (!string.IsNullOrEmpty(buffer)) + Progress = Convert.ToInt32(buffer.Substring(0,buffer.IndexOf("."))); + else + { + buffer = Regex.Match(ScenesRaw.Last(), @" pts_time:\d*\.\d* ").Value.Trim().Replace("pts_time:", "", StringComparison.InvariantCultureIgnoreCase); + if (!string.IsNullOrEmpty(buffer)) + Progress = Convert.ToInt32(buffer.Substring(0, buffer.IndexOf("."))); + } + } + } + } RunProcess.ErrorDataReceived += DataReadHandler; RunProcess.OutputDataReceived += DataReadHandler; + //Start FFmpeg chapter extraction var Start = DateTime.Now; AnsiConsole.MarkupLine("[Green]Start: " + Start.ToLongTimeString() + "[/]"); RunProcess.Start(); RunProcess.BeginOutputReadLine(); RunProcess.BeginErrorReadLine(); + + //Show progressbar with time estimation while (!RunProcess.HasExited) { - ctx.Refresh(); + if (task.Value < Progress && Duration != 0) + task.Value = Progress; } + task.Value = task.MaxValue; var Stop = DateTime.Now; AnsiConsole.MarkupLine("[Green]Stop: " + Stop.ToLongTimeString() + "[/]"); AnsiConsole.MarkupLine("[Green]Time: " + (Stop - Start).ToString(@"hh\:mm\:ss") + "[/]"); - ctx.Refresh(); } catch (Exception e) { @@ -457,7 +502,7 @@ void DataReadHandler(object sender, DataReceivedEventArgs e) if (ScenesRaw[i].ToLowerInvariant().Contains("parsed_showinfo") && ScenesRaw[i].ToLowerInvariant().Contains("pts_time")) { buffer = ""; - //support pts_time format for ffmpeg versions <=5.1.2 and >=6.0 + //Support pts_time format for ffmpeg versions <=5.1.2 and >=6.0 buffer = Regex.Match(ScenesRaw[i], "(?<=pts_time:)(.*)(?=\\sduration:)").Value.Trim().Replace(" ", ""); //ffmpeg version >=6.0 if (buffer.Length == 0 || buffer == null) buffer = Regex.Match(ScenesRaw[i], "(?<=pts_time:)(.*)(?=pos:)").Value.Trim().Replace(" ", ""); //ffmpeg version <=5.1.2 @@ -495,7 +540,7 @@ void DataReadHandler(object sender, DataReceivedEventArgs e) ScenesAll = ScenesAll.Distinct().ToList(); ScenesAll.Sort(); -//remove trailing Spaces which were needed for correct sorting +//Remove trailing Spaces which were needed for correct sorting for (int i = 0; i < ScenesAll.Count; i++) { ScenesAll[i] = ScenesAll[i].Trim(); @@ -788,7 +833,7 @@ string GetFFmpegVersion() try { buffer = string.Empty; - Process RunProcess = new Process(); + Process RunProcess = new(); if (OSLinux) { RunProcess.StartInfo.FileName = $"{@FFmpeg}";