From 5107f311d472893082e0967923190948cd69b637 Mon Sep 17 00:00:00 2001 From: sim0n00ps Date: Sun, 8 Sep 2024 22:42:28 +0100 Subject: [PATCH] Use FFMPEG.NET and Improve Debug logging around DRM Videos --- OF DL/Helpers/APIHelper.cs | 14 +++++++------- OF DL/Helpers/DownloadHelper.cs | 19 ++++--------------- OF DL/OF DL.csproj | 3 +-- OF DL/Program.cs | 30 +++++------------------------- 4 files changed, 17 insertions(+), 49 deletions(-) diff --git a/OF DL/Helpers/APIHelper.cs b/OF DL/Helpers/APIHelper.cs index 6660ca31..ec3a9ae5 100644 --- a/OF DL/Helpers/APIHelper.cs +++ b/OF DL/Helpers/APIHelper.cs @@ -2555,7 +2555,7 @@ public async Task GetDecryptionKey(Dictionary 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(); @@ -2600,18 +2600,18 @@ public async Task GetDecryptionKeyNew(Dictionary 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 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) { diff --git a/OF DL/Helpers/DownloadHelper.cs b/OF DL/Helpers/DownloadHelper.cs index c6556057..946a5eba 100644 --- a/OF DL/Helpers/DownloadHelper.cs +++ b/OF DL/Helpers/DownloadHelper.cs @@ -1,3 +1,4 @@ +using FFmpeg.NET; using OF_DL.Entities; using OF_DL.Entities.Archived; using OF_DL.Entities.Messages; @@ -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; @@ -601,9 +600,10 @@ private async Task 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)) { @@ -627,17 +627,6 @@ private async Task 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); diff --git a/OF DL/OF DL.csproj b/OF DL/OF DL.csproj index f5b0c14b..47257bcf 100755 --- a/OF DL/OF DL.csproj +++ b/OF DL/OF DL.csproj @@ -24,8 +24,7 @@ - - + diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 3500e833..20d3197f 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -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; @@ -258,8 +256,6 @@ 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"); @@ -267,8 +263,6 @@ public async static Task Main(string[] args) 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}"); @@ -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; @@ -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; @@ -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")))