Reduce need for last modified variants

This commit is contained in:
Matt Nadareski
2026-03-02 21:41:52 -05:00
parent ac0a19e536
commit 5d1b705b61
3 changed files with 7 additions and 65 deletions

View File

@@ -90,9 +90,9 @@ namespace RedumpTool.Features
if (onlyList)
processingTask = _client.ListUser(username, limit);
else if (onlyNew)
processingTask = _client.DownloadUserLastModified(username, outDir, limit);
processingTask = _client.DownloadUser(username, outDir, lastModified: true, limit: limit);
else
processingTask = _client.DownloadUser(username, outDir, limit);
processingTask = _client.DownloadUser(username, outDir, lastModified: false, limit: limit);
// Retrieve the result
processingTask.Wait();

View File

@@ -575,29 +575,6 @@ namespace SabreTools.RedumpLib.Web
return await CheckSingleSitePage(url, outDir);
}
/// <summary>
/// Process a Redump discs by last modified page as a list of possible IDs or disc page
/// </summary>
/// <param name="pageNumber">Page number to use</param>
/// <returns>List of IDs from the page, empty on none, null on error</returns>
public async Task<List<int>?> CheckSingleDiscsLastModifiedPage(int pageNumber)
{
string url = UrlBuilder.BuildDiscsUrl(sort: SortCategory.Modified, sortDir: SortDirection.Descending, page: pageNumber);
return await CheckSingleSitePage(url);
}
/// <summary>
/// Process a Redump discs by last modified page as a list of possible IDs or disc page
/// </summary>
/// <param name="pageNumber">Page number to use</param>
/// <param name="outDir">Output directory to save data to</param>
/// <returns>List of IDs from the page, empty on none, null on error</returns>
public async Task<List<int>?> CheckSingleDiscsLastModifiedPage(int pageNumber, string? outDir)
{
string url = UrlBuilder.BuildDiscsUrl(sort: SortCategory.Modified, sortDir: SortDirection.Descending, page: pageNumber);
return await CheckSingleSitePage(url, outDir);
}
/// <summary>
/// Process a Redump quicksearch page as a list of possible IDs or disc page
/// </summary>

View File

@@ -16,11 +16,13 @@ namespace SabreTools.RedumpLib.Web
/// <param name="client">RedumpClient for connectivity</param>
/// <param name="username">Username to check discs for</param>
/// <param name="outDir">Output directory to save data to</param>
/// <param name="lastModified">True to sort by last modified descending, false for default sorting</param>
/// <param name="limit">Limit number of retrieved result pages, non-positive for unlimited</param>
/// <returns>All disc IDs for the given user, empty on error</returns>
public static async Task<List<int>> DownloadUser(this RedumpClient client,
string? username,
string? outDir,
bool lastModified = false,
int limit = -1)
{
List<int> ids = [];
@@ -37,46 +39,9 @@ namespace SabreTools.RedumpLib.Web
if (limit > 0 && pageNumber >= limit)
break;
var pageIds = await client.CheckSingleDiscsPage(outDir, dumper: username, page: pageNumber++);
if (pageIds is null)
return [];
ids.AddRange(pageIds);
if (pageIds.Count == 0)
break;
}
return ids;
}
/// <summary>
/// Download the last modified disc pages associated with the given user, until first failure
/// </summary>
/// <param name="client">RedumpClient for connectivity</param>
/// <param name="username">Username to check discs for</param>
/// <param name="outDir">Output directory to save data to</param>
/// <param name="limit">Limit number of retrieved result pages, non-positive for unlimited</param>
/// <returns>All disc IDs for the given user, empty on error</returns>
public static async Task<List<int>> DownloadUserLastModified(this RedumpClient client,
string? username,
string? outDir,
int limit = -1)
{
List<int> ids = [];
if (string.IsNullOrEmpty(username))
{
Console.WriteLine("A username must be specified!");
return ids;
}
// Keep getting last modified user pages until there are none left
int pageNumber = 1;
while (true)
{
if (limit > 0 && pageNumber >= limit)
break;
var pageIds = await client.CheckSingleDiscsPage(outDir, dumper: username, sort: SortCategory.Modified, sortDir: SortDirection.Descending, page: pageNumber++);
var pageIds = lastModified
? await client.CheckSingleDiscsPage(outDir, dumper: username, sort: SortCategory.Modified, sortDir: SortDirection.Descending, page: pageNumber++)
: await client.CheckSingleDiscsPage(outDir, dumper: username, page: pageNumber++);
if (pageIds is null)
return [];