From 5185f566e32c6842179855f6fc257b34b405a33f Mon Sep 17 00:00:00 2001 From: Jonas Kamsker <11245306+JKamsker@users.noreply.github.com> Date: Sun, 20 Mar 2022 19:31:15 +0100 Subject: [PATCH 1/3] Applied reqested changes Former-commit-id: 5b0d3d21c9946fb8095559faf3a4ef139115a2ef --- FFMpegCore/Extend/StringExtensions.cs | 5 +-- .../FFMpeg/Arguments/IDynamicArgument.cs | 6 ++-- .../FFMpeg/Arguments/MetaDataArgument.cs | 10 ++++-- FFMpegCore/FFMpeg/FFMpegArguments.cs | 33 ++++++++++--------- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/FFMpegCore/Extend/StringExtensions.cs b/FFMpegCore/Extend/StringExtensions.cs index d07ad1e..35f2e84 100644 --- a/FFMpegCore/Extend/StringExtensions.cs +++ b/FFMpegCore/Extend/StringExtensions.cs @@ -93,12 +93,9 @@ public static int CountOccurrences(this string s, string substring, bool aggressiveSearch = false) { // if s or substring is null or empty, substring cannot be found in s - if (string.IsNullOrEmpty(s) || string.IsNullOrEmpty(substring)) - return 0; - // if the length of substring is greater than the length of s, // substring cannot be found in s - if (substring.Length > s.Length) + if (string.IsNullOrEmpty(s) || string.IsNullOrEmpty(substring) || substring.Length > s.Length) return 0; int count = 0, n = 0; diff --git a/FFMpegCore/FFMpeg/Arguments/IDynamicArgument.cs b/FFMpegCore/FFMpeg/Arguments/IDynamicArgument.cs index 1213630..36a504e 100644 --- a/FFMpegCore/FFMpeg/Arguments/IDynamicArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/IDynamicArgument.cs @@ -1,4 +1,5 @@ -using System.Text; +using System.Collections.Generic; +using System.Text; namespace FFMpegCore.Arguments { @@ -9,6 +10,7 @@ public interface IDynamicArgument /// /// /// - public string GetText(StringBuilder context); + //public string GetText(StringBuilder context); + public string GetText(IEnumerable context); } } \ No newline at end of file diff --git a/FFMpegCore/FFMpeg/Arguments/MetaDataArgument.cs b/FFMpegCore/FFMpeg/Arguments/MetaDataArgument.cs index c34257e..89bb1fe 100644 --- a/FFMpegCore/FFMpeg/Arguments/MetaDataArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/MetaDataArgument.cs @@ -1,6 +1,7 @@ using FFMpegCore.Extend; using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -28,9 +29,14 @@ public MetaDataArgument(string metaDataContent) public void Post() => File.Delete(_tempFileName); - public string GetText(StringBuilder context) + public string GetText(IEnumerable? arguments) { - var index = context.ToString().CountOccurrences("-i"); + arguments ??= Enumerable.Empty(); + + var index = arguments + .TakeWhile(x => x != this) + .OfType() + .Count(); return $"-i \"{_tempFileName}\" -map_metadata {index}"; } diff --git a/FFMpegCore/FFMpeg/FFMpegArguments.cs b/FFMpegCore/FFMpeg/FFMpegArguments.cs index 4546dbe..e7a5940 100644 --- a/FFMpegCore/FFMpeg/FFMpegArguments.cs +++ b/FFMpegCore/FFMpeg/FFMpegArguments.cs @@ -22,24 +22,27 @@ private FFMpegArguments() { } private string GetText() { - var sb = new StringBuilder(); - var appendSpace = false; + //var sb = new StringBuilder(); + //var appendSpace = false; - foreach (var arg in _globalArguments.Arguments.Concat(Arguments)) - { - if (appendSpace) - { - sb.Append(' '); - } - else - { - appendSpace = true; - } + //foreach (var arg in _globalArguments.Arguments.Concat(Arguments)) + //{ + // if (appendSpace) + // { + // sb.Append(' '); + // } + // else + // { + // appendSpace = true; + // } - sb.Append(arg is IDynamicArgument dynArg ? dynArg.GetText(sb) : arg.Text); - } + // sb.Append(arg is IDynamicArgument dynArg ? dynArg.GetText(sb) : arg.Text); + //} - return sb.ToString(); + //return sb.ToString(); + + var allArguments = _globalArguments.Arguments.Concat(Arguments).ToArray(); + return string.Join(" ", allArguments.Select(arg => arg is IDynamicArgument dynArg ? dynArg.GetText(allArguments) : arg.Text)); } public static FFMpegArguments FromConcatInput(IEnumerable filePaths, Action? addArguments = null) => new FFMpegArguments().WithInput(new ConcatArgument(filePaths), addArguments); From 6be96905270c9d0f817647264d3175be2c58c6ce Mon Sep 17 00:00:00 2001 From: Jonas Kamsker <11245306+JKamsker@users.noreply.github.com> Date: Sun, 20 Mar 2022 19:32:48 +0100 Subject: [PATCH 2/3] Removed string count extension Former-commit-id: 373c604a11b4050846d88a15f57b919e16dd7e1e --- FFMpegCore/Extend/StringExtensions.cs | 43 --------------------------- 1 file changed, 43 deletions(-) diff --git a/FFMpegCore/Extend/StringExtensions.cs b/FFMpegCore/Extend/StringExtensions.cs index 35f2e84..7b02089 100644 --- a/FFMpegCore/Extend/StringExtensions.cs +++ b/FFMpegCore/Extend/StringExtensions.cs @@ -67,48 +67,5 @@ public static string Replace(this string str, Dictionary replaceLi return parsedString.ToString(); } - - /// - /// Counts the number of occurrences of the specified substring within - /// the current string. - /// - /// The current string. - /// The substring we are searching for. - /// Indicates whether or not the algorithm - /// should be aggressive in its search behavior (see Remarks). Default - /// behavior is non-aggressive. - /// This algorithm has two search modes - aggressive and - /// non-aggressive. When in aggressive search mode (aggressiveSearch = - /// true), the algorithm will try to match at every possible starting - /// character index within the string. When false, all subsequent - /// character indexes within a substring match will not be evaluated. - /// For example, if the string was 'abbbc' and we were searching for - /// the substring 'bb', then aggressive search would find 2 matches - /// with starting indexes of 1 and 2. Non aggressive search would find - /// just 1 match with starting index at 1. After the match was made, - /// the non aggressive search would attempt to make it's next match - /// starting at index 3 instead of 2. - /// The count of occurrences of the substring within the string. - public static int CountOccurrences(this string s, string substring, - bool aggressiveSearch = false) - { - // if s or substring is null or empty, substring cannot be found in s - // if the length of substring is greater than the length of s, - // substring cannot be found in s - if (string.IsNullOrEmpty(s) || string.IsNullOrEmpty(substring) || substring.Length > s.Length) - return 0; - - int count = 0, n = 0; - while ((n = s.IndexOf(substring, n, StringComparison.InvariantCulture)) != -1) - { - if (aggressiveSearch) - n++; - else - n += substring.Length; - count++; - } - - return count; - } } } \ No newline at end of file From 59e5ceb45583c87c3ac80992d7543d4ded745f93 Mon Sep 17 00:00:00 2001 From: Jonas Kamsker <11245306+JKamsker@users.noreply.github.com> Date: Sun, 20 Mar 2022 19:34:01 +0100 Subject: [PATCH 3/3] Removed comment Former-commit-id: 353bbff1b883ebeaf2412977ae581bb548585e68 --- FFMpegCore/FFMpeg/FFMpegArguments.cs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/FFMpegCore/FFMpeg/FFMpegArguments.cs b/FFMpegCore/FFMpeg/FFMpegArguments.cs index e7a5940..a93f1bd 100644 --- a/FFMpegCore/FFMpeg/FFMpegArguments.cs +++ b/FFMpegCore/FFMpeg/FFMpegArguments.cs @@ -22,25 +22,6 @@ private FFMpegArguments() { } private string GetText() { - //var sb = new StringBuilder(); - //var appendSpace = false; - - //foreach (var arg in _globalArguments.Arguments.Concat(Arguments)) - //{ - // if (appendSpace) - // { - // sb.Append(' '); - // } - // else - // { - // appendSpace = true; - // } - - // sb.Append(arg is IDynamicArgument dynArg ? dynArg.GetText(sb) : arg.Text); - //} - - //return sb.ToString(); - var allArguments = _globalArguments.Arguments.Concat(Arguments).ToArray(); return string.Join(" ", allArguments.Select(arg => arg is IDynamicArgument dynArg ? dynArg.GetText(allArguments) : arg.Text)); }