Skip to content

Commit

Permalink
Merge pull request #503 from whimsical-c4lic0/feature/add-ignore-list…
Browse files Browse the repository at this point in the history
…-support

Add support for an ignored users list
  • Loading branch information
sim0n00ps authored Jul 31, 2024
2 parents 8fa2551 + c4c0e06 commit abea1e1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
3 changes: 3 additions & 0 deletions OF DL/Entities/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
50 changes: 31 additions & 19 deletions OF DL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,25 @@ private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Conf
}
}
}
await dBHelper.CreateUsersDB(users);

Dictionary<string, int> 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<bool, Dictionary<string, int>> hasSelectedUsersKVP;
if(Config.NonInteractiveMode && Config.NonInteractiveModePurchasedTab)
{
Expand All @@ -401,14 +418,9 @@ private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Conf
}
else if (Config.NonInteractiveMode && !string.IsNullOrEmpty(Config.NonInteractiveModeListName))
{
List<string> listUsernames = new();
int listId = lists[Config.NonInteractiveModeListName];
List<string> 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<bool, Dictionary<string, int>>(true, selectedUsers);
}
else
Expand Down Expand Up @@ -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}");
}
Expand Down Expand Up @@ -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}";
}


Expand Down Expand Up @@ -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}");
}
Expand Down Expand Up @@ -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}");
}
Expand Down Expand Up @@ -1937,7 +1949,7 @@ private static async Task<int> 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;
Expand Down
11 changes: 11 additions & 0 deletions docs/docs/config/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit abea1e1

Please sign in to comment.