-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathseek_moddb_id.py
236 lines (221 loc) · 10.4 KB
/
seek_moddb_id.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# Copyright (c) 2022 Facenapalm
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""
Add Mod DB game ID (P6774) based on matching Steam application ID (P1733).
To get started, type:
python seek_moddb_id.py -h
"""
import re
import time
import requests
import pywikibot
from common.seek_basis import SearchIDSeekerBot
class ModDBSeekerBot(SearchIDSeekerBot):
def __init__(self):
super().__init__(
database_property="P6774",
default_matching_property="P1733",
allowed_matching_properties=["P1733", "P2725"],
)
get_item = lambda x: pywikibot.ItemPage(self.repo, x)
self.engine_property = "P408"
self.engines_map = {
"3d-game-studio": get_item("Q229443"),
"3d-rad": get_item("Q4636302"),
"4a-engine": get_item("Q4031580"),
"adobe-flash-professional": get_item("Q165658"),
"adventure-game-studio": get_item("Q379950"),
"andengine": get_item("Q20312927"),
"app-game-kit": get_item("Q4780806"),
"aurora-engine": get_item("Q2716371"),
"biengine": get_item("Q14791544"),
"bitsquid": get_item("Q20313353"),
"blender-game-engine": get_item("Q2536408"),
"blitz-max": get_item("Q114731514"),
"blitz3d": get_item("Q11605797"),
"box2d": get_item("Q2579122"),
"brender": get_item("Q4034737"),
"build": get_item("Q1003003"),
"clausewitz-engine": get_item("Q13218581"),
"cloaknt": get_item("Q4036308"),
"cocos2d-for-iphone": get_item("Q1525915"),
"cocos2d-x": get_item("Q1525915"),
"construct": get_item("Q1049161"),
"construct-2": get_item("Q5164395"),
"coppercube": get_item("Q5168683"),
"cpal3d-engine": get_item("Q4035669"),
"creation-engine": get_item("Q4036655"),
"cryengine": get_item("Q21693758"),
"cryengine-2": get_item("Q1064234"),
"cryengine-3": get_item("Q2347849"),
"cryengine-4": get_item("Q21653706"),
"cryengine-v": get_item("Q30894842"),
"crystalspace-3d": get_item("Q1142409"),
"dagor": get_item("Q4036974"),
"dark-engine": get_item("Q736363"),
"darkbasic-professional": get_item("Q10986684"),
"darkplaces-engine": get_item("Q838299"),
"diesel-engine": get_item("Q4037333"),
"doom-engine": get_item("Q909009"),
"dunia": get_item("Q113073"),
"eduke32": get_item("Q64167651"),
"enigma-engine": get_item("Q4038075"),
"essence-engine": get_item("Q4038228"),
"europa-engine": get_item("Q111203019"),
"flixel": get_item("Q2348717"),
"forgelight-engine": get_item("Q5469616"),
"fox-engine": get_item("Q650498"),
"fpsc": get_item("Q107458689"),
"frostbite": get_item("Q124514"),
"frostbite-2": get_item("Q12809604"),
"frostbite-3": get_item("Q20472780"),
"gamebryo": get_item("Q1196211"),
"gamemaker": get_item("Q243720"),
"genie-engine": get_item("Q2981987"),
"genome": get_item("Q71848663"),
"geo-mod-2": get_item("Q4039342"),
"godot-engine": get_item("Q16972633"),
"goldsource": get_item("Q369990"),
"hedgehog-engine": get_item("Q4040509"),
"heroengine": get_item("Q3134308"),
"i-novae-engine": get_item("Q5967667"),
"id-tech-2": get_item("Q13231453"),
"id-tech-3": get_item("Q263952"),
"id-tech-4": get_item("Q306572"),
"id-tech-5": get_item("Q521406"),
"id-tech-6": get_item("Q4041255"),
"infernal-engine": get_item("Q4041377"),
"infinity-engine": get_item("Q602983"),
"instead": get_item("Q4041077"),
"iron-engine": get_item("Q4041612"),
"irrlicht-3d-engine": get_item("Q1423300"),
"iw-engine": get_item("Q1775450"),
"jmonkeyengine": get_item("Q285718"),
"leadwerks": get_item("Q28957023"),
"libgdx": get_item("Q16321264"),
"lightweight-java-game-library": get_item("Q940526"),
"lithtech": get_item("Q213136"),
"ls3d": get_item("Q2669875"),
"lumberyard": get_item("Q22949502"),
"lyn": get_item("Q4043279"),
"moai": get_item("Q6886358"),
"monogame": get_item("Q13218967"),
"multimedia-fusion": get_item("Q1755199"),
"neoaxis": get_item("Q10336182"),
"odyssey": get_item("Q2072101"),
"ogre-engine": get_item("Q1073498"),
"openmw": get_item("Q21758353"),
"panda3d": get_item("Q2049263"),
"pathengine": get_item("Q4046528"),
"phaser": get_item("Q48851432"),
"phoenix-engine-relic-entertainment": get_item("Q7186840"),
"phyreengine": get_item("Q834539"),
"pyrogenesis": get_item("Q76618176"),
"quake-engine": get_item("Q181202"),
"quest3d": get_item("Q385875"),
"rage": get_item("Q961461"),
"renderware": get_item("Q1377750"),
"renpy": get_item("Q1196014"),
"rpg-maker-2003": get_item("Q7277472"),
"rpg-maker-mv": get_item("Q22128818"),
"rpg-maker-mz": get_item("Q107315313"),
"rpg-maker-vx": get_item("Q5241236"),
"rpg-maker-vx-ace": get_item("Q32953569"),
"rpg-maker-xp": get_item("Q3276130"),
"sage-strategy-action-game-engine": get_item("Q1971936"),
"scimitar": get_item("Q282293"),
"serious-engine": get_item("Q4049306"),
"sfml": get_item("Q919155"),
"source": get_item("Q643572"),
"source-2": get_item("Q21658271"),
"spring": get_item("Q1754264"),
"stencyl": get_item("Q7607505"),
"storm3d": get_item("Q114731401"),
"stratagus": get_item("Q1936867"),
"torque-2d": get_item("Q851402"), # create an element for this separate version ?
"torque-3d": get_item("Q851402"), # create an element for this separate version ?
"torque-game-engine": get_item("Q851402"),
"treyarch-ngl": get_item("Q2688551"),
"twine": get_item("Q15411624"),
"tyranobuilder": get_item("Q113938826"),
"unigine": get_item("Q2564057"),
"unity": get_item("Q63966"),
"unreal-development-kit": get_item("Q13156651"), # just an alias for Unreal Engine 3 ?
"unreal-engine-1": get_item("Q84583653"),
"unreal-engine-2": get_item("Q13156650"),
"unreal-engine-3": get_item("Q13156651"),
"unreal-engine-4": get_item("Q13156652"),
"unreal-engine-5": get_item("Q94277753"),
"visionaire-studio": get_item("Q2528330"),
"wintermute": get_item("Q841283"),
"wolf-rpg-editor": get_item("Q11253808"),
"wolf3d-engine": get_item("Q4020662"),
"x-ray-engine": get_item("Q1984445"),
"xash3d-engine": get_item("Q20732283"),
"xna": get_item("Q949728"),
"zengin": get_item("Q71850046"),
"unknown": None,
"custom-built": None,
}
def search(self, query, max_results=10):
params = [
( "a", "search" ),
( "p", "games" ),
( "q", query ),
( "l", max_results ),
]
response = requests.get("https://www.moddb.com/html/scripts/autocomplete.php", params=params, headers=self.headers)
time.sleep(2)
if response:
return re.findall(r'href="/games/([^"]+)"', response.text)
else:
raise RuntimeError(f"can't get search results for query `{query}`. Status code: {response.status_code}")
def parse_entry(self, entry_id):
response = requests.get(f"https://www.moddb.com/games/{entry_id}", headers=self.headers)
time.sleep(2)
if not response:
print(f"WARNING: can't get info for game `{entry_id}`")
return {}
html = response.text
result = {}
match = re.search(r'<div class="table tablemenu tableprice">.*?</div>\s*</div>', html, flags=re.DOTALL)
if match:
tableprice = match.group(0)
match = re.search(r'href="https?://store\.steampowered\.com/app/(\d+)[/"]', tableprice)
if match:
result["P1733"] = match.group(1)
match = re.search(r'href="https?://www\.gog\.com/(?:en/)?(game/[a-z0-9_]+)[?"]', tableprice)
if match:
result["P2725"] = match.group(1)
else:
print(f"WARNING: can't get price table for game `{entry_id}`")
match = re.search(r'<h5>Engine</h5>\s*<span class="summary">\s*<a href="/engines/([a-z0-9\-]+)">([^<]+)</a>\s*</span>\s*</div>', html)
if match:
engine_slug = match.group(1)
if engine_slug in self.engines_map:
if self.engines_map[engine_slug] is not None:
result[self.engine_property] = self.engines_map[engine_slug]
else:
print(f"WARNING: unknown engine `{engine_slug}` for game `{entry_id}`")
else:
print(f"WARNING: can't get engine for game `{entry_id}`")
return result
if __name__ == "__main__":
ModDBSeekerBot().run()