Created
April 7, 2025 00:14
-
-
Save AARP41298/07d46930374875ef90da6f2eb4cdf97b to your computer and use it in GitHub Desktop.
Listar TODAS las canciones instaladas de rock band RPCS3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#codigo de python para hacer scrap | |
import os | |
import re | |
def detectar_encoding(path): | |
with open(path, 'rb') as f: | |
try: | |
contenido = f.read(2048).decode("latin1") | |
match = re.search(r"\('encoding'\s*'([^']+)'\)", contenido) | |
if match: | |
return match.group(1) | |
except Exception: | |
pass | |
return "latin1" | |
def intentar_reparar(texto): | |
try: | |
return texto.encode("latin1").decode("utf-8") | |
except UnicodeDecodeError: | |
return texto # devolver el texto original si falla | |
def extraer_canciones_desde_archivo(ruta_archivo): | |
canciones = [] | |
encoding = detectar_encoding(ruta_archivo) | |
with open(ruta_archivo, encoding="latin1", errors="ignore") as f: | |
contenido = f.read() | |
bloques = re.findall(r"\(\s*'[^']+'\s*(\(.*?\))\s*(\(.*?\))", contenido, re.DOTALL) | |
for bloque in bloques: | |
nombre = artista = None | |
for parte in bloque: | |
name_match = re.search(r"'name'\s*\"(.*?)\"", parte) | |
artist_match = re.search(r"'artist'\s*\"(.*?)\"", parte) | |
if name_match: | |
nombre = intentar_reparar(name_match.group(1)) | |
if artist_match: | |
artista = intentar_reparar(artist_match.group(1)) | |
if nombre and artista: | |
canciones.append((artista, nombre, ruta_archivo)) | |
return canciones | |
def buscar_archivos_y_extraer(rutas_base): | |
resultado = [] | |
for base_dir in rutas_base: | |
for root, _, files in os.walk(base_dir): | |
for file in files: | |
if file == "songs.dta": | |
path = os.path.join(root, file) | |
resultado.extend(extraer_canciones_desde_archivo(path)) | |
return resultado | |
# 👉 Aquà defines todas las rutas base que quieras | |
rutas_base = [ | |
'PS3/dev_hdd0/game/BLUS30463/USRDIR', | |
'PS3/dev_hdd0/game/BLUS30050/USRDIR', | |
# Puedes agregar más rutas aquà | |
] | |
canciones = buscar_archivos_y_extraer(rutas_base) | |
# Ordenar alfabéticamente por artista, luego por canción | |
canciones_ordenadas = sorted(canciones, key=lambda x: (x[0].lower(), x[1].lower())) | |
# Guardar en un archivo de texto | |
with open("canciones.txt", "w", encoding="utf-8") as f: | |
f.write(f"artista,nombre\n") | |
for artista, nombre, ruta in canciones_ordenadas: | |
f.write(f"{artista},{nombre}\n") | |
print(f"{artista} - {nombre} - {ruta}") # también imprimir en consola |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment