Actualizado fbneo_roms_by_manufacturer.py con muuuuchas cosas
This commit is contained in:
@@ -10,17 +10,51 @@ import sys
|
|||||||
import argparse
|
import argparse
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
|
|
||||||
# Inicialización de las opciones
|
|
||||||
ignore_list = ["DECO Cassette"]
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
# Elimina los caracteres ilegales de la cadena de texto
|
||||||
parser.add_argument("-l", "--list", help="Muestra la lista de desarrolladores o de juegos", action="store_true")
|
def normalize_path(path):
|
||||||
parser.add_argument("-c", "--copy", help="Copia las roms", action="store_true")
|
illegal_chars = ["<", ">", ":", '"', "/", "\\", "|", "?", "*"]
|
||||||
parser.add_argument("-s", "--sort", help="Ordena los resultados", action="store_true")
|
replace_with = "_"
|
||||||
|
for char in illegal_chars:
|
||||||
|
path = path.replace(char, replace_with)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
# Inicialización de las opciones
|
||||||
|
ignore_list = ["DECO Cassette", "Bootleg", "prototype", "Quiz", "Mahjong", "Demo"]
|
||||||
|
|
||||||
|
# Obtiene los argumentos
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Gestiona las roms de fbneo por desarrolladores a partir de un fichero .dat"
|
||||||
|
)
|
||||||
|
group = parser.add_mutually_exclusive_group()
|
||||||
|
group.add_argument(
|
||||||
|
"-l",
|
||||||
|
"--list",
|
||||||
|
help="Muestra la lista de desarrolladores o de juegos",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
|
group.add_argument("-c", "--copy", help="Copia las roms", action="store_true")
|
||||||
|
parser.add_argument(
|
||||||
|
"-s",
|
||||||
|
"--sort",
|
||||||
|
help="Ordena los resultados por carpetas de desarrollador al copiar todas las roms",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-cf",
|
||||||
|
"--create_folder",
|
||||||
|
help="Copia las roms dentro de la carpeta del desarrollador",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument("-m", "--manufacturer", help="Selecciona un desarrollador")
|
parser.add_argument("-m", "--manufacturer", help="Selecciona un desarrollador")
|
||||||
parser.add_argument("-d", "--dat", help="Ruta del fichero .dat con información de las roms")
|
parser.add_argument(
|
||||||
parser.add_argument("-i", "--input", help="Ruta donde se encuentran las roms", default="")
|
"-d", "--dat", help="Ruta del fichero .dat con información de las roms"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-i", "--input", help="Ruta donde se encuentran las roms", default=""
|
||||||
|
)
|
||||||
parser.add_argument("-o", "--output", help="Ruta donde depositar las roms", default="")
|
parser.add_argument("-o", "--output", help="Ruta donde depositar las roms", default="")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -44,18 +78,21 @@ if args.list and args.manufacturer == None:
|
|||||||
for game in games:
|
for game in games:
|
||||||
manufacturer = game.getElementsByTagName("manufacturer")[0]
|
manufacturer = game.getElementsByTagName("manufacturer")[0]
|
||||||
manufacturers.append(manufacturer.firstChild.data)
|
manufacturers.append(manufacturer.firstChild.data)
|
||||||
|
|
||||||
# Elimina los duplicados
|
# Elimina los duplicados
|
||||||
manufacturers = list(dict.fromkeys(manufacturers))
|
manufacturers = list(dict.fromkeys(manufacturers))
|
||||||
|
|
||||||
# Ordena la lista
|
# Ordena la lista
|
||||||
manufacturers.sort()
|
manufacturers.sort()
|
||||||
|
|
||||||
# Imprime la lista
|
# Imprime la lista
|
||||||
for i in manufacturers:
|
for i in manufacturers:
|
||||||
print(i)
|
print(i)
|
||||||
|
|
||||||
# Lista los juegos de un desarrollador
|
# Lista los juegos de un desarrollador
|
||||||
if args.list and args.manufacturer != None:
|
if args.list and args.manufacturer != None:
|
||||||
print("List of all {} games".format(args.manufacturer))
|
|
||||||
games = file.getElementsByTagName("game")
|
games = file.getElementsByTagName("game")
|
||||||
|
print("List of all", args.manufacturer, "games:", len(games))
|
||||||
for game in games:
|
for game in games:
|
||||||
cloneof = game.getAttribute("cloneof")
|
cloneof = game.getAttribute("cloneof")
|
||||||
isbios = game.getAttribute("isbios")
|
isbios = game.getAttribute("isbios")
|
||||||
@@ -66,19 +103,25 @@ if args.list and args.manufacturer != None:
|
|||||||
and not cloneof
|
and not cloneof
|
||||||
and not isbios
|
and not isbios
|
||||||
):
|
):
|
||||||
print("%s" % (description.firstChild.data))
|
print(description.firstChild.data)
|
||||||
|
|
||||||
# Copia los juegos seleccionados
|
# Copia los juegos del desarrollador seleccionado
|
||||||
if (
|
if (
|
||||||
args.copy
|
args.copy
|
||||||
and os.path.isdir(args.input)
|
and os.path.isdir(args.input)
|
||||||
and os.path.isdir(args.output)
|
and os.path.isdir(args.output)
|
||||||
and args.manufacturer != None
|
and args.manufacturer != None
|
||||||
):
|
):
|
||||||
print("Copying all {} games".format(args.manufacturer))
|
# Comprueba si ha de crear la carpeta con el nombre del desarrollador
|
||||||
|
if args.create_folder:
|
||||||
|
normalized_manufacturer = normalize_path(args.manufacturer)
|
||||||
|
os.mkdir(os.path.join(args.output, args.manufacturer))
|
||||||
|
|
||||||
notfound = []
|
notfound = []
|
||||||
ignored_games = []
|
ignored_games = []
|
||||||
|
copied_games = []
|
||||||
games = file.getElementsByTagName("game")
|
games = file.getElementsByTagName("game")
|
||||||
|
print("Copying all", args.manufacturer, "games:", len(games))
|
||||||
for game in games:
|
for game in games:
|
||||||
isignored = False
|
isignored = False
|
||||||
name = game.getAttribute("name") + ".zip"
|
name = game.getAttribute("name") + ".zip"
|
||||||
@@ -86,15 +129,88 @@ if (
|
|||||||
isbios = game.getAttribute("isbios")
|
isbios = game.getAttribute("isbios")
|
||||||
manufacturer = game.getElementsByTagName("manufacturer")[0]
|
manufacturer = game.getElementsByTagName("manufacturer")[0]
|
||||||
description = game.getElementsByTagName("description")[0]
|
description = game.getElementsByTagName("description")[0]
|
||||||
|
driver = game.getElementsByTagName("driver")
|
||||||
|
status = (
|
||||||
|
game.getElementsByTagName("driver")[0].getAttribute("status")
|
||||||
|
if driver
|
||||||
|
else ""
|
||||||
|
)
|
||||||
if (
|
if (
|
||||||
manufacturer.firstChild.data == args.manufacturer
|
manufacturer.firstChild.data == args.manufacturer
|
||||||
and not cloneof
|
and not cloneof
|
||||||
and not isbios
|
and not isbios
|
||||||
|
and status == "good"
|
||||||
):
|
):
|
||||||
for element in ignore_list:
|
for ignore_element in ignore_list:
|
||||||
if description.firstChild.data.find(element) != -1:
|
if ignore_element.casefold() in description.firstChild.data.casefold():
|
||||||
ignored_games.append(description.firstChild.data)
|
ignored_games.append(description.firstChild.data)
|
||||||
isignored = True
|
isignored = True
|
||||||
|
|
||||||
|
if not isignored:
|
||||||
|
src = os.path.join(args.input, name)
|
||||||
|
if args.sort:
|
||||||
|
x = manufacturer.firstChild.data
|
||||||
|
x = x.replace(r"/", r"-")
|
||||||
|
dst = os.path.join(args.output, x, name)
|
||||||
|
if not os.path.isdir(os.path.join(args.output, x)):
|
||||||
|
os.mkdir(os.path.join(args.output, x))
|
||||||
|
else:
|
||||||
|
if args.create_folder:
|
||||||
|
dst = os.path.join(args.output, normalized_manufacturer, name)
|
||||||
|
else:
|
||||||
|
dst = os.path.join(args.output, name)
|
||||||
|
|
||||||
|
if os.path.isfile(src):
|
||||||
|
shutil.copyfile(src, dst)
|
||||||
|
copied_games.append(description.firstChild.data)
|
||||||
|
print(description.firstChild.data)
|
||||||
|
else:
|
||||||
|
notfound.append(description.firstChild.data)
|
||||||
|
|
||||||
|
print("\nMissing games:", len(notfound))
|
||||||
|
for game in notfound:
|
||||||
|
print(game)
|
||||||
|
|
||||||
|
print("\nIgnored games:", len(ignored_games))
|
||||||
|
for game in ignored_games:
|
||||||
|
print(game)
|
||||||
|
|
||||||
|
print("\nCopied games: ", len(copied_games))
|
||||||
|
print("Missing games:", len(notfound))
|
||||||
|
print("Ignored games:", len(ignored_games))
|
||||||
|
|
||||||
|
# Copia todos los juegos
|
||||||
|
if (
|
||||||
|
args.copy
|
||||||
|
and os.path.isdir(args.input)
|
||||||
|
and os.path.isdir(args.output)
|
||||||
|
and args.manufacturer == None
|
||||||
|
):
|
||||||
|
notfound = []
|
||||||
|
ignored_games = []
|
||||||
|
copied_games = []
|
||||||
|
games = file.getElementsByTagName("game")
|
||||||
|
print("Copying all games:", len(games))
|
||||||
|
for game in games:
|
||||||
|
isignored = False
|
||||||
|
name = game.getAttribute("name") + ".zip"
|
||||||
|
cloneof = game.getAttribute("cloneof")
|
||||||
|
isbios = game.getAttribute("isbios")
|
||||||
|
manufacturer = game.getElementsByTagName("manufacturer")[0]
|
||||||
|
description = game.getElementsByTagName("description")[0]
|
||||||
|
driver = game.getElementsByTagName("driver")
|
||||||
|
status = (
|
||||||
|
game.getElementsByTagName("driver")[0].getAttribute("status")
|
||||||
|
if driver
|
||||||
|
else ""
|
||||||
|
)
|
||||||
|
|
||||||
|
if not cloneof and not isbios and status == "good":
|
||||||
|
for ignore_element in ignore_list:
|
||||||
|
if ignore_element.casefold() in description.firstChild.data.casefold():
|
||||||
|
ignored_games.append(description.firstChild.data)
|
||||||
|
isignored = True
|
||||||
|
|
||||||
if not isignored:
|
if not isignored:
|
||||||
src = os.path.join(args.input, name)
|
src = os.path.join(args.input, name)
|
||||||
if args.sort:
|
if args.sort:
|
||||||
@@ -105,50 +221,22 @@ if (
|
|||||||
os.mkdir(os.path.join(args.output, x))
|
os.mkdir(os.path.join(args.output, x))
|
||||||
else:
|
else:
|
||||||
dst = os.path.join(args.output, name)
|
dst = os.path.join(args.output, name)
|
||||||
|
|
||||||
if os.path.isfile(src):
|
if os.path.isfile(src):
|
||||||
shutil.copyfile(src, dst)
|
shutil.copyfile(src, dst)
|
||||||
print("%s" % (description.firstChild.data))
|
copied_games.append(description.firstChild.data)
|
||||||
|
print(description.firstChild.data)
|
||||||
else:
|
else:
|
||||||
notfound.append(description.firstChild.data)
|
notfound.append(description.firstChild.data)
|
||||||
print("\nMissing games:")
|
|
||||||
|
print("\nMissing games:", len(notfound))
|
||||||
for game in notfound:
|
for game in notfound:
|
||||||
print(game)
|
print(game)
|
||||||
|
|
||||||
print("\nIgnored games:")
|
print("\nIgnored games:", len(ignored_games))
|
||||||
for game in ignored_games:
|
for game in ignored_games:
|
||||||
print(game)
|
print(game)
|
||||||
|
|
||||||
# Copia todos los juegos
|
print("\nCopied games: ", len(copied_games))
|
||||||
if (
|
print("Missing games:", len(notfound))
|
||||||
args.copy
|
print("Ignored games:", len(ignored_games))
|
||||||
and os.path.isdir(args.input)
|
|
||||||
and os.path.isdir(args.output)
|
|
||||||
and args.manufacturer == None
|
|
||||||
):
|
|
||||||
print("Copying all games")
|
|
||||||
notfound = []
|
|
||||||
games = file.getElementsByTagName("game")
|
|
||||||
for game in games:
|
|
||||||
name = game.getAttribute("name") + ".zip"
|
|
||||||
cloneof = game.getAttribute("cloneof")
|
|
||||||
isbios = game.getAttribute("isbios")
|
|
||||||
manufacturer = game.getElementsByTagName("manufacturer")[0]
|
|
||||||
description = game.getElementsByTagName("description")[0]
|
|
||||||
if not cloneof and not isbios:
|
|
||||||
src = os.path.join(args.input, name)
|
|
||||||
if args.sort:
|
|
||||||
x = manufacturer.firstChild.data
|
|
||||||
x = x.replace(r"/", r"-")
|
|
||||||
dst = os.path.join(args.output, x, name)
|
|
||||||
if not os.path.isdir(os.path.join(args.output, x)):
|
|
||||||
os.mkdir(os.path.join(args.output, x))
|
|
||||||
else:
|
|
||||||
dst = os.path.join(args.output, name)
|
|
||||||
if os.path.isfile(src):
|
|
||||||
shutil.copyfile(src, dst)
|
|
||||||
print("%s" % (description.firstChild.data))
|
|
||||||
else:
|
|
||||||
notfound.append(description.firstChild.data)
|
|
||||||
print("\nMissing games:")
|
|
||||||
for game in notfound:
|
|
||||||
print(game)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user