Skip to content

Instantly share code, notes, and snippets.

@x
Created December 23, 2023 01:29
Show Gist options
  • Save x/ede2e6ea8d5b1e32bbf9755a83f7f577 to your computer and use it in GitHub Desktop.
Save x/ede2e6ea8d5b1e32bbf9755a83f7f577 to your computer and use it in GitHub Desktop.
Extract game images from OpenEmu with rom-based names
#! python
import argparse
import sqlite3
import os
import shutil
import sys
from urllib.parse import unquote
QUERY = """
SELECT ZGAME.ZNAME, ZIMAGE.ZRELATIVEPATH, ZIMAGE.ZSOURCE, ZROM.ZLOCATION
FROM ZGAME
JOIN ZIMAGE ON ZGAME.ZBOXIMAGE = ZIMAGE.Z_PK
JOIN ZROM ON ZROM.ZGAME = ZGAME.Z_PK
WHERE ZIMAGE.ZRELATIVEPATH != "";
"""
def main():
out_dir = sys.argv[1]
if not out_dir.endswith("/"):
out_dir += "/"
lib_dir = os.path.expanduser("~/Library/Application Support/OpenEmu/Game Library/")
conn = sqlite3.connect(f"{lib_dir}Library.storedata")
for name, img_rel_path, img_src, rom_path in conn.cursor().execute(QUERY):
ext = img_src.split(".")[-1]
art_path = lib_dir + "Artwork/" + img_rel_path
try:
_dir, rom_fname = unquote(rom_path).split("/")
except Exception:
print(f"Didn't know how to handle {rom_path}")
os.makedirs("./" + out_dir + _dir, exist_ok=True)
out_path = "./" + out_dir + _dir + "/" + rom_fname.split(".")[0] + "." + ext
shutil.copyfile(art_path, out_path)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment