From 4b08c127636bd12166a1a8d0b3204f74af8629e6 Mon Sep 17 00:00:00 2001 From: whimsical-c4lic0 Date: Sat, 17 Feb 2024 00:47:03 -0600 Subject: [PATCH 1/3] Move ffmpeg path to config.json with path detection fallback and auth.json fallback --- OF DL/Entities/Config.cs | 1 + OF DL/Helpers/DownloadHelper.cs | 32 ++++---- OF DL/Helpers/Interfaces/IDownloadHelper.cs | 14 ++-- OF DL/Program.cs | 83 ++++++++++++++++----- docker/entrypoint.sh | 6 +- 5 files changed, 92 insertions(+), 44 deletions(-) diff --git a/OF DL/Entities/Config.cs b/OF DL/Entities/Config.cs index 32e1fd4a..537d42ae 100644 --- a/OF DL/Entities/Config.cs +++ b/OF DL/Entities/Config.cs @@ -53,6 +53,7 @@ public class Config public bool ShowScrapeSize { get; set; } = true; public bool DownloadPostsIncrementally { get; set; } = false; + public string? FFmpegPath { get; set; } = string.Empty; } } diff --git a/OF DL/Helpers/DownloadHelper.cs b/OF DL/Helpers/DownloadHelper.cs index 94c55085..c4940c60 100644 --- a/OF DL/Helpers/DownloadHelper.cs +++ b/OF DL/Helpers/DownloadHelper.cs @@ -579,7 +579,7 @@ public async Task CalculateTotalFileSize(List urls, Auth auth) #region drm common - private static async Task DownloadDrmMedia(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string customFileName, string filename, string path, bool showScrapeSize) + private static async Task DownloadDrmMedia(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string customFileName, string filename, string path, bool showScrapeSize, Config config) { int pos1 = decryptionKey.IndexOf(':'); string decKey = ""; @@ -592,7 +592,7 @@ private static async Task DownloadDrmMedia(string ffmpegpath, string user_ ProcessStartInfo ffmpegStartInfo = new() { - FileName = ffmpegpath, + FileName = config.FFmpegPath, Arguments = $"-cenc_decryption_key {decKey} -headers \"Cookie:CloudFront-Policy={policy}; CloudFront-Signature={signature}; CloudFront-Key-Pair-Id={kvp}; {sess}\r\nOrigin: https://onlyfans.com\r\nReferer: https://onlyfans.com\r\nUser-Agent: {user_agent}\r\n\r\n\" -i \"{url}\" -codec copy \"{tempFilename}\"", CreateNoWindow = true, UseShellExecute = false, @@ -882,7 +882,7 @@ public async Task DownloadAvatarHeader(string? avatarUrl, string? headerUrl, str } #region drm posts - public async Task DownloadMessageDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Messages.List messageInfo, Messages.Medium messageMedia, Messages.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize) + public async Task DownloadMessageDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Messages.List messageInfo, Messages.Medium messageMedia, Messages.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize) { try { @@ -921,7 +921,7 @@ public async Task DownloadMessageDRMVideo(string ffmpegpath, string user_a { if (!string.IsNullOrEmpty(customFileName) ? !File.Exists(folder + path + "/" + customFileName + ".mp4") : !File.Exists(folder + path + "/" + filename + "_source.mp4")) { - return await DownloadDrmMedia(ffmpegpath, user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize); + return await DownloadDrmMedia(user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize, config); } else { @@ -966,7 +966,7 @@ public async Task DownloadMessageDRMVideo(string ffmpegpath, string user_a } - public async Task DownloadPurchasedMessageDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Purchased.List messageInfo, Purchased.Medium messageMedia, Purchased.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize) + public async Task DownloadPurchasedMessageDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Purchased.List messageInfo, Purchased.Medium messageMedia, Purchased.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize) { try { @@ -1004,7 +1004,7 @@ public async Task DownloadPurchasedMessageDRMVideo(string ffmpegpath, stri { if (!string.IsNullOrEmpty(customFileName) ? !File.Exists(folder + path + "/" + customFileName + ".mp4") : !File.Exists(folder + path + "/" + filename + "_source.mp4")) { - return await DownloadDrmMedia(ffmpegpath, user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize); + return await DownloadDrmMedia(user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize, config); } else { @@ -1049,7 +1049,7 @@ public async Task DownloadPurchasedMessageDRMVideo(string ffmpegpath, stri } - public async Task DownloadPostDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Post.List postInfo, Post.Medium postMedia, Post.Author author, Dictionary users, Config config, bool showScrapeSize) + public async Task DownloadPostDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Post.List postInfo, Post.Medium postMedia, Post.Author author, Dictionary users, Config config, bool showScrapeSize) { try { @@ -1087,7 +1087,7 @@ public async Task DownloadPostDRMVideo(string ffmpegpath, string user_agen { if (!string.IsNullOrEmpty(customFileName) ? !File.Exists(folder + path + "/" + customFileName + ".mp4") : !File.Exists(folder + path + "/" + filename + "_source.mp4")) { - return await DownloadDrmMedia(ffmpegpath, user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize); + return await DownloadDrmMedia(user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize, config); } else { @@ -1130,7 +1130,7 @@ public async Task DownloadPostDRMVideo(string ffmpegpath, string user_agen } return false; } - public async Task DownloadPostDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, SinglePost postInfo, SinglePost.Medium postMedia, SinglePost.Author author, Dictionary users, Config config, bool showScrapeSize) + public async Task DownloadPostDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, SinglePost postInfo, SinglePost.Medium postMedia, SinglePost.Author author, Dictionary users, Config config, bool showScrapeSize) { try { @@ -1168,7 +1168,7 @@ public async Task DownloadPostDRMVideo(string ffmpegpath, string user_agen { if (!string.IsNullOrEmpty(customFileName) ? !File.Exists(folder + path + "/" + customFileName + ".mp4") : !File.Exists(folder + path + "/" + filename + "_source.mp4")) { - return await DownloadDrmMedia(ffmpegpath, user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize); + return await DownloadDrmMedia(user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize, config); } else { @@ -1211,7 +1211,7 @@ public async Task DownloadPostDRMVideo(string ffmpegpath, string user_agen } return false; } - public async Task DownloadStreamsDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Streams.List streamInfo, Streams.Medium streamMedia, Streams.Author author, Dictionary users, Config config, bool showScrapeSize) + public async Task DownloadStreamsDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Streams.List streamInfo, Streams.Medium streamMedia, Streams.Author author, Dictionary users, Config config, bool showScrapeSize) { try { @@ -1249,7 +1249,7 @@ public async Task DownloadStreamsDRMVideo(string ffmpegpath, string user_a { if (!string.IsNullOrEmpty(customFileName) ? !File.Exists(folder + path + "/" + customFileName + ".mp4") : !File.Exists(folder + path + "/" + filename + "_source.mp4")) { - return await DownloadDrmMedia(ffmpegpath, user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize); + return await DownloadDrmMedia(user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize, config); } else { @@ -1293,7 +1293,7 @@ public async Task DownloadStreamsDRMVideo(string ffmpegpath, string user_a return false; } - public async Task DownloadPurchasedPostDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Purchased.List postInfo, Purchased.Medium postMedia, Purchased.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize) + public async Task DownloadPurchasedPostDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Purchased.List postInfo, Purchased.Medium postMedia, Purchased.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize) { try { @@ -1332,7 +1332,7 @@ public async Task DownloadPurchasedPostDRMVideo(string ffmpegpath, string { if (!string.IsNullOrEmpty(customFileName) ? !File.Exists(folder + path + "/" + customFileName + ".mp4") : !File.Exists(folder + path + "/" + filename + "_source.mp4")) { - return await DownloadDrmMedia(ffmpegpath, user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize); + return await DownloadDrmMedia(user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize, config); } else { @@ -1377,7 +1377,7 @@ public async Task DownloadPurchasedPostDRMVideo(string ffmpegpath, string } - public async Task DownloadArchivedPostDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Archived.List postInfo, Archived.Medium postMedia, Archived.Author author, Dictionary users, Config config, bool showScrapeSize) + public async Task DownloadArchivedPostDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Archived.List postInfo, Archived.Medium postMedia, Archived.Author author, Dictionary users, Config config, bool showScrapeSize) { try { @@ -1407,7 +1407,7 @@ public async Task DownloadArchivedPostDRMVideo(string ffmpegpath, string u { if (!string.IsNullOrEmpty(customFileName) ? !File.Exists(folder + path + "/" + customFileName + ".mp4") : !File.Exists(folder + path + "/" + filename + "_source.mp4")) { - return await DownloadDrmMedia(ffmpegpath, user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize); + return await DownloadDrmMedia(user_agent, policy, signature, kvp, sess, url, decryptionKey, folder, lastModified, media_id, task, customFileName, filename, path, showScrapeSize, config); } else { diff --git a/OF DL/Helpers/Interfaces/IDownloadHelper.cs b/OF DL/Helpers/Interfaces/IDownloadHelper.cs index 3574003f..5d75d149 100644 --- a/OF DL/Helpers/Interfaces/IDownloadHelper.cs +++ b/OF DL/Helpers/Interfaces/IDownloadHelper.cs @@ -12,20 +12,20 @@ public interface IDownloadHelper { Task CalculateTotalFileSize(List urls, Auth auth); Task DownloadArchivedMedia(string url, string folder, long media_id, ProgressTask task, string filenameFormat, Archived.List messageInfo, Archived.Medium messageMedia, Archived.Author author, Dictionary users, Config config, bool showScrapeSize); - Task DownloadArchivedPostDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Archived.List postInfo, Archived.Medium postMedia, Archived.Author author, Dictionary users, Config config, bool showScrapeSize); - Task DownloadPostDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, SinglePost postInfo, SinglePost.Medium postMedia, SinglePost.Author author, Dictionary users, Config config, bool showScrapeSize); + Task DownloadArchivedPostDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Archived.List postInfo, Archived.Medium postMedia, Archived.Author author, Dictionary users, Config config, bool showScrapeSize); + Task DownloadPostDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, SinglePost postInfo, SinglePost.Medium postMedia, SinglePost.Author author, Dictionary users, Config config, bool showScrapeSize); Task DownloadAvatarHeader(string? avatarUrl, string? headerUrl, string folder, string username); - Task DownloadMessageDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Messages.List messageInfo, Messages.Medium messageMedia, Messages.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize); + Task DownloadMessageDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Messages.List messageInfo, Messages.Medium messageMedia, Messages.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize); Task DownloadMessageMedia(string url, string folder, long media_id, ProgressTask task, string filenameFormat, Messages.List messageInfo, Messages.Medium messageMedia, Messages.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize); - Task DownloadPostDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Post.List postInfo, Post.Medium postMedia, Post.Author author, Dictionary users, Config config, bool showScrapeSize); + Task DownloadPostDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Post.List postInfo, Post.Medium postMedia, Post.Author author, Dictionary users, Config config, bool showScrapeSize); Task DownloadPostMedia(string url, string folder, long media_id, ProgressTask task, string? filenameFormat, Post.List? postInfo, Post.Medium? postMedia, Post.Author? author, Dictionary users, Config config, bool showScrapeSize); Task DownloadPostMedia(string url, string folder, long media_id, ProgressTask task, string? filenameFormat, SinglePost? postInfo, SinglePost.Medium? postMedia, SinglePost.Author? author, Dictionary users, Config config, bool showScrapeSize); Task DownloadPurchasedMedia(string url, string folder, long media_id, ProgressTask task, string filenameFormat, Purchased.List messageInfo, Purchased.Medium messageMedia, Purchased.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize); - Task DownloadPurchasedMessageDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Purchased.List messageInfo, Purchased.Medium messageMedia, Purchased.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize); - Task DownloadPurchasedPostDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Purchased.List postInfo, Purchased.Medium postMedia, Purchased.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize); + Task DownloadPurchasedMessageDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Purchased.List messageInfo, Purchased.Medium messageMedia, Purchased.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize); + Task DownloadPurchasedPostDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Purchased.List postInfo, Purchased.Medium postMedia, Purchased.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize); Task DownloadPurchasedPostMedia(string url, string folder, long media_id, ProgressTask task, string filenameFormat, Purchased.List messageInfo, Purchased.Medium messageMedia, Purchased.FromUser fromUser, Dictionary users, Config config, bool showScrapeSize); Task DownloadStoryMedia(string url, string folder, long media_id, ProgressTask task, Config config, bool showScrapeSize); Task DownloadStreamMedia(string url, string folder, long media_id, ProgressTask task, string? filenameFormat, Streams.List? streamInfo, Streams.Medium? streamMedia, Streams.Author? author, Dictionary users, Config config, bool showScrapeSize); - Task DownloadStreamsDRMVideo(string ffmpegpath, string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Streams.List streamInfo, Streams.Medium streamMedia, Streams.Author author, Dictionary users, Config config, bool showScrapeSize); + Task DownloadStreamsDRMVideo(string user_agent, string policy, string signature, string kvp, string sess, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, ProgressTask task, string filenameFormat, Streams.List streamInfo, Streams.Medium streamMedia, Streams.Author author, Dictionary users, Config config, bool showScrapeSize); } } diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 9403960f..9b6a42ff 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -46,7 +46,7 @@ public async static Task Main() .WriteTo.File("logs/OFDL.txt", rollingInterval: RollingInterval.Day) .CreateLogger(); - + AnsiConsole.Write(new FigletText("Welcome to OF-DL").Color(Color.Red)); if (File.Exists("auth.json")) @@ -74,15 +74,50 @@ public async static Task Main() Console.ReadKey(); Environment.Exit(0); } - - if (ValidateFilePath(Auth.FFMPEG_PATH)) + + var ffmpegFound = false; + if (!string.IsNullOrEmpty(Config!.FFmpegPath) && ValidateFilePath(Config.FFmpegPath)) + { + // FFmpeg path is set in config.json and is valid + ffmpegFound = true; + } + 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) + ffmpegFound = true; + Config.FFmpegPath = Auth.FFMPEG_PATH; + } + else if (string.IsNullOrEmpty(Config!.FFmpegPath)) + { + // FFmpeg path is not set in config.json, so we will try to locate it in the PATH or current directory + var ffmpegPath = GetFullPath("ffmpeg"); + if (ffmpegPath != null) + { + // FFmpeg is found in the PATH or current directory + ffmpegFound = true; + Config.FFmpegPath = ffmpegPath; + } + else + { + // FFmpeg is not found in the PATH or current directory, so we will try to locate the windows executable + ffmpegPath = GetFullPath("ffmpeg.exe"); + if (ffmpegPath != null) + { + // FFmpeg windows executable is found in the PATH or current directory + ffmpegFound = true; + Config.FFmpegPath = ffmpegPath; + } + } + } + + if (ffmpegFound) { - AnsiConsole.Markup($"[green]ffmpeg.exe located successfully![/]\n"); - } + AnsiConsole.Markup($"[green]FFmpeg located successfully ({Config.FFmpegPath})\n[/]"); + } else { - AnsiConsole.Markup($"[red]Cannot locate ffmpeg.exe; please modify auth.json with the correct path. Press any key to exit.[/]\n"); - Log.Error($"Cannot locate ffmpeg.exe with path {Auth.FFMPEG_PATH}"); + 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}"); Console.ReadKey(); Environment.Exit(0); } @@ -382,13 +417,12 @@ await AnsiConsole.Progress() { decryptionKey = await m_ApiHelper.GetDecryptionKeyNew(drmHeaders, $"https://onlyfans.com/api2/v2/users/media/{mediaId}/drm/message/{messageId}?type=widevine", pssh, Auth); } - + Purchased.Medium? mediaInfo = paidMessageCollection.PaidMessageMedia.FirstOrDefault(m => m.id == paidMessageKVP.Key); Purchased.List? messageInfo = paidMessageCollection.PaidMessageObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); isNew = await m_DownloadHelper.DownloadPurchasedMessageDRMVideo( - ffmpegpath: Auth.FFMPEG_PATH, user_agent: Auth.USER_AGENT, policy: policy, signature: signature, @@ -516,7 +550,6 @@ await AnsiConsole.Progress() Messages.List? messageInfo = messages.MessageObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); isNew = await m_DownloadHelper.DownloadMessageDRMVideo( - ffmpegpath: Auth.FFMPEG_PATH, user_agent: Auth.USER_AGENT, policy: policy, signature: signature, @@ -748,7 +781,6 @@ await AnsiConsole.Progress() Archived.List? postInfo = archived.ArchivedPostObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); isNew = await m_DownloadHelper.DownloadArchivedPostDRMVideo( - ffmpegpath: Auth.FFMPEG_PATH, user_agent: Auth.USER_AGENT, policy: policy, signature: signature, @@ -830,7 +862,7 @@ private static async Task DownloadFreePosts(KeyValuePair p?.media?.Contains(mediaInfo) == true); isNew = await m_DownloadHelper.DownloadPostDRMVideo( - ffmpegpath: Auth.FFMPEG_PATH, user_agent: Auth.USER_AGENT, policy: policy, signature: signature, @@ -1018,7 +1049,6 @@ await AnsiConsole.Progress() Purchased.List? postInfo = purchasedPosts.PaidPostObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); isNew = await m_DownloadHelper.DownloadPurchasedPostDRMVideo( - ffmpegpath: Auth.FFMPEG_PATH, user_agent: Auth.USER_AGENT, policy: policy, signature: signature, @@ -1144,7 +1174,6 @@ await AnsiConsole.Progress() Streams.List streamInfo = streams.StreamObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); isNew = await m_DownloadHelper.DownloadStreamsDRMVideo( - ffmpegpath: Auth.FFMPEG_PATH, user_agent: Auth.USER_AGENT, policy: policy, signature: signature, @@ -1274,7 +1303,6 @@ await AnsiConsole.Progress() SinglePost postInfo = post.SinglePostObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); isNew = await m_DownloadHelper.DownloadPostDRMVideo( - ffmpegpath: Auth.FFMPEG_PATH, user_agent: Auth.USER_AGENT, policy: policy, signature: signature, @@ -1344,7 +1372,7 @@ public static async Task>> HandleUser .Title("[red]Select Accounts to Scrape | Select All = All Accounts | List = Download content from users on List | Custom = Specific Account(s)[/]") .AddChoices(mainMenuOptions) ); - + switch (mainMenuSelection) { case "[red]Select All[/]": @@ -1551,7 +1579,7 @@ static bool ValidateFilePath(string path) { char[] invalidChars = System.IO.Path.GetInvalidPathChars(); char[] foundInvalidChars = path.Where(c => invalidChars.Contains(c)).ToArray(); - + if (foundInvalidChars.Any()) { AnsiConsole.Markup($"[red]Invalid characters found in path {path}:[/] {string.Join(", ", foundInvalidChars)}\n"); @@ -1592,4 +1620,23 @@ static ProgressColumn[] GetProgressColumns(bool showScrapeSize) } return progressColumns.ToArray(); } + + public static string? GetFullPath(string filename) + { + if (File.Exists(filename)) + { + return Path.GetFullPath(filename); + } + + var pathEnv = Environment.GetEnvironmentVariable("PATH") ?? string.Empty; + foreach (var path in pathEnv.Split(Path.PathSeparator)) + { + var fullPath = Path.Combine(path, filename); + if (File.Exists(fullPath)) + { + return fullPath; + } + } + return null; + } } diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index cd589e18..8aead8ba 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -8,8 +8,7 @@ if [ ! -f /config/auth.json ]; then "USER_ID": "", "USER_AGENT": "", "X_BC": "", - "COOKIE": "", - "FFMPEG_PATH": "/usr/bin/ffmpeg" + "COOKIE": "" } EOF fi @@ -48,7 +47,8 @@ if [ ! -f /config/config.json ]; then "DownloadDateSelection": "after", "CustomDate": "", "ShowScrapeSize": false, - "DownloadPostsIncrementally": false + "DownloadPostsIncrementally": false, + "FFmpegPath": "/usr/bin/ffmpeg" } EOF fi From d68f1eec866794caf1d63a0fcd61072f6b75346b Mon Sep 17 00:00:00 2001 From: whimsical-c4lic0 Date: Sat, 17 Feb 2024 00:52:29 -0600 Subject: [PATCH 2/3] Remove unnecessary null-forgiving operators --- OF DL/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 9b6a42ff..c06961bb 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -81,13 +81,13 @@ public async static Task Main() // FFmpeg path is set in config.json and is valid ffmpegFound = true; } - else if (!string.IsNullOrEmpty(Auth!.FFMPEG_PATH) && ValidateFilePath(Auth!.FFMPEG_PATH)) + 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) ffmpegFound = true; Config.FFmpegPath = Auth.FFMPEG_PATH; } - else if (string.IsNullOrEmpty(Config!.FFmpegPath)) + else if (string.IsNullOrEmpty(Config.FFmpegPath)) { // FFmpeg path is not set in config.json, so we will try to locate it in the PATH or current directory var ffmpegPath = GetFullPath("ffmpeg"); From c63f119057ef2b60e083cabec631f5e6d0ab43c1 Mon Sep 17 00:00:00 2001 From: whimsical-c4lic0 Date: Sun, 18 Feb 2024 09:51:42 -0600 Subject: [PATCH 3/3] Improve console output to indicate when the FFmpeg path was auto-detected --- OF DL/Program.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/OF DL/Program.cs b/OF DL/Program.cs index c06961bb..1c1625f9 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -76,6 +76,7 @@ public async static Task Main() } var ffmpegFound = false; + var pathAutoDetected = false; if (!string.IsNullOrEmpty(Config!.FFmpegPath) && ValidateFilePath(Config.FFmpegPath)) { // FFmpeg path is set in config.json and is valid @@ -95,6 +96,7 @@ public async static Task Main() { // FFmpeg is found in the PATH or current directory ffmpegFound = true; + pathAutoDetected = true; Config.FFmpegPath = ffmpegPath; } else @@ -105,6 +107,7 @@ public async static Task Main() { // FFmpeg windows executable is found in the PATH or current directory ffmpegFound = true; + pathAutoDetected = true; Config.FFmpegPath = ffmpegPath; } } @@ -112,12 +115,19 @@ public async static Task Main() if (ffmpegFound) { - AnsiConsole.Markup($"[green]FFmpeg located successfully ({Config.FFmpegPath})\n[/]"); + if (pathAutoDetected) + { + AnsiConsole.Markup($"[green]FFmpeg located successfully. Path auto-detected: {Config.FFmpegPath}\n[/]"); + } + else + { + AnsiConsole.Markup($"[green]FFmpeg located successfully\n[/]"); + } } else { - 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}"); + 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}"); Console.ReadKey(); Environment.Exit(0); }