From f42faa4f264b8ee84016c1386400a05545c5be1b Mon Sep 17 00:00:00 2001 From: Jonas Kamsker <11245306+JKamsker@users.noreply.github.com> Date: Sun, 20 Mar 2022 19:56:17 +0100 Subject: [PATCH] Fixed merge & implemented aax mode --- .../FFMpegArgumentProcessorTest.cs | 8 +++++ .../Arguments/AudibleEncryptionKeyArgument.cs | 14 +++++++- .../FFMpeg/Arguments/MapMetadataArgument.cs | 32 +++++++++++++++---- FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs | 1 + 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs b/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs index c0a565e..6e30999 100644 --- a/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs +++ b/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs @@ -101,5 +101,13 @@ public void Audible_Aaxc_Test() var arg = new AudibleEncryptionKeyArgument("123", "456"); arg.Text.Should().Be($"-audible_key 123 -audible_iv 456"); } + + + [TestMethod] + public void Audible_Aax_Test() + { + var arg = new AudibleEncryptionKeyArgument("62689101"); + arg.Text.Should().Be($"-activation_bytes 62689101"); + } } } \ No newline at end of file diff --git a/FFMpegCore/FFMpeg/Arguments/AudibleEncryptionKeyArgument.cs b/FFMpegCore/FFMpeg/Arguments/AudibleEncryptionKeyArgument.cs index 9f1a325..0f514dc 100644 --- a/FFMpegCore/FFMpeg/Arguments/AudibleEncryptionKeyArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/AudibleEncryptionKeyArgument.cs @@ -2,15 +2,27 @@ { public class AudibleEncryptionKeyArgument : IArgument { + private readonly bool _aaxcMode; + private readonly string _key; private readonly string _iv; + private readonly string _activationBytes; + + + public AudibleEncryptionKeyArgument(string activationBytes) + { + _activationBytes = activationBytes; + } + public AudibleEncryptionKeyArgument(string key, string iv) { + _aaxcMode = true; + _key = key; _iv = iv; } - public string Text => $"-audible_key {_key} -audible_iv {_iv}"; + public string Text => _aaxcMode ? $"-audible_key {_key} -audible_iv {_iv}" : $"-activation_bytes {_activationBytes}"; } } diff --git a/FFMpegCore/FFMpeg/Arguments/MapMetadataArgument.cs b/FFMpegCore/FFMpeg/Arguments/MapMetadataArgument.cs index 01b661c..afec731 100644 --- a/FFMpegCore/FFMpeg/Arguments/MapMetadataArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/MapMetadataArgument.cs @@ -1,5 +1,8 @@ using FFMpegCore.Extend; +using System; +using System.Collections.Generic; +using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -10,8 +13,10 @@ public class MapMetadataArgument : IInputArgument, IDynamicArgument { private readonly int? _inputIndex; + public string Text => GetText(null); + /// - /// Null means it takes the last input used befroe this argument + /// Null means it takes the last input used before this argument /// /// public MapMetadataArgument(int? inputIndex = null) @@ -19,15 +24,28 @@ public MapMetadataArgument(int? inputIndex = null) _inputIndex = inputIndex; } - public string Text => GetText(null); - - public string GetText(StringBuilder context) + public string GetText(IEnumerable? arguments) { - var index = _inputIndex ?? context?.ToString().CountOccurrences("-i") -1 ?? 0; + arguments ??= Enumerable.Empty(); + + var index = 0; + if (_inputIndex is null) + { + index = arguments + .TakeWhile(x => x != this) + .OfType() + .Count(); + + index = Math.Max(index - 1, 0); + } + else + { + index = _inputIndex.Value; + } + return $"-map_metadata {index}"; } - public Task During(CancellationToken cancellationToken = default) { return Task.CompletedTask; @@ -40,5 +58,7 @@ public void Post() public void Pre() { } + + } } diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs index b4f5111..7b3da7a 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs @@ -68,6 +68,7 @@ public FFMpegArgumentOptions WithAudioFilters(Action audioFi public FFMpegArgumentOptions ForcePixelFormat(PixelFormat pixelFormat) => WithArgument(new ForcePixelFormat(pixelFormat)); public FFMpegArgumentOptions WithAudibleEncryptionKeys(string key, string iv) => WithArgument(new AudibleEncryptionKeyArgument(key, iv)); + public FFMpegArgumentOptions WithAudibleActivationBytes(string activationBytes) => WithArgument(new AudibleEncryptionKeyArgument(activationBytes)); public FFMpegArgumentOptions WithTagVersion(int id3v2Version = 3) => WithArgument(new ID3V2VersionArgument(id3v2Version));