forked from sim0n00ps/OF-DL
Compare commits
3 Commits
319e98443a
...
44bb749c2d
Author | SHA1 | Date | |
---|---|---|---|
44bb749c2d | |||
cb107d11ea | |||
ed5f6ad6f7 |
@ -326,61 +326,49 @@ public class APIHelper : IAPIHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<Dictionary<string, int>?> GetAllSubscriptions(Dictionary<string, string> getParams, int limit, string endpoint, bool includeRestricted, IDownloadConfig config)
|
public async Task<Dictionary<string, int>?> GetAllSubscriptions(Dictionary<string, string> getParams, string endpoint, bool includeRestricted, IDownloadConfig config)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Dictionary<string, int> users = new();
|
Dictionary<string, int> users = new();
|
||||||
Subscriptions subscriptions = new();
|
|
||||||
|
|
||||||
|
int limit = 25;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
|
getParams["limit"] = limit.ToString();
|
||||||
getParams["offset"] = offset.ToString();
|
getParams["offset"] = offset.ToString();
|
||||||
|
|
||||||
Log.Debug("Calling GetAllSubscrptions");
|
Log.Debug("Calling GetAllSubscrptions");
|
||||||
|
|
||||||
string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, httpClient);
|
while (true)
|
||||||
|
|
||||||
subscriptions = JsonConvert.DeserializeObject<Subscriptions>(body);
|
|
||||||
if (subscriptions != null && subscriptions.hasMore)
|
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!subscriptions.hasMore)
|
||||||
|
break;
|
||||||
|
|
||||||
offset += limit;
|
offset += limit;
|
||||||
getParams["offset"] = offset.ToString();
|
getParams["offset"] = offset.ToString();
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
Subscriptions newSubscriptions = new();
|
|
||||||
string? loopbody = await BuildHeaderAndExecuteRequests(getParams, endpoint, httpClient);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(loopbody) && (!loopbody.Contains("[]") || loopbody.Trim() != "[]"))
|
|
||||||
{
|
|
||||||
newSubscriptions = JsonConvert.DeserializeObject<Subscriptions>(loopbody, m_JsonSerializerSettings);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
subscriptions.list.AddRange(newSubscriptions.list);
|
|
||||||
if (!newSubscriptions.hasMore)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
offset += limit;
|
|
||||||
getParams["offset"] = offset.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Subscriptions.List subscription in subscriptions.list)
|
|
||||||
{
|
|
||||||
if (users.ContainsKey(subscription.username))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
bool isRestricted = subscription.isRestricted ?? false;
|
|
||||||
bool isRestrictedButAllowed = isRestricted && includeRestricted;
|
|
||||||
|
|
||||||
if (!isRestricted || isRestrictedButAllowed)
|
|
||||||
users.Add(subscription.username, subscription.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return users;
|
return users;
|
||||||
@ -401,10 +389,8 @@ public class APIHelper : IAPIHelper
|
|||||||
|
|
||||||
public async Task<Dictionary<string, int>?> GetActiveSubscriptions(string endpoint, bool includeRestricted, IDownloadConfig config)
|
public async Task<Dictionary<string, int>?> GetActiveSubscriptions(string endpoint, bool includeRestricted, IDownloadConfig config)
|
||||||
{
|
{
|
||||||
int limit = 50;
|
|
||||||
Dictionary<string, string> getParams = new()
|
Dictionary<string, string> getParams = new()
|
||||||
{
|
{
|
||||||
{ "limit", $"{limit}" },
|
|
||||||
{ "type", "active" },
|
{ "type", "active" },
|
||||||
{ "format", "infinite"}
|
{ "format", "infinite"}
|
||||||
};
|
};
|
||||||
@ -412,16 +398,14 @@ public class APIHelper : IAPIHelper
|
|||||||
Log.Debug("Calling GetActiveSubscriptions");
|
Log.Debug("Calling GetActiveSubscriptions");
|
||||||
AnsiConsole.Markup($"[red]Getting Active Subscriptions (Include Restricted: {includeRestricted})\n[/]");
|
AnsiConsole.Markup($"[red]Getting Active Subscriptions (Include Restricted: {includeRestricted})\n[/]");
|
||||||
|
|
||||||
return await GetAllSubscriptions(getParams, limit, endpoint, includeRestricted, config);
|
return await GetAllSubscriptions(getParams, endpoint, includeRestricted, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<Dictionary<string, int>?> GetExpiredSubscriptions(string endpoint, bool includeRestricted, IDownloadConfig config)
|
public async Task<Dictionary<string, int>?> GetExpiredSubscriptions(string endpoint, bool includeRestricted, IDownloadConfig config)
|
||||||
{
|
{
|
||||||
int limit = 50;
|
|
||||||
Dictionary<string, string> getParams = new()
|
Dictionary<string, string> getParams = new()
|
||||||
{
|
{
|
||||||
{ "limit", $"{limit}" },
|
|
||||||
{ "type", "expired" },
|
{ "type", "expired" },
|
||||||
{ "format", "infinite"}
|
{ "format", "infinite"}
|
||||||
};
|
};
|
||||||
@ -429,15 +413,13 @@ public class APIHelper : IAPIHelper
|
|||||||
Log.Debug("Calling GetExpiredSubscriptions");
|
Log.Debug("Calling GetExpiredSubscriptions");
|
||||||
AnsiConsole.Markup($"[red]Getting Expired Subscriptions (Include Restricted: {includeRestricted})\n[/]");
|
AnsiConsole.Markup($"[red]Getting Expired Subscriptions (Include Restricted: {includeRestricted})\n[/]");
|
||||||
|
|
||||||
return await GetAllSubscriptions(getParams, limit, endpoint, includeRestricted, config);
|
return await GetAllSubscriptions(getParams, endpoint, includeRestricted, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Dictionary<string, int>?> GetBlockedUsers(string endpoint, IDownloadConfig config)
|
public async Task<Dictionary<string, int>?> GetBlockedUsers(string endpoint, IDownloadConfig config)
|
||||||
{
|
{
|
||||||
int limit = 50;
|
|
||||||
Dictionary<string, string> getParams = new()
|
Dictionary<string, string> getParams = new()
|
||||||
{
|
{
|
||||||
{ "limit", $"{limit}" },
|
|
||||||
{ "type", "expired" },
|
{ "type", "expired" },
|
||||||
{ "format", "infinite"}
|
{ "format", "infinite"}
|
||||||
};
|
};
|
||||||
@ -445,7 +427,7 @@ public class APIHelper : IAPIHelper
|
|||||||
Log.Debug("Calling GetBlockedUsers");
|
Log.Debug("Calling GetBlockedUsers");
|
||||||
AnsiConsole.Markup($"[red]Getting Blocked Users\n[/]");
|
AnsiConsole.Markup($"[red]Getting Blocked Users\n[/]");
|
||||||
|
|
||||||
return await GetAllSubscriptions(getParams, limit, endpoint, true, config);
|
return await GetAllSubscriptions(getParams, endpoint, true, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Dictionary<string, int>> GetLists(string endpoint, IDownloadConfig config)
|
public async Task<Dictionary<string, int>> GetLists(string endpoint, IDownloadConfig config)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user