Skip to content

Instantly share code, notes, and snippets.

@alpozcan
Last active September 13, 2020 04:48
Show Gist options
  • Save alpozcan/63382ad66006833b29d55ebd18712f9f to your computer and use it in GitHub Desktop.
Save alpozcan/63382ad66006833b29d55ebd18712f9f to your computer and use it in GitHub Desktop.
Generates RetroArch-compatible playlists from directories containing zipped roms
#!/usr/bin/env python3
# Generates RetroArch-compatible playlists from directories containing zipped roms
# Copy this script into ~/.config/retroarch and Set ROM_DIR below to the directory containing the system subdirectories with roms
# These system subdirectories must be named the same way as the RetroArch's playlist names i.e. "Vendor - Console_Model"
import glob, json, os
from zipfile import ZipFile
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
PL_DIR = f'{BASE_DIR}/playlists'
ROM_DIR = '/home/a/Games/Golden Age of Video Games - Age of the Cartridge v8.0'
header = {
"version": "1.4",
"default_core_path": "",
"default_core_name": "",
"label_display_mode": 0,
"right_thumbnail_mode": 0,
"left_thumbnail_mode": 0,
"sort_mode": 0
}
for d in glob.glob(f'{ROM_DIR}/*/'):
system = d.split('/')[-2]
if '-' not in system:
continue
items = []
for f in glob.glob(f'{d}/*.zip'):
zf = ZipFile(f)
info = zf.infolist()[0]
item = {
"path": f"{f}#{info.filename}",
"label": f"{'.'.join(info.filename.split('.')[:-1])}",
"core_path": "DETECT",
"core_name": "DETECT",
"crc32": f"{info.CRC}|crc",
"db_name": f"{system}.lpl"
}
items.append(item)
items_dict = { "items": items }
pl = { **header, **items_dict }
#print(json.dumps(pl))
with open(f"{PL_DIR}/{system}.lpl", "w") as outfile:
json.dump(pl, outfile, indent = 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment