Skip to content

Commit

Permalink
Use FFMPEG.NET and Improve Debug logging around DRM Videos
Browse files Browse the repository at this point in the history
  • Loading branch information
sim0n00ps committed Sep 8, 2024
1 parent 806ec1e commit 5107f31
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 49 deletions.
14 changes: 7 additions & 7 deletions OF DL/Helpers/APIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2555,7 +2555,7 @@ public async Task<string> GetDecryptionKey(Dictionary<string, string> drmHeaders

using var response = await client.SendAsync(request);

Log.Debug($"CDRM Project Response (Attempt {attempt}): {response}");
Log.Debug($"CDRM Project Response (Attempt {attempt}): {response.Content.ReadAsStringAsync().Result}");

response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Expand Down Expand Up @@ -2600,18 +2600,18 @@ public async Task<string> GetDecryptionKeyNew(Dictionary<string, string> drmHead
var challenge = cdm.GetChallenge(pssh, certDataB64, false, false);
var resp2 = PostData(licenceURL, drmHeaders, challenge);
var licenseB64 = Convert.ToBase64String(resp2);
Log.Debug($"resp1: {resp1}");
Log.Debug($"certDataB64: {certDataB64}");
Log.Debug($"challenge: {challenge}");
Log.Debug($"resp2: {resp2}");
Log.Debug($"licenseB64: {licenseB64}");
cdm.ProvideLicense(licenseB64);
List<ContentKey> keys = cdm.GetKeys();
if (keys.Count > 0)
{
Log.Debug($"GetDecryptionKeyNew Key: {keys[0].ToString()}");
return keys[0].ToString();
}

Log.Debug($"resp1: {resp1}");
Log.Debug($"certDataB64: {certDataB64}");
Log.Debug($"challenge: {challenge}");
Log.Debug($"resp2: {resp2}");
Log.Debug($"licenseB64: {licenseB64}");
}
catch (Exception ex)
{
Expand Down
19 changes: 4 additions & 15 deletions OF DL/Helpers/DownloadHelper.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FFmpeg.NET;
using OF_DL.Entities;
using OF_DL.Entities.Archived;
using OF_DL.Entities.Messages;
Expand All @@ -21,8 +22,6 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Xabe.FFmpeg;
using Xabe.FFmpeg.Exceptions;
using static OF_DL.Entities.Lists.UserList;
using static OF_DL.Entities.Messages.Messages;

Expand Down Expand Up @@ -601,9 +600,10 @@ private async Task<bool> DownloadDrmMedia(string user_agent, string policy, stri

string parameters = $"-cenc_decryption_key {decKey} -headers \"Cookie:CloudFront-Policy={policy}; CloudFront-Signature={signature}; CloudFront-Key-Pair-Id={kvp}; {sess} Origin: https://onlyfans.com Referer: https://onlyfans.com User-Agent: {user_agent}\" -y -i \"{url}\" -codec copy \"{tempFilename}\"";

var conversion = FFmpeg.Conversions.New().AddParameter(parameters.Replace("\n", "")).SetOverwriteOutput(true);
Log.Debug($"Calling FFMPEG with Parameters: {parameters}");

IConversionResult result = await conversion.Start();
Engine ffmpeg = new Engine(downloadConfig.FFmpegPath);
await ffmpeg.ExecuteAsync(parameters, CancellationToken.None);

if (File.Exists(tempFilename))
{
Expand All @@ -627,17 +627,6 @@ private async Task<bool> DownloadDrmMedia(string user_agent, string policy, stri

return true;
}
catch (ConversionException ex)
{
Console.WriteLine("Exception caught: {0}\n\nStackTrace: {1}", ex.Message, ex.StackTrace);
Log.Error("Exception caught: {0}\n\nStackTrace: {1}", ex.Message, ex.StackTrace);
if (ex.InnerException != null)
{
Console.WriteLine("\nInner Exception:");
Console.WriteLine("Exception caught: {0}\n\nStackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace);
Log.Error("Inner Exception: {0}\n\nStackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception caught: {0}\n\nStackTrace: {1}", ex.Message, ex.StackTrace);
Expand Down
3 changes: 1 addition & 2 deletions OF DL/OF DL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
<PackageReference Include="Xabe.FFmpeg" Version="5.2.6" />
<PackageReference Include="Xabe.FFmpeg.Downloader" Version="5.2.6" />
<PackageReference Include="xFFmpeg.NET" Version="7.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
30 changes: 5 additions & 25 deletions OF DL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using Xabe.FFmpeg;
using Xabe.FFmpeg.Downloader;
using static OF_DL.Entities.Messages.Messages;

namespace OF_DL;
Expand Down Expand Up @@ -258,17 +256,13 @@ public async static Task Main(string[] args)
if (!string.IsNullOrEmpty(config!.FFmpegPath) && ValidateFilePath(config.FFmpegPath))
{
// FFmpeg path is set in config.json and is valid
DirectoryInfo directory = Directory.GetParent(config.FFmpegPath);
FFmpeg.SetExecutablesPath(directory.FullName);
ffmpegFound = true;
Log.Debug($"FFMPEG found: {config.FFmpegPath}");
Log.Debug("FFMPEG path set in config.json");
}
else if (!string.IsNullOrEmpty(auth!.FFMPEG_PATH) && ValidateFilePath(auth.FFMPEG_PATH))
{
// FFmpeg path is set in auth.json and is valid (config.json takes precedence and auth.json is only available for backward compatibility)
DirectoryInfo directory = Directory.GetParent(auth.FFMPEG_PATH);
FFmpeg.SetExecutablesPath(directory.FullName);
ffmpegFound = true;
config.FFmpegPath = auth.FFMPEG_PATH;
Log.Debug($"FFMPEG found: {config.FFmpegPath}");
Expand All @@ -281,8 +275,6 @@ public async static Task Main(string[] args)
if (ffmpegPath != null)
{
// FFmpeg is found in the PATH or current directory
DirectoryInfo directory = Directory.GetParent(ffmpegPath);
FFmpeg.SetExecutablesPath(directory.FullName);
ffmpegFound = true;
pathAutoDetected = true;
config.FFmpegPath = ffmpegPath;
Expand All @@ -296,8 +288,6 @@ public async static Task Main(string[] args)
if (ffmpegPath != null)
{
// FFmpeg windows executable is found in the PATH or current directory
DirectoryInfo directory = Directory.GetParent(ffmpegPath);
FFmpeg.SetExecutablesPath(directory.FullName);
ffmpegFound = true;
pathAutoDetected = true;
config.FFmpegPath = ffmpegPath;
Expand Down Expand Up @@ -326,23 +316,13 @@ public async static Task Main(string[] args)
}
else
{
AnsiConsole.Markup("[yellow]Cannot locate FFmpeg; Attempting to download latest version.[/]");
await FFmpegDownloader.GetLatestVersion(FFmpegVersion.Full);
string ffmpegExePath = Path.Combine(FFmpeg.ExecutablesPath, "ffmpeg.exe");
if (!File.Exists(ffmpegExePath))
AnsiConsole.Markup("[red]Cannot locate FFmpeg; please modify config.json with the correct path. Press any key to exit.[/]");
Log.Error($"Cannot locate FFmpeg with path: {config.FFmpegPath}");
if (!config.NonInteractiveMode)
{
AnsiConsole.Markup("[red]Cannot locate FFmpeg; please modify config.json with the correct path. Press any key to exit.[/]");
Log.Error($"Cannot locate FFmpeg with path: {config.FFmpegPath}");
if (!config.NonInteractiveMode)
{
Console.ReadKey();
}
Environment.Exit(4);
}
else
{
AnsiConsole.Markup($"[green]FFmpeg located successfully\n[/]");
Console.ReadKey();
}
Environment.Exit(4);
}

if (!File.Exists(Path.Join(WidevineClient.Widevine.Constants.DEVICES_FOLDER, WidevineClient.Widevine.Constants.DEVICE_NAME, "device_client_id_blob")))
Expand Down

0 comments on commit 5107f31

Please sign in to comment.