Skip to content

Instantly share code, notes, and snippets.

@cobaltgit
Last active April 23, 2024 12:58
Show Gist options
  • Save cobaltgit/2df62f97d331808cc9da52af0f57dff7 to your computer and use it in GitHub Desktop.
Save cobaltgit/2df62f97d331808cc9da52af0f57dff7 to your computer and use it in GitHub Desktop.
Generate M3U files for CHD ROMs in a directory
import os
import re
CHD_DIR = "/path/to/chds"
chds = [*filter(lambda i: i.endswith(".chd"), os.listdir(CHD_DIR))]
games = set(name[:name.find("(")] for name in chds)
for game in games:
m3u_list = [chd + "\n" for chd in chds if game in chd]
if game_match := re.search(r"\(Disc.*$", m3u_list[0]): # multi-disc
m3u_name = m3u_list[0][:game_match.start() - 1] + ".m3u"
else: # single-disc
m3u_name = m3u_list[0].replace(".chd", ".m3u")
with open(os.path.join(CHD_DIR, m3u_name), "w") as m3u:
m3u.writelines(m3u_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment