canvi d'estrategia en create_m3u_multidisc_files.py
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import os
|
||||
import shutil
|
||||
import re
|
||||
import sys
|
||||
|
||||
@@ -7,7 +6,7 @@ def organize_files(base_path):
|
||||
# Expresión regular para buscar específicamente '(Disc X)' donde X es un único dígito
|
||||
disc_pattern = re.compile(r'\(Disc \d\)')
|
||||
|
||||
print(f"Iniciando organización de archivos en: {base_path}")
|
||||
print(f"Iniciando organización y renombrado de archivos en: {base_path}")
|
||||
|
||||
# Obtiene una lista de archivos que coincidan exactamente con el formato esperado
|
||||
files = [f for f in os.listdir(base_path) if disc_pattern.search(f)]
|
||||
@@ -25,28 +24,26 @@ def organize_files(base_path):
|
||||
|
||||
print(f"Grupos formados: {len(groups)} grupos identificados")
|
||||
|
||||
# Crear carpetas, mover archivos y generar archivos .m3u
|
||||
# Renombrar archivos y generar archivos .m3u
|
||||
for base_name, group_files in groups.items():
|
||||
print(f"Procesando grupo: {base_name}")
|
||||
|
||||
# Crear la carpeta para el grupo
|
||||
folder_path = os.path.join(base_path, base_name)
|
||||
os.makedirs(folder_path, exist_ok=True)
|
||||
print(f"Carpeta creada: {folder_path}")
|
||||
|
||||
# Mover archivos al nuevo directorio
|
||||
# Renombrar los archivos
|
||||
for file in sorted(group_files): # Ordenar los archivos por disco
|
||||
shutil.move(os.path.join(base_path, file), folder_path)
|
||||
print(f"Archivo movido: {file} → {folder_path}")
|
||||
original_path = os.path.join(base_path, file)
|
||||
new_path = os.path.join(base_path, file + '.disc')
|
||||
os.rename(original_path, new_path)
|
||||
print(f"Archivo renombrado: {original_path} → {new_path}")
|
||||
|
||||
# Crear el archivo .m3u
|
||||
m3u_path = os.path.join(folder_path, f'{base_name}.m3u')
|
||||
m3u_path = os.path.join(base_path, f'{base_name}.m3u')
|
||||
with open(m3u_path, 'w') as m3u_file:
|
||||
for file in sorted(group_files): # Asegura que estén en orden
|
||||
m3u_file.write(file + '\n')
|
||||
new_filename = file + '.disc' # El nombre con la nueva extensión
|
||||
m3u_file.write(new_filename + '\n')
|
||||
print(f"Archivo .m3u creado: {m3u_path}")
|
||||
|
||||
print("Organización y creación de listas .m3u completadas.")
|
||||
print("Organización y renombrado completados.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comprobamos que se pase un argumento con la ruta base
|
||||
|
||||
Reference in New Issue
Block a user