forked from sim0n00ps/OF-DL
Compare commits
No commits in common. "1d587eeccb6d4eaf3ee8b2744b68084ce2e6471c" and "1c39b29d6584bd276845e73f99340b188372656e" have entirely different histories.
1d587eeccb
...
1c39b29d65
@ -414,85 +414,17 @@ public class APIHelper : IAPIHelper
|
|||||||
return await GetAllSubscriptions(getParams, endpoint, includeRestricted, config);
|
return await GetAllSubscriptions(getParams, endpoint, includeRestricted, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Dictionary<string, int>?> GetUsersWithProgress(string typeDisplay, string endpoint, StatusContext ctx, string? typeParam, bool offsetByCount)
|
public async Task<Dictionary<string, int>?> GetBlockedUsers(string endpoint, IDownloadConfig config)
|
||||||
{
|
{
|
||||||
int limit = 50;
|
|
||||||
int offset = 0;
|
|
||||||
bool includeRestricted = true;
|
|
||||||
|
|
||||||
Dictionary<string, string> getParams = new()
|
Dictionary<string, string> getParams = new()
|
||||||
{
|
{
|
||||||
["format"] = "infinite",
|
{ "type", "expired" },
|
||||||
["limit"] = limit.ToString(),
|
{ "format", "infinite"}
|
||||||
["offset"] = offset.ToString()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(typeParam))
|
Log.Debug("Calling GetBlockedUsers");
|
||||||
getParams["type"] = typeParam;
|
|
||||||
|
|
||||||
try
|
return await GetAllSubscriptions(getParams, endpoint, true, config);
|
||||||
{
|
|
||||||
Dictionary<string, int> users = [];
|
|
||||||
|
|
||||||
Log.Debug("Calling GetUsersWithProgress");
|
|
||||||
|
|
||||||
bool isLastLoop = false;
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, httpClient);
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(body))
|
|
||||||
break;
|
|
||||||
|
|
||||||
Subscriptions? subscriptions = JsonConvert.DeserializeObject<Subscriptions>(body, m_JsonSerializerSettings);
|
|
||||||
|
|
||||||
if (subscriptions?.list is null)
|
|
||||||
break;
|
|
||||||
|
|
||||||
foreach (Subscriptions.List item in subscriptions.list)
|
|
||||||
{
|
|
||||||
if (users.ContainsKey(item.username))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
bool isRestricted = item.isRestricted ?? false;
|
|
||||||
bool isRestrictedButAllowed = isRestricted && includeRestricted;
|
|
||||||
|
|
||||||
if (!isRestricted || isRestrictedButAllowed)
|
|
||||||
users.Add(item.username, item.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Status($"[red]Getting {typeDisplay} Users\n[/] [red]Found {users.Count}[/]");
|
|
||||||
ctx.Spinner(Spinner.Known.Dots);
|
|
||||||
ctx.SpinnerStyle(Style.Parse("blue"));
|
|
||||||
|
|
||||||
if (isLastLoop)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!subscriptions.hasMore || subscriptions.list.Count == 0)
|
|
||||||
isLastLoop = true;
|
|
||||||
|
|
||||||
offset += offsetByCount
|
|
||||||
? subscriptions.list.Count
|
|
||||||
: limit;
|
|
||||||
|
|
||||||
getParams["offset"] = offset.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return users;
|
|
||||||
}
|
|
||||||
catch (Exception 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Dictionary<string, int>> GetLists(string endpoint, IDownloadConfig config)
|
public async Task<Dictionary<string, int>> GetLists(string endpoint, IDownloadConfig config)
|
||||||
|
@ -857,7 +857,7 @@ public class Program
|
|||||||
{
|
{
|
||||||
if (config.OutputBlockedUsers)
|
if (config.OutputBlockedUsers)
|
||||||
{
|
{
|
||||||
await DownloadBlockedOrExpiredUsers(apiHelper, config);
|
await DownloadBlockedUsers(apiHelper, config);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -887,37 +887,21 @@ public class Program
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task DownloadBlockedOrExpiredUsers(APIHelper m_ApiHelper, Entities.Config Config)
|
private static async Task DownloadBlockedUsers(APIHelper m_ApiHelper, Entities.Config Config)
|
||||||
{
|
{
|
||||||
const string OUTPUT_FILE_BLOCKED = "blocked-users.json";
|
const string OUTPUT_FILE = "blocked-users.json";
|
||||||
const string OUTPUT_FILE_EXPIRED = "expired-users.json";
|
|
||||||
|
|
||||||
await GetUsers("Blocked", "/users/blocked", OUTPUT_FILE_BLOCKED);
|
Dictionary<string, int>? blockedUsers = await m_ApiHelper.GetBlockedUsers("/users/blocked", Config);
|
||||||
await GetUsers("Expired", "/subscriptions/subscribes", OUTPUT_FILE_EXPIRED, typeParam: "expired", offsetByCount: false);
|
|
||||||
|
|
||||||
async Task GetUsers(string typeDisplay, string uri, string outputFile, string? typeParam = null, bool offsetByCount = true)
|
if (blockedUsers is null || blockedUsers.Count == 0)
|
||||||
{
|
{
|
||||||
Dictionary<string, int>? users = null;
|
AnsiConsole.Markup($"[green]No Blocked Users found.\n[/]");
|
||||||
|
}
|
||||||
await AnsiConsole
|
else
|
||||||
.Status()
|
{
|
||||||
.StartAsync($"[red]Getting {typeDisplay} Users[/]", async ctx =>
|
AnsiConsole.Markup($"[green]Found {blockedUsers.Count} Blocked Users, saving to '{OUTPUT_FILE}'\n[/]");
|
||||||
{
|
string json = JsonConvert.SerializeObject(blockedUsers, Formatting.Indented);
|
||||||
users = await m_ApiHelper.GetUsersWithProgress(typeDisplay, uri, ctx, typeParam, offsetByCount);
|
await File.WriteAllTextAsync(OUTPUT_FILE, json);
|
||||||
});
|
|
||||||
|
|
||||||
Console.WriteLine();
|
|
||||||
|
|
||||||
if (users is null || users.Count == 0)
|
|
||||||
{
|
|
||||||
AnsiConsole.Markup($"[green]No {typeDisplay} Users found.\n[/]");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AnsiConsole.Markup($"[green]Found {users.Count} {typeDisplay} Users, saving to '{outputFile}'\n[/]");
|
|
||||||
string json = JsonConvert.SerializeObject(users, Formatting.Indented);
|
|
||||||
await File.WriteAllTextAsync(outputFile, json);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user