@@ -185,73 +185,81 @@ impl ScreenScraperClient {
185185 pub async fn get_game_by_md5 (
186186 & self ,
187187 system_id : i32 ,
188+ rom_name : & str ,
189+ rom_size : Option < i64 > ,
188190 md5 : & str ,
189191 ) -> anyhow:: Result < Option < SsGame > > {
190- if !valid_system_id ( system_id) {
191- debug ! ( "screenscraper get_game_by_md5 skipped: invalid system_id ({system_id})" ) ;
192- return Ok ( None ) ;
193- }
194- let trimmed = md5. trim ( ) ;
195- if trimmed. is_empty ( ) {
196- debug ! ( "screenscraper get_game_by_md5 skipped: empty md5" ) ;
197- return Ok ( None ) ;
198- }
199- let url = self . url (
200- "jeuInfos.php" ,
201- & [
202- ( "systemeid" , system_id. to_string ( ) ) ,
203- ( "md5" , trimmed. to_string ( ) ) ,
204- ] ,
205- ) ?;
206- self . fetch_optional_game ( "game_by_md5" , url) . await
192+ self . get_game_by_hash ( "game_by_md5" , system_id, rom_name, rom_size, "md5" , md5)
193+ . await
207194 }
208195
209196 pub async fn get_game_by_sha1 (
210197 & self ,
211198 system_id : i32 ,
199+ rom_name : & str ,
200+ rom_size : Option < i64 > ,
212201 sha1 : & str ,
213202 ) -> anyhow:: Result < Option < SsGame > > {
214- if !valid_system_id ( system_id) {
215- debug ! ( "screenscraper get_game_by_sha1 skipped: invalid system_id ({system_id})" ) ;
216- return Ok ( None ) ;
217- }
218- let trimmed = sha1. trim ( ) ;
219- if trimmed. is_empty ( ) {
220- debug ! ( "screenscraper get_game_by_sha1 skipped: empty sha1" ) ;
221- return Ok ( None ) ;
222- }
223- let url = self . url (
224- "jeuInfos.php" ,
225- & [
226- ( "systemeid" , system_id. to_string ( ) ) ,
227- ( "sha1" , trimmed. to_string ( ) ) ,
228- ] ,
229- ) ?;
230- self . fetch_optional_game ( "game_by_sha1" , url) . await
203+ self . get_game_by_hash (
204+ "game_by_sha1" ,
205+ system_id,
206+ rom_name,
207+ rom_size,
208+ "sha1" ,
209+ sha1,
210+ )
211+ . await
231212 }
232213
233214 pub async fn get_game_by_crc (
234215 & self ,
235216 system_id : i32 ,
217+ rom_name : & str ,
218+ rom_size : Option < i64 > ,
236219 crc : & str ,
220+ ) -> anyhow:: Result < Option < SsGame > > {
221+ self . get_game_by_hash ( "game_by_crc" , system_id, rom_name, rom_size, "crc" , crc)
222+ . await
223+ }
224+
225+ /// `jeuInfos.php` hash lookups require `systemeid`, `romnom` and a hash;
226+ /// `romtaille` is optional but improves the hit rate. Calls without
227+ /// `romnom` come back as HTTP 400 "Il manque des champs obligatoires
228+ /// dans l'url", so guard for it here.
229+ async fn get_game_by_hash (
230+ & self ,
231+ endpoint_label : & ' static str ,
232+ system_id : i32 ,
233+ rom_name : & str ,
234+ rom_size : Option < i64 > ,
235+ hash_param : & ' static str ,
236+ hash_value : & str ,
237237 ) -> anyhow:: Result < Option < SsGame > > {
238238 if !valid_system_id ( system_id) {
239- debug ! ( "screenscraper get_game_by_crc skipped: invalid system_id ({system_id})" ) ;
239+ debug ! ( "screenscraper {endpoint_label} skipped: invalid system_id ({system_id})" ) ;
240240 return Ok ( None ) ;
241241 }
242- let trimmed = crc . trim ( ) ;
243- if trimmed . is_empty ( ) {
244- debug ! ( "screenscraper get_game_by_crc skipped: empty crc " ) ;
242+ let trimmed_hash = hash_value . trim ( ) ;
243+ if trimmed_hash . is_empty ( ) {
244+ debug ! ( "screenscraper {endpoint_label} skipped: empty {hash_param} " ) ;
245245 return Ok ( None ) ;
246246 }
247- let url = self . url (
248- "jeuInfos.php" ,
249- & [
250- ( "systemeid" , system_id. to_string ( ) ) ,
251- ( "crc" , trimmed. to_string ( ) ) ,
252- ] ,
253- ) ?;
254- self . fetch_optional_game ( "game_by_crc" , url) . await
247+ let trimmed_name = rom_name. trim ( ) ;
248+ if trimmed_name. is_empty ( ) {
249+ debug ! ( "screenscraper {endpoint_label} skipped: empty rom_name" ) ;
250+ return Ok ( None ) ;
251+ }
252+ let mut params: Vec < ( & ' static str , String ) > = vec ! [
253+ ( "systemeid" , system_id. to_string( ) ) ,
254+ ( "romtype" , "rom" . to_string( ) ) ,
255+ ( "romnom" , trimmed_name. to_string( ) ) ,
256+ ( hash_param, trimmed_hash. to_string( ) ) ,
257+ ] ;
258+ if let Some ( size) = rom_size. filter ( |s| * s > 0 ) {
259+ params. push ( ( "romtaille" , size. to_string ( ) ) ) ;
260+ }
261+ let url = self . url ( "jeuInfos.php" , & params) ?;
262+ self . fetch_optional_game ( endpoint_label, url) . await
255263 }
256264
257265 async fn fetch_optional_game (
0 commit comments