From c4c0e066de6ab1dbe7484039377cf5ae311f0771 Mon Sep 17 00:00:00 2001 From: whimsical-c4lic0 Date: Wed, 31 Jul 2024 17:30:44 -0500 Subject: [PATCH] Add support for an ignored users list --- OF DL/Entities/Config.cs | 3 ++ OF DL/Program.cs | 50 +++++++++++++++++++------------ docs/docs/config/configuration.md | 11 +++++++ 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/OF DL/Entities/Config.cs b/OF DL/Entities/Config.cs index 6f1db2a7..baf39f9f 100644 --- a/OF DL/Entities/Config.cs +++ b/OF DL/Entities/Config.cs @@ -89,6 +89,9 @@ public class Config : IDownloadConfig, IFileNameFormatConfig [ToggleableConfig] public bool DownloadDuplicatedMedia { get; set; } = false; + + public string IgnoredUsersListName { get; set; } = string.Empty; + [JsonConverter(typeof(StringEnumConverter))] public LoggingLevel LoggingLevel { get; set; } = LoggingLevel.Error; } diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 0761ddfb..87ac2350 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -388,8 +388,25 @@ private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Conf } } } - await dBHelper.CreateUsersDB(users); + Dictionary lists = await m_ApiHelper.GetLists("/lists", Config); + + // Remove users from the list if they are in the ignored list + if (!string.IsNullOrEmpty(Config.IgnoredUsersListName)) + { + if (!lists.TryGetValue(Config.IgnoredUsersListName, out var ignoredUsersListId)) + { + AnsiConsole.Markup($"[red]Ignored users list '{Config.IgnoredUsersListName}' not found\n[/]"); + Log.Error($"Ignored users list '{Config.IgnoredUsersListName}' not found"); + } + else + { + var ignoredUsernames = await m_ApiHelper.GetListUsers($"/lists/{ignoredUsersListId}/users", Config) ?? []; + users = users.Where(x => !ignoredUsernames.Contains(x.Key)).ToDictionary(x => x.Key, x => x.Value); + } + } + + await dBHelper.CreateUsersDB(users); KeyValuePair> hasSelectedUsersKVP; if(Config.NonInteractiveMode && Config.NonInteractiveModePurchasedTab) { @@ -401,14 +418,9 @@ private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Conf } else if (Config.NonInteractiveMode && !string.IsNullOrEmpty(Config.NonInteractiveModeListName)) { - List listUsernames = new(); - int listId = lists[Config.NonInteractiveModeListName]; - List usernames = await m_ApiHelper.GetListUsers($"/lists/{listId}/users", Config); - foreach (string user in usernames) - { - listUsernames.Add(user); - } - var selectedUsers = users.Where(x => listUsernames.Contains($"{x.Key}")).Distinct().ToDictionary(x => x.Key, x => x.Value); + var listId = lists[Config.NonInteractiveModeListName]; + var listUsernames = await m_ApiHelper.GetListUsers($"/lists/{listId}/users", Config) ?? []; + var selectedUsers = users.Where(x => listUsernames.Contains(x.Key)).Distinct().ToDictionary(x => x.Key, x => x.Value); hasSelectedUsersKVP = new KeyValuePair>(true, selectedUsers); } else @@ -456,9 +468,9 @@ private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Conf Log.Debug($"Download path: {path}"); - if (!Directory.Exists(path)) + if (!Directory.Exists(path)) { - Directory.CreateDirectory(path); + Directory.CreateDirectory(path); AnsiConsole.Markup($"[red]Created folder for {username}\n[/]"); Log.Debug($"Created folder for {username}"); } @@ -534,7 +546,7 @@ private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Conf } else { - path = $"__user_data__/sites/OnlyFans/{purchasedTabCollection.Username}"; + path = $"__user_data__/sites/OnlyFans/{purchasedTabCollection.Username}"; } @@ -603,14 +615,14 @@ private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Conf } else { - path = $"__user_data__/sites/OnlyFans/{username}"; + path = $"__user_data__/sites/OnlyFans/{username}"; } Log.Debug("Download path: ", path); - if (!Directory.Exists(path)) + if (!Directory.Exists(path)) { - Directory.CreateDirectory(path); + Directory.CreateDirectory(path); AnsiConsole.Markup($"[red]Created folder for {username}\n[/]"); Log.Debug($"Created folder for {username}"); } @@ -651,16 +663,16 @@ private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Conf } else { - path = $"__user_data__/sites/OnlyFans/{user.Key}"; + path = $"__user_data__/sites/OnlyFans/{user.Key}"; } Log.Debug("Download path: ", path); await dBHelper.CheckUsername(user, path); - if (!Directory.Exists(path)) + if (!Directory.Exists(path)) { - Directory.CreateDirectory(path); + Directory.CreateDirectory(path); AnsiConsole.Markup($"[red]Created folder for {user.Key}\n[/]"); Log.Debug($"Created folder for {user.Key}"); } @@ -1937,7 +1949,7 @@ private static async Task DownloadPaidMessage(IDownloadContext downloadCont Log.Debug($"Calling DownloadPaidMessage - {username}"); AnsiConsole.Markup($"[red]Getting Paid Message\n[/]"); - + PaidMessageCollection paidMessageCollection = await downloadContext.ApiHelper.GetPaidMessage($"/messages/{message_id.ToString()}", path, downloadContext.DownloadConfig!); int oldPaidMessagesCount = 0; int newPaidMessagesCount = 0; diff --git a/docs/docs/config/configuration.md b/docs/docs/config/configuration.md index 3ab38e10..f3664243 100644 --- a/docs/docs/config/configuration.md +++ b/docs/docs/config/configuration.md @@ -471,6 +471,17 @@ Allowed values: `true`, `false` Description: By default (or when set to `false`), the program will not download duplicated media. If set to `true`, duplicated media will be downloaded. +## IgnoredUsersListName + +Type: `string` + +Default: `""` + +Allowed values: The name of a list of users you have created on OnlyFans or `""` + +Description: When set to the name of a list, users in the list will be ignored when scraping content. +If set to `""` (or an invalid list name), no users will be ignored when scraping content. + ## LoggingLevel Type: `string`