mirror of
https://github.com/SabreTools/SabreTools.RedumpLib.git
synced 2026-09-22 15:04:34 +00:00
Reorder methods to match other extension classes
This commit is contained in:
@@ -9,54 +9,6 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// </summary>
|
||||
public static class Search
|
||||
{
|
||||
/// <summary>
|
||||
/// List the disc IDs associated with a given quicksearch query
|
||||
/// </summary>
|
||||
/// <param name="client">RedumpClient for connectivity</param>
|
||||
/// <param name="query">Query string to attempt to search for</param>
|
||||
/// <param name="convertForwardSlashes">Replace forward slashes with `-` in queries</param>
|
||||
/// <param name="limit">Limit number of retrieved result pages, non-positive for unlimited</param>
|
||||
/// <returns>All disc IDs for the given query, empty on error</returns>
|
||||
public static async Task<List<int>> ListSearchResults(this RedumpClient client,
|
||||
string? query,
|
||||
bool convertForwardSlashes,
|
||||
int limit = -1)
|
||||
{
|
||||
// If the query is invalid
|
||||
if (string.IsNullOrEmpty(query))
|
||||
return [];
|
||||
|
||||
// Keep getting quicksearch pages until there are none left
|
||||
List<int> ids = [];
|
||||
try
|
||||
{
|
||||
int pageNumber = 1;
|
||||
while (true)
|
||||
{
|
||||
if (limit > 0 && pageNumber >= limit)
|
||||
break;
|
||||
|
||||
// Convert forward slashes implies a strict query
|
||||
var pageIds = convertForwardSlashes
|
||||
? await client.CheckSingleDiscsPage(quicksearch: query, page: pageNumber++)
|
||||
: await client.CheckSingleQuicksearchPage(query!, pageNumber++);
|
||||
if (pageIds is null)
|
||||
return [];
|
||||
|
||||
ids.AddRange(pageIds);
|
||||
if (pageIds.Count <= 1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"An exception occurred while trying to log in: {ex}");
|
||||
return [];
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download the disc pages associated with a given quicksearch query
|
||||
/// </summary>
|
||||
@@ -106,5 +58,53 @@ namespace SabreTools.RedumpLib.Web
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List the disc IDs associated with a given quicksearch query
|
||||
/// </summary>
|
||||
/// <param name="client">RedumpClient for connectivity</param>
|
||||
/// <param name="query">Query string to attempt to search for</param>
|
||||
/// <param name="convertForwardSlashes">Replace forward slashes with `-` in queries</param>
|
||||
/// <param name="limit">Limit number of retrieved result pages, non-positive for unlimited</param>
|
||||
/// <returns>All disc IDs for the given query, empty on error</returns>
|
||||
public static async Task<List<int>> ListSearchResults(this RedumpClient client,
|
||||
string? query,
|
||||
bool convertForwardSlashes,
|
||||
int limit = -1)
|
||||
{
|
||||
// If the query is invalid
|
||||
if (string.IsNullOrEmpty(query))
|
||||
return [];
|
||||
|
||||
// Keep getting quicksearch pages until there are none left
|
||||
List<int> ids = [];
|
||||
try
|
||||
{
|
||||
int pageNumber = 1;
|
||||
while (true)
|
||||
{
|
||||
if (limit > 0 && pageNumber >= limit)
|
||||
break;
|
||||
|
||||
// Convert forward slashes implies a strict query
|
||||
var pageIds = convertForwardSlashes
|
||||
? await client.CheckSingleDiscsPage(quicksearch: query, page: pageNumber++)
|
||||
: await client.CheckSingleQuicksearchPage(query!, pageNumber++);
|
||||
if (pageIds is null)
|
||||
return [];
|
||||
|
||||
ids.AddRange(pageIds);
|
||||
if (pageIds.Count <= 1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"An exception occurred while trying to log in: {ex}");
|
||||
return [];
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user