Skip to content

Commit 59ebab5

Browse files
committed
Simplify build process; Update display_name to remove region information and instead introduce a new full_name field; Remove description which doesn't contain any useful information
1 parent 5edcf6c commit 59ebab5

File tree

5 files changed

+76
-50
lines changed

5 files changed

+76
-50
lines changed

Makefile

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
SHELL := /bin/bash
1+
SHELL := /bin/bash
2+
PYTHON_EXE := python3
23

3-
PYTHON_EXE := python3
4-
LIBRETRO_SUPER_GIT_URL := https://github.com/libretro/libretro-super.git
4+
LIBRETRO_DATABASE_GIT_URL := https://github.com/libretro/libretro-database.git
5+
LIBRETRO_DATABASE_TAG := v1.10.3
56

6-
BUILD_DIR := build
7-
LIBRETRO_SUPER_DIR := $(BUILD_DIR)/libretro-super
8-
RETROARCH_DIR := $(LIBRETRO_SUPER_DIR)/retroarch
9-
RDB_DIR := $(RETROARCH_DIR)/media/libretrodb/rdb
10-
LIBRETRO_DB_DIR := $(RETROARCH_DIR)/libretro-db
11-
LIBRETRO_DB_TOOL_EXE := $(LIBRETRO_DB_DIR)/libretrodb_tool
7+
BUILD_DIR := build
8+
LIBRETRO_DATABASE_DIR := $(BUILD_DIR)/libretro-database
9+
LIBRETRO_RDB_DIR := $(LIBRETRO_DATABASE_DIR)/rdb
10+
LIBRETRO_SUPER_DIR := $(LIBRETRO_DATABASE_DIR)/libretro-super
11+
LIBRETRO_DB_TOOL_EXE := $(LIBRETRO_SUPER_DIR)/retroarch/libretro-db/libretrodb_tool
1212

1313
SQLITE_DATABASE_FILE := $(BUILD_DIR)/libretrodb.sqlite
1414
SQLITE_DATABASE_ARCHIVE := $(SQLITE_DATABASE_FILE).tgz
@@ -17,24 +17,25 @@ SQLITE_DATABASE_ARCHIVE := $(SQLITE_DATABASE_FILE).tgz
1717
$(BUILD_DIR):
1818
mkdir -p $(BUILD_DIR)
1919

20-
# Retrieve the libretro-super repository
21-
$(LIBRETRO_SUPER_DIR): | $(BUILD_DIR)
22-
git clone $(LIBRETRO_SUPER_GIT_URL) $(LIBRETRO_SUPER_DIR)
20+
$(LIBRETRO_RDB_DIR): $(LIBRETRO_DATABASE_DIR) $(LIBRETRO_SUPER_DIR)
2321

24-
# Retrieve the Retroarch data and build the database
25-
$(RETROARCH_DIR): $(LIBRETRO_SUPER_DIR)
26-
cd $(LIBRETRO_SUPER_DIR) && \
27-
./libretro-fetch.sh retroarch && \
28-
./libretro-build-database.sh
22+
# Retrieve the libretro-database repository
23+
$(LIBRETRO_DATABASE_DIR): | $(BUILD_DIR)
24+
git clone $(LIBRETRO_DATABASE_GIT_URL) $(LIBRETRO_DATABASE_DIR)
25+
git -C $(LIBRETRO_DATABASE_DIR) checkout tags/$(LIBRETRO_DATABASE_TAG)
2926

30-
# Build the libretrodb_tool
31-
$(LIBRETRO_DB_TOOL_EXE): $(RETROARCH_DIR)
32-
$(MAKE) -C $(LIBRETRO_DB_DIR) libretrodb_tool
27+
# Build the libretro-database repository
28+
$(LIBRETRO_SUPER_DIR): | $(LIBRETRO_DATABASE_DIR)
29+
$(MAKE) -C $(LIBRETRO_DATABASE_DIR) build
30+
31+
# Ensure that the libretrodb_tool is built
32+
$(LIBRETRO_DB_TOOL_EXE): | $(LIBRETRO_SUPER_DIR)
33+
$(MAKE) -C $(LIBRETRO_DATABASE_DIR) build
3334

3435
# Generates the .sqlite database file
35-
$(SQLITE_DATABASE_FILE): $(LIBRETRO_DB_TOOL_EXE)
36+
$(SQLITE_DATABASE_FILE): $(LIBRETRO_RDB_DIR) $(LIBRETRO_DB_TOOL_EXE)
3637
$(PYTHON_EXE) main.py \
37-
--rdb-dir=$(RDB_DIR) \
38+
--rdb-dir=$(LIBRETRO_RDB_DIR) \
3839
--output=$(SQLITE_DATABASE_FILE) \
3940
--libretrodb-tool=$(LIBRETRO_DB_TOOL_EXE)
4041

@@ -44,9 +45,11 @@ $(SQLITE_DATABASE_ARCHIVE): $(SQLITE_DATABASE_FILE)
4445

4546
.PHONY: database
4647
database: $(SQLITE_DATABASE_FILE)
48+
$(info $(shell du -sh $(SQLITE_DATABASE_FILE)))
4749

4850
.PHONY: archive
4951
archive: $(SQLITE_DATABASE_ARCHIVE)
52+
$(info $(shell du -sh $(SQLITE_DATABASE_ARCHIVE)))
5053

5154
.PHONY: all
5255
all: database archive

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<img src="https://img.shields.io/badge/size-41.6%20MB-blue"></img>
2-
<img src="https://img.shields.io/badge/compressed%20size-13.4%20MB-blue"></img>
1+
<img src="https://img.shields.io/badge/size-37%20MB-blue"></img>
2+
<img src="https://img.shields.io/badge/compressed%20size-13%20MB-blue"></img>
33

44
# SQLite Libretro DB
55

@@ -44,8 +44,8 @@ build/libretrodb.sqlite.tgz
4444
| release_month | INTEGER |
4545
| region_id | INTEGER |
4646
| genre_id | INTEGER |
47-
| description | TEXT |
4847
| display_name | TEXT |
48+
| full_name | TEXT |
4949
| boxart_url | TEXT |
5050
| platform_id | INTEGER |
5151

@@ -131,7 +131,7 @@ Output:
131131

132132
| serial_id | release_year | release_month | display_name | developer_name | franchise_name | region_name | genre_name | rom_name | rom_md5 | platform_name | manufacturer_name |
133133
| --------- | ------------ | ------------- | ------------ | -------------- | -------------- | ----------- | ---------- | -------- | ------- | ------------- | ----------------- |
134-
| 41575245 | 2001 | 9 | Advance Wars (USA) | Intelligent Systems | Advance Wars | USA | Strategy | Advance Wars (USA).gba | 27F322F5CD535297AB21BC4A41CBFC12 | Game Boy Advance | Nintendo |
134+
| 41575245 | 2001 | 9 | Advance Wars | Intelligent Systems | Advance Wars | USA | Strategy | Advance Wars (USA).gba | 27F322F5CD535297AB21BC4A41CBFC12 | Game Boy Advance | Nintendo |
135135

136136
## Artwork
137137

main.py

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99
from pathlib import Path
1010
from subprocess import PIPE
1111

12+
class Logger:
13+
14+
def __init__(self):
15+
self.CRED = '\033[91m'
16+
self.CGREEN = '\033[92m'
17+
self.CEND = '\033[0m'
18+
19+
def error(self, msg):
20+
print("{cred}{msg}{cend}".format(cred=self.CRED, msg=msg, cend=self.CEND))
21+
22+
def info(self, msg):
23+
print(msg)
24+
25+
def success(self, msg):
26+
print("{cgreen}{msg}{cend}".format(cgreen=self.CGREEN, msg=msg, cend=self.CEND))
27+
1228
class Platform:
1329

1430
def __init__(self, name, manufacturer_id):
@@ -25,9 +41,10 @@ def __init__(self, name, md5):
2541

2642
class Game:
2743

28-
def __init__(self, display_name, serial, rom, developer_id, franchise_id, release_year, release_month, region_id, genre_id, description, platform_id):
44+
def __init__(self, display_name, full_name, serial, rom, developer_id, franchise_id, release_year, release_month, region_id, genre_id, platform_id):
2945
self.id = None
3046
self.display_name = display_name
47+
self.full_name = full_name
3148
self.serial = serial
3249
self.rom = rom
3350
self.developer_id = developer_id
@@ -36,7 +53,6 @@ def __init__(self, display_name, serial, rom, developer_id, franchise_id, releas
3653
self.release_month = release_month
3754
self.region_id = region_id
3855
self.genre_id = genre_id
39-
self.description = description
4056
self.platform_id = platform_id
4157

4258
"""
@@ -46,6 +62,8 @@ def join(self, other):
4662
# Join the top-level fields
4763
if self.display_name is None and other.display_name is not None:
4864
self.display_name = other.display_name
65+
if self.full_name is None and other.full_name is not None:
66+
self.full_name = other.full_name
4967
if self.serial is None and other.serial is not None:
5068
self.serial = other.serial
5169
if self.developer_id is None and other.developer_id is not None:
@@ -60,8 +78,6 @@ def join(self, other):
6078
self.region_id = other.region_id
6179
if self.genre_id is None and other.genre_id is not None:
6280
self.genre_id = other.genre_id
63-
if self.description is None and other.description is not None:
64-
self.description = other.description
6581
if self.platform_id is None and other.platform_id is not None:
6682
self.platform_id = other.platform_id
6783
# Join the ROM
@@ -75,6 +91,7 @@ def join(self, other):
7591
class Converter:
7692

7793
def __init__(self, rdb_dir, output_file, libretrodb_tool):
94+
self.logger = Logger()
7895
self.rdb_dir = self._validate_rdb_dir(rdb_dir)
7996
self.output_file = self._validate_output_file(output_file)
8097
self.libretrodb_tool = self._validate_libretrodb_tool(libretrodb_tool)
@@ -92,7 +109,7 @@ def __init__(self, rdb_dir, output_file, libretrodb_tool):
92109
"""
93110
def _validate_rdb_dir(self, rdb_dir):
94111
if not os.path.isdir(rdb_dir):
95-
print("{} is not a directory".format(rdb_dir))
112+
self.logger.error("{} is not a directory".format(rdb_dir))
96113
exit(1)
97114
return rdb_dir
98115

@@ -101,7 +118,7 @@ def _validate_rdb_dir(self, rdb_dir):
101118
"""
102119
def _validate_output_file(self, output_file):
103120
if os.path.isfile(output_file):
104-
print("{} already exists".format(output_file))
121+
self.logger.error("{} already exists".format(output_file))
105122
exit(1)
106123
return output_file
107124

@@ -123,7 +140,7 @@ def _validate_output_file(self, output_file):
123140
"""
124141
def _validate_libretrodb_tool(self, libretrodb_tool):
125142
if not os.path.isfile(libretrodb_tool):
126-
print("{} not found".format(libretrodb_tool))
143+
self.logger.error("{} not found".format(libretrodb_tool))
127144
exit(1)
128145
return libretrodb_tool
129146

@@ -143,7 +160,7 @@ def run(self):
143160
# Iterate over the .rdb files in the input directory and parse all data
144161
for file in [f for f in os.listdir(self.rdb_dir) if os.path.isfile(os.path.join(self.rdb_dir, f))]:
145162
if not file.endswith('.rdb'):
146-
print("Skipping non-RDB file: {}".format(file))
163+
self.logger.info("Skipping non-RDB file: {}".format(file))
147164
continue
148165
self._parse_platform_file(os.path.join(self.rdb_dir, file))
149166
# break # TODO: Remove this
@@ -174,7 +191,7 @@ def run(self):
174191
Parses a single platform .rdb file.
175192
"""
176193
def _parse_platform_file(self, rdb_file):
177-
print(" > Parsing: {}".format(rdb_file))
194+
self.logger.info("Parsing {}".format(rdb_file))
178195

179196
# Try to parse out the manufacturer and platfrom from the .rdb filename
180197
system_fullname = Path(rdb_file).stem
@@ -209,8 +226,8 @@ def _parse_line(self, json_str, platform_id):
209226
try:
210227
json_obj = json.loads(json_str)
211228
except json.decoder.JSONDecodeError as e:
212-
print("Error while parsing JSON: {}".format(e.msg))
213-
print("Original JSON string: {}".format(json_str))
229+
self.logger.error("Error while parsing JSON: {}".format(str(e)))
230+
self.logger.error("Original JSON string: {}".format(json_str))
214231
return
215232

216233
# Extract the fields from the JSON
@@ -224,8 +241,14 @@ def _parse_line(self, json_str, platform_id):
224241
rom_name = self._get_json_value(json_obj, 'rom_name')
225242
region = self._get_json_value(json_obj, 'region')
226243
genre = self._get_json_value(json_obj, 'genre')
227-
description = self._get_json_value(json_obj, 'description')
228-
display_name = self._get_json_value(json_obj, 'name')
244+
# description = self._get_json_value(json_obj, 'description') # This field in the dataset doesn't currently provide any added value
245+
full_name = self._get_json_value(json_obj, 'name')
246+
247+
# Build the display name from the full name, but ignore all the trailing parenthesis-wrapped meta-tags
248+
if full_name is None:
249+
display_name = None
250+
else:
251+
display_name = full_name.split("(")[0].strip() if "(" in full_name else full_name
229252

230253
# Save potentially common references to developers, franchises, regions and genres, and assign an ID
231254
if developer is not None and developer not in self.developers:
@@ -244,7 +267,7 @@ def _parse_line(self, json_str, platform_id):
244267

245268
# Build the ROM and Game objects. Note that ROMs and games should be 1:1.
246269
rom = ROM(rom_name, md5)
247-
game = Game(display_name, serial, rom, developer_id, franchise_id, release_year, release_month, region_id, genre_id, description, platform_id)
270+
game = Game(display_name, full_name, serial, rom, developer_id, franchise_id, release_year, release_month, region_id, genre_id, platform_id)
248271
if md5 in self.games:
249272
self.games[md5].join(game)
250273
else:
@@ -257,60 +280,59 @@ def _parse_line(self, json_str, platform_id):
257280
Insert the manufacturers into the database.
258281
"""
259282
def _insert_manufacturers(self, cursor):
260-
print(" > Inserting {} manufacturers into database…".format(len(self.manufacturers)))
261283
for key,value in self.manufacturers.items():
262284
(id, name) = (value, key)
263285
cursor.execute(self._load_sql("./sql/insert_manufacturer.sql"), (id, name))
286+
self.logger.success("Inserted {} manufacturers into database".format(len(self.manufacturers)))
264287

265288
"""
266289
Insert the platforms into the database.
267290
"""
268291
def _insert_platforms(self, cursor):
269-
print(" > Inserting {} platforms into database…".format(len(self.platforms)))
270292
for key,value in self.platforms.items():
271293
cursor.execute(self._load_sql("./sql/insert_platform.sql"), (value.id, value.name, value.manufacturer_id))
294+
self.logger.success("Inserted {} platforms into database".format(len(self.platforms)))
272295

273296
"""
274297
Insert the developers into the database.
275298
"""
276299
def _insert_developers(self, cursor):
277-
print(" > Inserting {} developers into database…".format(len(self.developers)))
278300
for key,value in self.developers.items():
279301
(id, name) = (value, key)
280302
cursor.execute(self._load_sql("./sql/insert_developer.sql"), (id, name))
303+
self.logger.success("Inserted {} developers into database".format(len(self.developers)))
281304

282305
"""
283306
Insert the franchises into the database.
284307
"""
285308
def _insert_franchises(self, cursor):
286-
print(" > Inserting {} franchises into database…".format(len(self.franchises)))
287309
for key,value in self.franchises.items():
288310
(id, name) = (value, key)
289311
cursor.execute(self._load_sql("./sql/insert_franchise.sql"), (id, name))
312+
self.logger.success("Inserted {} franchises into database".format(len(self.franchises)))
290313

291314
"""
292315
Insert the regions into the database.
293316
"""
294317
def _insert_regions(self, cursor):
295-
print(" > Inserting {} regions into database…".format(len(self.regions)))
296318
for key,value in self.regions.items():
297319
(id, name) = (value, key)
298320
cursor.execute(self._load_sql("./sql/insert_region.sql"), (id, name))
321+
self.logger.success("Inserted {} regions into database".format(len(self.regions)))
299322

300323
"""
301324
Insert the genres into the database.
302325
"""
303326
def _insert_genres(self, cursor):
304-
print(" > Inserting {} genres into database…".format(len(self.genres)))
305327
for key,value in self.genres.items():
306328
(id, name) = (value, key)
307329
cursor.execute(self._load_sql("./sql/insert_genre.sql"), (id, name))
330+
self.logger.success("Inserted {} genres into database".format(len(self.genres)))
308331

309332
"""
310333
Insert the ROMs and games into the database.
311334
"""
312335
def _insert_games(self, cursor):
313-
print(" > Inserting {} games into database…".format(len(self.games)))
314336
for key,value in self.games.items():
315337
game = value
316338
cursor.execute(self._load_sql("./sql/insert_rom.sql"), (game.rom.id, game.rom.name, game.rom.md5))
@@ -324,9 +346,10 @@ def _insert_games(self, cursor):
324346
game.release_month,
325347
game.region_id,
326348
game.genre_id,
327-
game.description,
328349
game.display_name,
350+
game.full_name,
329351
game.platform_id))
352+
self.logger.success("Inserted {} games into database".format(len(self.games)))
330353

331354
def _get_json_value(self, json_obj, key):
332355
return json_obj[key] if key in json_obj else None

sql/create_tables.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ CREATE TABLE games (
88
release_month INTEGER,
99
region_id INTEGER,
1010
genre_id INTEGER,
11-
description TEXT,
1211
display_name TEXT,
12+
full_name TEXT,
1313
-- boxart_url TEXT,
1414
platform_id INTEGER
1515
);

sql/insert_game.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ INSERT INTO games(
88
release_month,
99
region_id,
1010
genre_id,
11-
description,
1211
display_name,
12+
full_name,
1313
-- boxart_url,
1414
platform_id
1515
) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)

0 commit comments

Comments
 (0)