5
5
import sys
6
6
from concurrent .futures import ThreadPoolExecutor , as_completed
7
7
import subprocess
8
+ import hashlib
8
9
9
- # Define the log file path
10
- if os .name == 'nt' :
11
- home_dir = os .environ .get ("USERPROFILE" )
12
- msg_file = os .path .join (home_dir , 'AppData' , 'Roaming' , 'EmuDeck' , "logs/msg.log" )
13
- else :
14
- home_dir = os .environ .get ("HOME" )
15
- msg_file = os .path .join (home_dir , ".config/EmuDeck/logs/msg.log" )
16
-
17
- def getSettings ():
18
- pattern = re .compile (r'([A-Za-z_][A-Za-z0-9_]*)=(.*)' )
19
- user_home = os .path .expanduser ("~" )
20
-
21
- if os .name == 'nt' :
22
- config_file_path = os .path .join (user_home , 'AppData' , 'Roaming' , 'EmuDeck' , 'settings.ps1' )
23
- else :
24
- config_file_path = os .path .join (user_home , 'emudeck' , 'settings.sh' )
25
-
26
- configuration = {}
27
-
28
- with open (config_file_path , 'r' ) as file :
29
- for line in file :
30
- match = pattern .search (line )
31
- if match :
32
- variable = match .group (1 )
33
- value = match .group (2 ).strip ().strip ('"' )
34
- expanded_value = os .path .expandvars (value .replace ('"' , '' ).replace ("'" , "" ))
35
- configuration [variable ] = expanded_value
36
-
37
- # Obtener rama actual del repositorio backend
38
- if os .name == 'nt' :
39
- bash_command = f"cd { os .path .join (user_home , 'AppData' , 'Roaming' , 'EmuDeck' , 'backend' )} && git rev-parse --abbrev-ref HEAD"
40
- else :
41
- bash_command = "cd $HOME/.config/EmuDeck/backend/ && git rev-parse --abbrev-ref HEAD"
42
-
43
- result = subprocess .run (bash_command , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
44
- configuration ["branch" ] = result .stdout .strip ()
45
-
46
- configuration ["systemOS" ] = os .name
47
-
48
- return configuration
10
+ from vars import home_dir , msg_file
11
+ from utils import getSettings , log_message
49
12
50
13
settings = getSettings ()
51
14
storage_path = os .path .expandvars (settings ["storagePath" ])
@@ -54,11 +17,132 @@ def getSettings():
54
17
save_folder = sys .argv [1 ]
55
18
json_path = os .path .join (storage_path , "retrolibrary/cache/missing_artwork_no_hash.json" )
56
19
20
+ def rom_parser_ss_get_alias (system ):
21
+ system_map = {
22
+ "genesis" : "1" , "ps3" : "59" , "ngp" : "25" , "genesiswide" : "1" , "mastersystem" : "2" ,
23
+ "nes" : "3" , "snes" : "4" , "sneshd" : "4" , "gb" : "9" , "gbc" : "10" , "virtualboy" : "11" ,
24
+ "gba" : "12" , "gc" : "13" , "n64" : "14" , "nds" : "15" , "wii" : "16" , "n3ds" : "17" ,
25
+ "sega32x" : "19" , "segacd" : "20" , "gamegear" : "21" , "saturn" : "22" , "dreamcast" : "23" ,
26
+ "atari2600" : "26" , "atarijaguar" : "27" , "atarijaguarcd" : "27" , "lynx" : "28" , "3do" : "29" ,
27
+ "pcengine" : "31" , "bbcmicro" : "37" , "atari5200" : "40" , "atari7800" : "41" , "atarist" : "42" ,
28
+ "atari800" : "43" , "wonderswan" : "45" , "wonderswancolor" : "46" , "colecovision" : "48" ,
29
+ "gw" : "52" , "psx" : "57" , "ps2" : "58" , "psp" : "61" , "amiga600" : "64" , "amstradcpc" : "65" ,
30
+ "c64" : "66" , "scv" : "67" , "neogeocd" : "70" , "pcfx" : "72" , "vic20" : "73" , "zxspectrum" : "76" ,
31
+ "zx81" : "77" , "x68000" : "79" , "channelf" : "80" , "ngpc" : "82" , "apple2" : "86" , "gx4000" : "87" ,
32
+ "dragon" : "91" , "bk" : "93" , "vectrex" : "102" , "supergrafx" : "105" , "fds" : "106" , "satellaview" : "107" ,
33
+ "sufami" : "108" , "sg1000" : "109" , "amiga1200" : "111" , "msx" : "113" , "pcenginecd" : "114" ,
34
+ "intellivision" : "115" , "msx2" : "116" , "msxturbor" : "118" , "n64dd" : "122" , "scummvm" : "123" ,
35
+ "amigacdtv" : "129" , "amigacd32" : "130" , "oricatmos" : "131" , "amiga" : "134" , "dos" : "135" ,
36
+ "prboom" : "135" , "thomson" : "141" , "neogeo" : "142" , "sneswide" : "202" , "megadrive" : "203" ,
37
+ "ti994a" : "205" , "lutro" : "206" , "supervision" : "207" , "pc98" : "208" , "pokemini" : "211" ,
38
+ "samcoupe" : "213" , "openbor" : "214" , "uzebox" : "216" , "apple2gs" : "217" , "spectravideo" : "218" ,
39
+ "palm" : "219" , "x1" : "220" , "pc88" : "221" , "tic80" : "222" , "solarus" : "223" , "mame" : "230" ,
40
+ "easyrpg" : "231" , "pico8" : "234" , "pcv2" : "237" , "pet" : "240" , "lowresnx" : "244" , "switch" : "225" ,
41
+ "wiiU" : "18" , "primehacks" : "16" , "naomi" : "56" , "xbox" : "32" , "xbox360" : "33" , "ps4" : "60" ,
42
+ "doom" : "135" , "atomiswave" : "53"
43
+ }
44
+ return system_map .get (system , "unknown" )
45
+
46
+ def calculate_md5 (filename ):
47
+ hash_md5 = hashlib .md5 ()
48
+ with open (filename , "rb" ) as f :
49
+ for chunk in iter (lambda : f .read (4096 ), b"" ):
50
+ hash_md5 .update (chunk )
51
+ return hash_md5 .hexdigest ()
52
+
53
+ def fetch_game_artwork (name , platform , media_type ):
54
+ username_ss = "djrodtc"
55
+ password_ss = "diFay35WElL"
56
+ api_url_ss = "https://www.screenscraper.fr/api2/"
57
+
58
+ s_id = rom_parser_ss_get_alias (platform )
59
+ params = {
60
+ "devid" : username_ss ,
61
+ "devpassword" : password_ss ,
62
+ "softname" : "EmuDeckRetroLibrary" ,
63
+ "romnom" : name ,
64
+ "systemeid" : s_id ,
65
+ "output" : "json"
66
+ }
67
+
68
+ response = requests .get (f"{ api_url_ss } jeuInfos.php" , params = params )
69
+ if response .status_code == 200 :
70
+ data = response .json ()
71
+ result = {"name" : None , "img" : None }
72
+
73
+ if "response" in data and "jeu" in data ["response" ] and "medias" in data ["response" ]["jeu" ]:
74
+ medias = data ["response" ]["jeu" ]["medias" ]
75
+
76
+ for media in medias :
77
+ if media .get ("type" ) == "ss" and media_type == 'screenshot' :
78
+ result ["name" ] = name
79
+ result ["img" ] = media ["url" ]
80
+ break
81
+ if media .get ("type" ) == "ss-title" and media_type == 'screenshot' :
82
+ result ["name" ] = name
83
+ result ["img" ] = media ["url" ]
84
+ break
85
+ if media .get ("type" ) == media_type :
86
+ result ["name" ] = name
87
+ result ["img" ] = media ["url" ]
88
+ break
89
+ if media .get ("type" ) == "box-2D" and media_type == 'box2dfront' :
90
+ result ["name" ] = name
91
+ result ["img" ] = media ["url" ]
92
+ break
93
+
94
+
95
+ return json .dumps (result )
96
+ else :
97
+ return json .dumps ({"name" : None , "img" : None })
98
+
99
+ def fetch_game_artwork_md5 (filename , platform , media_type ):
100
+ username_ss = "djrodtc"
101
+ password_ss = "diFay35WElL"
102
+ api_url_ss = "https://www.screenscraper.fr/api2/"
103
+
104
+ s_id = rom_parser_ss_get_alias (platform )
105
+ rom_md5 = calculate_md5 (filename )
106
+
107
+ params = {
108
+ "devid" : username_ss ,
109
+ "devpassword" : password_ss ,
110
+ "softname" : "EmuDeckRetroLibrary" ,
111
+ "rommd5" : rom_md5 ,
112
+ "systemeid" : s_id ,
113
+ "output" : "json"
114
+ }
115
+
116
+ response = requests .get (f"{ api_url_ss } jeuInfos.php" , params = params )
117
+ if response .status_code == 200 :
118
+ data = response .json ()
119
+ result = {"name" : None , "img" : None }
120
+
121
+ if "response" in data and "jeu" in data ["response" ] and "medias" in data ["response" ]["jeu" ]:
122
+ medias = data ["response" ]["jeu" ]["medias" ]
123
+
124
+ for media in medias :
125
+ if media .get ("type" ) == "ss" and media_type == 'screenshot' :
126
+ result ["name" ] = name
127
+ result ["img" ] = media ["url" ]
128
+ break
129
+ if media .get ("type" ) == "ss-title" and media_type == 'screenshot' :
130
+ result ["name" ] = name
131
+ result ["img" ] = media ["url" ]
132
+ break
133
+ if media .get ("type" ) == media_type :
134
+ result ["name" ] = name
135
+ result ["img" ] = media ["url" ]
136
+ break
137
+ if media .get ("type" ) == "box-2D" and media_type == 'box2dfront' :
138
+ result ["name" ] = name
139
+ result ["img" ] = media ["url" ]
140
+ break
141
+
142
+ return json .dumps (result )
143
+ else :
144
+ return json .dumps ({"name" : None , "img" : None })
57
145
58
- # Function to write messages to the log file
59
- def log_message (message ):
60
- with open (msg_file , "a" ) as log_file : # "a" to append messages without overwriting
61
- log_file .write (message + "\n " )
62
146
63
147
def create_empty_image (name , platform , save_folder , type ):
64
148
extension = "jpg" if type != "wheel" else "png"
@@ -91,7 +175,8 @@ def fetch_image_data(game):
91
175
name = game ['name' ]
92
176
platform = game ['platform' ]
93
177
type = game ['type' ]
94
- url = f"https://bot.emudeck.com/steamdbimg.php?name={ name } &platform={ platform } &type={ type } "
178
+ filename = game ['filename' ]
179
+ url = f"https://artwork.emudeck.com/steamdbimg.php?name={ name } &platform={ platform } &type={ type } "
95
180
try :
96
181
response = requests .get (url , timeout = 10 )
97
182
response .raise_for_status () # Raise an exception for HTTP error codes
@@ -100,8 +185,20 @@ def fetch_image_data(game):
100
185
if img_url :
101
186
download_image (name , platform , img_url , save_folder , type )
102
187
else :
103
- log_message (f"No URL found for { platform } /{ name } . Creating empty file." )
104
- print (f"No URL found for { platform } /{ name } . Creating empty file." )
188
+ #Let's try name matching with SS
189
+ ss_data = fetch_game_artwork (name , platform , type )
190
+ ss_data = json .loads (ss_data )
191
+ if ss_data and ss_data .get ('img' ):
192
+ download_image (name , platform , ss_data .get ('img' ), save_folder , type )
193
+ else :
194
+ #Let's try MD5
195
+ ss_data = fetch_game_artwork_md5 (filename , platform , type )
196
+ ss_data = json .loads (ss_data )
197
+ if ss_data and ss_data .get ('img' ):
198
+ download_image (name , platform , ss_data .get ('img' ), save_folder , type )
199
+ else :
200
+ print (f"No img found for { name } in { platform } ." )
201
+
105
202
#create_empty_image(name, platform, save_folder, type)
106
203
except requests .RequestException as e :
107
204
log_message (f"Error processing { platform } /{ name } : { e } " )
0 commit comments