@@ -33,9 +33,7 @@ const devpassword = 'diFay35WElL';
33
33
const softname = 'EmuDeckROMLauncher' ;
34
34
35
35
app . commandLine . appendSwitch ( 'disk-cache-size' , '10737418240' ) ;
36
- if ( os . platform ( ) === 'linux' ) {
37
- app . commandLine . appendSwitch ( '--no-sandbox' ) ;
38
- }
36
+ app . commandLine . appendSwitch ( '--no-sandbox' ) ;
39
37
40
38
let theme ;
41
39
ipcMain . on ( 'get-theme' , async ( event , name ) => {
@@ -157,6 +155,7 @@ if (!fs.existsSync(dbPathLibrary)) {
157
155
"played" INTEGER DEFAULT 0,
158
156
"path" TEXT,
159
157
"databaseID" INTEGER,
158
+ "parsed" INTEGER,
160
159
"favourite" INTEGER DEFAULT 0,
161
160
PRIMARY KEY("id" AUTOINCREMENT),
162
161
UNIQUE("file_name")
@@ -905,13 +904,15 @@ const insertROM = (
905
904
results . forEach ( ( result ) => {
906
905
imageData . databaseID = result . DatabaseID ;
907
906
} ) ;
907
+ imageData . parsed = 1 ;
908
908
} else {
909
909
imageData . databaseID = 0 ;
910
+ imageData . parsed = 0 ;
910
911
}
911
912
912
913
const insertQuery = `
913
- INSERT OR REPLACE INTO roms (file_name, name, system, platform, path, databaseID)
914
- VALUES (?, ?, ?, ?, ?, ?)
914
+ INSERT OR REPLACE INTO roms (file_name, name, system, platform, path, databaseID, parsed )
915
+ VALUES (?, ?, ?, ?, ?, ?, ? )
915
916
` ;
916
917
917
918
// console.log({ imageData });
@@ -924,6 +925,7 @@ const insertROM = (
924
925
imageData . platform ,
925
926
imageData . gameFilePath ,
926
927
imageData . databaseID ,
928
+ imageData . parsed ,
927
929
] ,
928
930
function ( err ) {
929
931
if ( err ) {
@@ -1173,12 +1175,52 @@ async function getGameIdByName(gameName, system) {
1173
1175
jsonData . response . jeux . length > 0
1174
1176
) {
1175
1177
const gameId = jsonData . response . jeux [ 0 ] . id ;
1176
- console . log ( 'ID del Juego encontrado:' , gameId ) ;
1177
- // Construimos la URL de la imagen y resolvemos la promesa con ella
1178
+ // console.log('ID del Juego encontrado:', gameId);
1178
1179
if ( gameId ) {
1179
- resolve (
1180
- `https://www.screenscraper.fr/image.php?gameid=${ gameId } &media=ss&hd=0®ion=wor&num=&version=&maxwidth=338&maxheight=190` ,
1181
- ) ;
1180
+ const urlSS = `https://www.screenscraper.fr/image.php?gameid=${ gameId } &media=ss&hd=0®ion=wor&num=&version=&maxwidth=338` ;
1181
+ // We check if the url exists
1182
+ https
1183
+ . get ( urlSS , ( res ) => {
1184
+ res . on ( 'data' , ( chunk ) => {
1185
+ data += chunk ;
1186
+ } ) ;
1187
+
1188
+ res . on ( 'end' , ( ) => {
1189
+ if ( data . length > 1000 ) {
1190
+ resolve (
1191
+ `https://www.screenscraper.fr/image.php?gameid=${ gameId } &media=ss&hd=0®ion=wor&num=&version=&maxwidth=338` ,
1192
+ ) ;
1193
+ } else {
1194
+ // We retry with other region
1195
+ urlSS = `https://www.screenscraper.fr/image.php?gameid=${ gameId } &media=ss&hd=0®ion=usa&num=&version=&maxwidth=338` ;
1196
+ // We check if the url exists
1197
+ https
1198
+ . get ( urlSS , ( res ) => {
1199
+ res . on ( 'data' , ( chunk ) => {
1200
+ data += chunk ;
1201
+ } ) ;
1202
+ res . on ( 'end' , ( ) => {
1203
+ if ( data . length > 1000 ) {
1204
+ resolve (
1205
+ `https://www.screenscraper.fr/image.php?gameid=${ gameId } &media=ss&hd=0®ion=usa&num=&version=&maxwidth=338` ,
1206
+ ) ;
1207
+ } else {
1208
+ console . log ( 'IMG not found' ) ;
1209
+ resolve ( false ) ;
1210
+ }
1211
+ } ) ;
1212
+ } )
1213
+ . on ( 'error' , ( err ) => {
1214
+ console . log ( `Error: ${ err . message } ` ) ;
1215
+ } ) ;
1216
+
1217
+ resolve ( false ) ;
1218
+ }
1219
+ } ) ;
1220
+ } )
1221
+ . on ( 'error' , ( err ) => {
1222
+ console . log ( `Error: ${ err . message } ` ) ;
1223
+ } ) ;
1182
1224
} else {
1183
1225
resolve ( null ) ;
1184
1226
}
@@ -1208,10 +1250,11 @@ ipcMain.on('ss-artwork', async (event, system) => {
1208
1250
SELECT DISTINCT
1209
1251
path,
1210
1252
name,
1253
+ file_name,
1211
1254
system
1212
1255
FROM roms
1213
1256
WHERE system = ?
1214
- AND databaseID = 0
1257
+ AND parsed = 0
1215
1258
GROUP BY name
1216
1259
` ;
1217
1260
@@ -1226,25 +1269,72 @@ ipcMain.on('ss-artwork', async (event, system) => {
1226
1269
const resultsArray = rows . map ( ( row ) => ( { ...row } ) ) ;
1227
1270
1228
1271
// We run through the array to get the missing pictures
1229
- async function main ( game , system ) {
1272
+ async function lookForGame ( game , system ) {
1230
1273
try {
1231
1274
const imageUrl = await getGameIdByName ( game , system ) ;
1232
- return imageUrl ;
1275
+ if ( imageUrl ) {
1276
+ return imageUrl ;
1277
+ }
1278
+ return false ;
1233
1279
} catch ( error ) {
1234
1280
console . error ( 'Error obteniendo la URL de la imagen:' , error ) ;
1235
1281
}
1236
1282
}
1237
1283
1238
1284
if ( resultsArray . length > 0 ) {
1239
1285
resultsArray . forEach ( ( result ) => {
1240
- main ( result . name , result . system )
1286
+ const romName = result . file_name ;
1287
+
1288
+ let romNameTrimmed = romName
1289
+ . replace ( / \. n k i t / g, '' )
1290
+ . replace ( / ! / g, '' )
1291
+ . replace ( / D i s c / g, '' )
1292
+ . replace ( / R e v / g, '' )
1293
+ . replace ( / \( [ ^ ( ) ] * \) / g, '' )
1294
+ . replace ( / \[ [ A - z 0 - 9 ! + ] * \] / g, '' )
1295
+ . replace ( / \. / g, '.' ) ;
1296
+
1297
+ romNameTrimmed = romNameTrimmed . replace ( / \. .* / , '' ) ;
1298
+ console . log ( { romNameTrimmed } ) ;
1299
+ lookForGame ( romNameTrimmed , result . system )
1241
1300
. then ( ( imageUrl ) => {
1242
- console . log ( 'URL de la imagen:' , imageUrl ) ;
1243
- result . screenshot = imageUrl ;
1301
+ if ( imageUrl ) {
1302
+ console . log ( 'URL de la imagen:' , imageUrl ) ;
1303
+ result . screenshot = imageUrl ;
1304
+ // We mark the game as scraped
1305
+
1306
+ // SQLITE UPDATE
1307
+ dbLibrary . run (
1308
+ `UPDATE roms
1309
+ SET parsed = 1
1310
+ WHERE name = ? and system = ?` ,
1311
+ [ result . name , result . system ] ,
1312
+ function ( err ) {
1313
+ if ( err ) {
1314
+ return console . error ( err . message ) ;
1315
+ }
1316
+ console . log ( `Filas actualizadas: ${ this . changes } ` ) ;
1317
+ } ,
1318
+ ) ;
1244
1319
1245
- // console.log({ resultsArray });
1246
- resultsJSON = JSON . stringify ( resultsArray , null , 2 ) ;
1247
- event . reply ( 'ss-artwork' , resultsJSON ) ;
1320
+ // console.log({ resultsArray });
1321
+ resultsJSON = JSON . stringify ( resultsArray , null , 2 ) ;
1322
+ event . reply ( 'ss-artwork' , resultsJSON ) ;
1323
+ } else {
1324
+ // SQLITE UPDATE
1325
+ dbLibrary . run (
1326
+ `UPDATE roms
1327
+ SET parsed = 2
1328
+ WHERE name = ? and system = ?` ,
1329
+ [ result . name , result . system ] ,
1330
+ function ( err ) {
1331
+ if ( err ) {
1332
+ return console . error ( err . message ) ;
1333
+ }
1334
+ console . log ( `Filas actualizadas: ${ this . changes } ` ) ;
1335
+ } ,
1336
+ ) ;
1337
+ }
1248
1338
} )
1249
1339
. catch ( ( error ) => {
1250
1340
console . error ( 'Error obteniendo la URL de la imagen:' , error ) ;
0 commit comments