diff --git a/OF DL/Entities/Config.cs b/OF DL/Entities/Config.cs index 5c0e067..3e4531e 100644 --- a/OF DL/Entities/Config.cs +++ b/OF DL/Entities/Config.cs @@ -52,6 +52,7 @@ public class Config public bool NonInteractiveMode { get; set; } = false; public string NonInteractiveModeListName { get; set; } = string.Empty; + public bool NonInteractiveModePurchasedTab { 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 7228c78..8a99529 100644 --- a/OF DL/Helpers/DownloadHelper.cs +++ b/OF DL/Helpers/DownloadHelper.cs @@ -150,6 +150,7 @@ private static async Task GenerateCustomFileName(string filename, object? postInfo, object? postMedia, object? author, + string username, Dictionary users, IFileNameHelper fileNameHelper, CustomFileNameOption option) @@ -169,7 +170,7 @@ private static async Task GenerateCustomFileName(string filename, MatchCollection matches = Regex.Matches(filenameFormat, pattern); properties.AddRange(matches.Select(match => match.Groups[1].Value)); - Dictionary values = await fileNameHelper.GetFilename(postInfo, postMedia, author, properties, users); + Dictionary values = await fileNameHelper.GetFilename(postInfo, postMedia, author, properties, username, users); return await fileNameHelper.BuildFilename(filenameFormat, values); } @@ -653,7 +654,7 @@ public async Task DownloadPostMedia(string url, string folder, long media_ Uri uri = new(url); string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath); - string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, postInfo, postMedia, author, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); + string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, postInfo, postMedia, author, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize); } @@ -671,7 +672,7 @@ public async Task DownloadPostMedia(string url, string folder, long media_ Uri uri = new(url); string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath); - string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, postInfo, postMedia, author, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); + string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, postInfo, postMedia, author, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize); } @@ -689,7 +690,7 @@ public async Task DownloadStreamMedia(string url, string folder, long medi Uri uri = new(url); string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath); - string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, streamInfo, streamMedia, author, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); + string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, streamInfo, streamMedia, author, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize); } @@ -708,7 +709,7 @@ public async Task DownloadMessageMedia(string url, string folder, long med } Uri uri = new(url); string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath); - string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, fromUser, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); + string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, fromUser, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize); } @@ -718,7 +719,7 @@ public async Task DownloadArchivedMedia(string url, string folder, long me string path = "/Archived/Posts/Free"; Uri uri = new(url); string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath); - string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, author, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); + string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, author, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize); } @@ -745,7 +746,7 @@ public async Task DownloadPurchasedMedia(string url, string folder, long m } Uri uri = new(url); string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath); - string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, fromUser, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); + string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, fromUser, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize); } @@ -772,7 +773,7 @@ public async Task DownloadPurchasedPostMedia(string url, } Uri uri = new(url); string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath); - string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, fromUser, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); + string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, fromUser, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal); return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize); } @@ -920,7 +921,7 @@ public async Task DownloadMessageDRMVideo(string user_agent, string policy { properties.Add(match.Groups[1].Value); } - Dictionary values = await _FileNameHelper.GetFilename(messageInfo, messageMedia, fromUser, properties, users); + Dictionary values = await _FileNameHelper.GetFilename(messageInfo, messageMedia, fromUser, properties, folder.Split("/")[^1],users); customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values); } @@ -1003,7 +1004,7 @@ public async Task DownloadPurchasedMessageDRMVideo(string user_agent, stri { properties.Add(match.Groups[1].Value); } - Dictionary values = await _FileNameHelper.GetFilename(messageInfo, messageMedia, fromUser, properties, users); + Dictionary values = await _FileNameHelper.GetFilename(messageInfo, messageMedia, fromUser, properties, folder.Split("/")[^1], users); customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values); } @@ -1086,7 +1087,7 @@ public async Task DownloadPostDRMVideo(string user_agent, string policy, s { properties.Add(match.Groups[1].Value); } - Dictionary values = await _FileNameHelper.GetFilename(postInfo, postMedia, author, properties, users); + Dictionary values = await _FileNameHelper.GetFilename(postInfo, postMedia, author, properties, folder.Split("/")[^1], users); customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values); } @@ -1167,7 +1168,7 @@ public async Task DownloadPostDRMVideo(string user_agent, string policy, s { properties.Add(match.Groups[1].Value); } - Dictionary values = await _FileNameHelper.GetFilename(postInfo, postMedia, author, properties, users); + Dictionary values = await _FileNameHelper.GetFilename(postInfo, postMedia, author, properties, folder.Split("/")[^1], users); customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values); } @@ -1248,7 +1249,7 @@ public async Task DownloadStreamsDRMVideo(string user_agent, string policy { properties.Add(match.Groups[1].Value); } - Dictionary values = await _FileNameHelper.GetFilename(streamInfo, streamMedia, author, properties, users); + Dictionary values = await _FileNameHelper.GetFilename(streamInfo, streamMedia, author, properties, folder.Split("/")[^1], users); customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values); } @@ -1331,7 +1332,7 @@ public async Task DownloadPurchasedPostDRMVideo(string user_agent, string { properties.Add(match.Groups[1].Value); } - Dictionary values = await _FileNameHelper.GetFilename(postInfo, postMedia, fromUser, properties, users); + Dictionary values = await _FileNameHelper.GetFilename(postInfo, postMedia, fromUser, properties, folder.Split("/")[^1], users); customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values); } @@ -1406,7 +1407,7 @@ public async Task DownloadArchivedPostDRMVideo(string user_agent, string p { properties.Add(match.Groups[1].Value); } - Dictionary values = await _FileNameHelper.GetFilename(postInfo, postMedia, author, properties, users); + Dictionary values = await _FileNameHelper.GetFilename(postInfo, postMedia, author, properties, folder.Split("/")[^1], users); customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values); } diff --git a/OF DL/Helpers/FileNameHelper.cs b/OF DL/Helpers/FileNameHelper.cs index 83328cd..4d64a3d 100644 --- a/OF DL/Helpers/FileNameHelper.cs +++ b/OF DL/Helpers/FileNameHelper.cs @@ -9,7 +9,7 @@ namespace OF_DL.Helpers { public class FileNameHelper : IFileNameHelper { - public async Task> GetFilename(object obj1, object obj2, object obj3, List selectedProperties, Dictionary users = null) + public async Task> GetFilename(object obj1, object obj2, object obj3, List selectedProperties, string username, Dictionary users = null) { Dictionary values = new(); Type type1 = obj1.GetType(); @@ -113,11 +113,18 @@ public async Task> GetFilename(object obj1, object ob } else if (propertyName.Contains("username")) { - string propertyPath = "id"; - object nestedPropertyValue = GetNestedPropertyValue(obj3, propertyPath); - if (nestedPropertyValue != null) + if(!string.IsNullOrEmpty(username)) { - values.Add(propertyName, users.FirstOrDefault(u => u.Value == Convert.ToInt32(nestedPropertyValue.ToString())).Key); + values.Add(propertyName, username); + } + else + { + string propertyPath = "id"; + object nestedPropertyValue = GetNestedPropertyValue(obj3, propertyPath); + if (nestedPropertyValue != null) + { + values.Add(propertyName, users.FirstOrDefault(u => u.Value == Convert.ToInt32(nestedPropertyValue.ToString())).Key); + } } } else if (propertyName.Contains("text", StringComparison.OrdinalIgnoreCase)) diff --git a/OF DL/Helpers/Interfaces/IFileNameHelper.cs b/OF DL/Helpers/Interfaces/IFileNameHelper.cs index 8b37759..aae3ba8 100644 --- a/OF DL/Helpers/Interfaces/IFileNameHelper.cs +++ b/OF DL/Helpers/Interfaces/IFileNameHelper.cs @@ -3,6 +3,6 @@ namespace OF_DL.Helpers public interface IFileNameHelper { Task BuildFilename(string fileFormat, Dictionary values); - Task> GetFilename(object obj1, object obj2, object obj3, List selectedProperties, Dictionary? users = null); + Task> GetFilename(object obj1, object obj2, object obj3, List selectedProperties, string username, Dictionary users = null); } } diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 4f67903..3a6594c 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -222,7 +222,11 @@ private static async Task DownloadAllData() Dictionary lists = await m_ApiHelper.GetLists("/lists", Auth); Dictionary selectedUsers = new(); KeyValuePair> hasSelectedUsersKVP; - if (Config.NonInteractiveMode && string.IsNullOrEmpty(Config.NonInteractiveModeListName)) + if(Config.NonInteractiveMode && Config.NonInteractiveModePurchasedTab) + { + hasSelectedUsersKVP = new KeyValuePair>(true, new Dictionary { { "PurchasedTab", 0 } }); + } + else if (Config.NonInteractiveMode && string.IsNullOrEmpty(Config.NonInteractiveModeListName)) { hasSelectedUsersKVP = new KeyValuePair>(true, users); } @@ -1837,12 +1841,13 @@ public static async Task>> HandleUser ( "[red]DownloadPostsBeforeOrAfterSpecificDate[/]", Config.DownloadOnlySpecificDates ), ( "[red]ShowScrapeSize[/]", Config.ShowScrapeSize), ( "[red]DownloadPostsIncrementally[/]", Config.DownloadPostsIncrementally), - ( "[red]NonInteractiveMode[/]", Config.NonInteractiveMode) + ( "[red]NonInteractiveMode[/]", Config.NonInteractiveMode), + ( "[red]NonInteractiveModePurchasedTab[/]", Config.NonInteractiveModePurchasedTab) }); MultiSelectionPrompt multiSelectionPrompt = new MultiSelectionPrompt() .Title("[red]Edit config.json[/]") - .PageSize(24); + .PageSize(25); foreach (var choice in choices) { @@ -1893,7 +1898,8 @@ public static async Task>> HandleUser DownloadOnlySpecificDates = configOptions.Contains("[red]DownloadPostsBeforeOrAfterSpecificDate[/]"), ShowScrapeSize = configOptions.Contains("[red]ShowScrapeSize[/]"), DownloadPostsIncrementally = configOptions.Contains("[red]DownloadPostsIncrementally[/]"), - NonInteractiveMode = configOptions.Contains("[red]NonInteractiveMode[/]") + NonInteractiveMode = configOptions.Contains("[red]NonInteractiveMode[/]"), + NonInteractiveModePurchasedTab = configOptions.Contains("[red]NonInteractiveModePurchasedTab[/]") };