Skip to content

Instantly share code, notes, and snippets.

@vurpo
Last active July 10, 2016 16:56
Show Gist options
  • Save vurpo/a8bab83db543044fa5a5cd35f3f67ba4 to your computer and use it in GitHub Desktop.
Save vurpo/a8bab83db543044fa5a5cd35f3f67ba4 to your computer and use it in GitHub Desktop.
Filter ROM files to remove region/beta duplicates
#!/usr/bin/env python3
import os
import glob
import sys
"""
Script for filtering duplicates of a game from multiple regions, betas, revisions, etc.
Usage: filter-roms.py <file extension>
"""
if len(sys.argv) != 2:
print("Usage: filter-roms.py <file extension>")
sys.exit(64)
def choose_rom_filename(game_filenames):
for index, rom in enumerate(game_filenames):
if "World" in rom and "Beta" not in rom:
print("Chose world ROM: {}".format(rom))
game_filenames.pop(index)
return [rom, game_filenames]
for index, rom in enumerate(game_filenames):
if "Europe" in rom and "Beta" not in rom:
print("Chose European ROM: {}".format(rom))
game_filenames.pop(index)
return [rom, game_filenames]
for index, rom in enumerate(game_filenames):
if "USA" in rom and "Beta" not in rom:
print("Chose USA ROM: {}".format(rom))
game_filenames.pop(index)
return [rom, game_filenames]
for index, rom in enumerate(game_filenames):
if "Japan" in rom and "Beta" not in rom:
print("Chose Japanese ROM: {}".format(rom))
game_filenames.pop(index)
return [rom, game_filenames]
for index, rom in enumerate(game_filenames):
if "Beta" not in rom:
print("Chose other ROM: {}".format(rom))
game_filenames.pop(index)
return [rom, game_filenames]
filename = game_filenames.pop(0)
print("Chose other ROM (last resort): {}".format(filename))
return [filename, game_filenames]
roms = glob.glob(os.getcwd()+"/*.{}".format(sys.argv[1]))
print("Directory: {}".format(os.getcwd()))
print("{} roms in directory".format(len(roms)))
rom_filenames = [i[len(os.getcwd())+1:] for i in roms]
files_to_delete = []
while len(rom_filenames) > 0:
current_game_name = rom_filenames[0].split("(")[0]
current_game_filenames = []
for index, filename in enumerate(rom_filenames):
if filename.startswith(current_game_name+"("):
current_game_filenames.append(rom_filenames.pop(index))
print("Choosing ROM for game: {}".format(current_game_name))
chosen_rom = choose_rom_filename(current_game_filenames)
files_to_delete.extend(chosen_rom[1])
#print("Files to delete: {}".format(files_to_delete))
deleting_list = open("delete_list", "w")
for filename in files_to_delete:
deleting_list.write(filename+"\n")
deleting_list.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment