@@ -10,6 +10,101 @@ namespace SabreTools.RedumpLib.Web
1010 /// </summary>
1111 public static class Discs
1212 {
13+ /// <summary>
14+ /// List the disc IDs associated with a given discs query
15+ /// </summary>
16+ /// <param name="rc">RedumpClient for connectivity</param>
17+ /// <param name="query">Query string to attempt to search for</param>
18+ /// <param name="noSlash">Don't replace slashes with `-` in queries</param>
19+ /// <returns>All disc IDs for the given query, empty on error</returns>
20+ public static async Task < List < int > > ListDiscsResults ( this RedumpClient rc , string ? query , bool noSlash )
21+ {
22+ // If the query is invalid
23+ if ( string . IsNullOrEmpty ( query ) )
24+ return [ ] ;
25+
26+ List < int > ids = [ ] ;
27+
28+ // Strip quotes
29+ query = query ! . Trim ( '"' , '\' ' ) ;
30+
31+ // Special characters become dashes
32+ query = query . Replace ( ' ' , '-' ) ;
33+ query = query . Replace ( '\\ ' , '-' ) ;
34+ if ( ! noSlash )
35+ query = query . Replace ( '/' , '-' ) ;
36+
37+ // Lowercase is defined per language
38+ query = query . ToLowerInvariant ( ) ;
39+
40+ // Keep getting quicksearch pages until there are none left
41+ try
42+ {
43+ int pageNumber = 1 ;
44+ while ( true )
45+ {
46+ var pageIds = await rc . CheckSingleSitePage ( string . Format ( Constants . DiscsUrl , query , pageNumber ++ ) ) ;
47+ if ( pageIds is null )
48+ return [ ] ;
49+
50+ ids . AddRange ( pageIds ) ;
51+ if ( pageIds . Count <= 1 )
52+ break ;
53+ }
54+ }
55+ catch ( Exception ex )
56+ {
57+ Console . WriteLine ( $ "An exception occurred while trying to log in: { ex } ") ;
58+ return [ ] ;
59+ }
60+
61+ return ids ;
62+ }
63+
64+ /// <summary>
65+ /// Download the disc pages associated with a given discs query
66+ /// </summary>
67+ /// <param name="rc">RedumpClient for connectivity</param>
68+ /// <param name="query">Query string to attempt to search for</param>
69+ /// <param name="outDir">Output directory to save data to</param>
70+ /// <param name="noSlash">Don't replace slashes with `-` in queries</param>
71+ /// <returns>All disc IDs for the given query, empty on error</returns>
72+ public static async Task < List < int > > DownloadDiscsResults ( this RedumpClient rc , string ? query , string ? outDir , bool noSlash )
73+ {
74+ List < int > ids = [ ] ;
75+
76+ // If the query is invalid
77+ if ( string . IsNullOrEmpty ( query ) )
78+ return ids ;
79+
80+ // Strip quotes
81+ query = query ! . Trim ( '"' , '\' ' ) ;
82+
83+ // Special characters become dashes
84+ query = query . Replace ( ' ' , '-' ) ;
85+ query = query . Replace ( '\\ ' , '-' ) ;
86+ if ( ! noSlash )
87+ query = query . Replace ( '/' , '-' ) ;
88+
89+ // Lowercase is defined per language
90+ query = query . ToLowerInvariant ( ) ;
91+
92+ // Keep getting quicksearch pages until there are none left
93+ int pageNumber = 1 ;
94+ while ( true )
95+ {
96+ var pageIds = await rc . CheckSingleSitePage ( string . Format ( Constants . DiscsUrl , query , pageNumber ++ ) , outDir , false ) ;
97+ if ( pageIds is null )
98+ return [ ] ;
99+
100+ ids . AddRange ( pageIds ) ;
101+ if ( pageIds . Count == 0 )
102+ break ;
103+ }
104+
105+ return ids ;
106+ }
107+
13108 /// <summary>
14109 /// Download the last modified disc pages, until first failure
15110 /// </summary>
0 commit comments