Fixed merge & implemented aax mode

This commit is contained in:
Jonas Kamsker 2022-03-20 19:56:17 +01:00
parent 499d03f710
commit f42faa4f26
4 changed files with 48 additions and 7 deletions

View file

@ -101,5 +101,13 @@ public void Audible_Aaxc_Test()
var arg = new AudibleEncryptionKeyArgument("123", "456"); var arg = new AudibleEncryptionKeyArgument("123", "456");
arg.Text.Should().Be($"-audible_key 123 -audible_iv 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");
}
} }
} }

View file

@ -2,15 +2,27 @@
{ {
public class AudibleEncryptionKeyArgument : IArgument public class AudibleEncryptionKeyArgument : IArgument
{ {
private readonly bool _aaxcMode;
private readonly string _key; private readonly string _key;
private readonly string _iv; private readonly string _iv;
private readonly string _activationBytes;
public AudibleEncryptionKeyArgument(string activationBytes)
{
_activationBytes = activationBytes;
}
public AudibleEncryptionKeyArgument(string key, string iv) public AudibleEncryptionKeyArgument(string key, string iv)
{ {
_aaxcMode = true;
_key = key; _key = key;
_iv = iv; _iv = iv;
} }
public string Text => $"-audible_key {_key} -audible_iv {_iv}"; public string Text => _aaxcMode ? $"-audible_key {_key} -audible_iv {_iv}" : $"-activation_bytes {_activationBytes}";
} }
} }

View file

@ -1,5 +1,8 @@
using FFMpegCore.Extend; using FFMpegCore.Extend;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -10,8 +13,10 @@ public class MapMetadataArgument : IInputArgument, IDynamicArgument
{ {
private readonly int? _inputIndex; private readonly int? _inputIndex;
public string Text => GetText(null);
/// <summary> /// <summary>
/// Null means it takes the last input used befroe this argument /// Null means it takes the last input used before this argument
/// </summary> /// </summary>
/// <param name="inputIndex"></param> /// <param name="inputIndex"></param>
public MapMetadataArgument(int? inputIndex = null) public MapMetadataArgument(int? inputIndex = null)
@ -19,14 +24,27 @@ public MapMetadataArgument(int? inputIndex = null)
_inputIndex = inputIndex; _inputIndex = inputIndex;
} }
public string Text => GetText(null); public string GetText(IEnumerable<IArgument>? arguments)
public string GetText(StringBuilder context)
{ {
var index = _inputIndex ?? context?.ToString().CountOccurrences("-i") -1 ?? 0; arguments ??= Enumerable.Empty<IArgument>();
return $"-map_metadata {index}";
var index = 0;
if (_inputIndex is null)
{
index = arguments
.TakeWhile(x => x != this)
.OfType<IInputArgument>()
.Count();
index = Math.Max(index - 1, 0);
}
else
{
index = _inputIndex.Value;
} }
return $"-map_metadata {index}";
}
public Task During(CancellationToken cancellationToken = default) public Task During(CancellationToken cancellationToken = default)
{ {
@ -40,5 +58,7 @@ public void Post()
public void Pre() public void Pre()
{ {
} }
} }
} }

View file

@ -68,6 +68,7 @@ public FFMpegArgumentOptions WithAudioFilters(Action<AudioFilterOptions> audioFi
public FFMpegArgumentOptions ForcePixelFormat(PixelFormat pixelFormat) => WithArgument(new ForcePixelFormat(pixelFormat)); public FFMpegArgumentOptions ForcePixelFormat(PixelFormat pixelFormat) => WithArgument(new ForcePixelFormat(pixelFormat));
public FFMpegArgumentOptions WithAudibleEncryptionKeys(string key, string iv) => WithArgument(new AudibleEncryptionKeyArgument(key, iv)); 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)); public FFMpegArgumentOptions WithTagVersion(int id3v2Version = 3) => WithArgument(new ID3V2VersionArgument(id3v2Version));