Skip to content

Commit

Permalink
Merge pull request #4 from feuster/V2.4
Browse files Browse the repository at this point in the history
Raised version to 2.4
  • Loading branch information
feuster authored Nov 9, 2023
2 parents f0dd47e + 1be161d commit 7f23622
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "3.0.0",
"version": "3.1.0",
"commands": [
"dotnet-cake"
]
Expand Down
3 changes: 2 additions & 1 deletion Cake_Init_Restore.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
)
4 changes: 2 additions & 2 deletions FFchapters2/FFchapters2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ErrorReport>none</ErrorReport>
<AssemblyVersion>2.0.0.3</AssemblyVersion>
<FileVersion>2.0.0.3</FileVersion>
<AssemblyVersion>2.0.0.4</AssemblyVersion>
<FileVersion>2.0.0.4</FileVersion>
<SignAssembly>False</SignAssembly>
<Title>FFchapters2</Title>
<Company>Feuster</Company>
Expand Down
93 changes: 69 additions & 24 deletions FFchapters2/Program.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,15 +11,17 @@
#region Declarations
//Declarations
string buffer;
List<string> ScenesRaw = new List<string>();
List<string> ScenesAll = new List<string>();
List<string> ScenesSelected = new List<string>();
List<string> ChaptersRaw = new List<string>();
List<string> MetaChaptersRaw = new List<string>();
List<string> Chapters = new List<string>();
List<string> MetaChapters = new List<string>();
List<string> ScenesRaw = new();
List<string> ScenesAll = new();
List<string> ScenesSelected = new();
List<string> ChaptersRaw = new();
List<string> MetaChaptersRaw = new();
List<string> Chapters = new();
List<string> MetaChapters = new();
int ShortStringMaxLength = 80;
int Length = 0;
int Duration = 0;
int Progress = 0;
string ChapterTitle = "";
string ChapterFile = "";
string InputFile = "";
Expand All @@ -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-d9cac16";
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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}[/]");
Expand All @@ -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}";
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -788,7 +833,7 @@ string GetFFmpegVersion()
try
{
buffer = string.Empty;
Process RunProcess = new Process();
Process RunProcess = new();
if (OSLinux)
{
RunProcess.StartInfo.FileName = $"{@FFmpeg}";
Expand Down
4 changes: 4 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
});
Expand Down

0 comments on commit 7f23622

Please sign in to comment.