|
|
|
|
|
import os |
|
|
import csv |
|
|
import ffmpeg |
|
|
|
|
|
|
|
|
carpeta_audios = "../data/crudo" |
|
|
|
|
|
|
|
|
salida_csv = "../metadata/registros.csv" |
|
|
|
|
|
|
|
|
os.makedirs(os.path.dirname(salida_csv), exist_ok=True) |
|
|
|
|
|
|
|
|
archivos = [f for f in os.listdir(carpeta_audios) if f.lower().endswith('.mp3')] |
|
|
|
|
|
|
|
|
with open(salida_csv, mode='w', newline='', encoding='utf-8') as csvfile: |
|
|
writer = csv.writer(csvfile) |
|
|
writer.writerow(['archivo', 'duracion', 'contiene_cotorra', 'notas']) |
|
|
|
|
|
for archivo in archivos: |
|
|
ruta = os.path.join(carpeta_audios, archivo) |
|
|
try: |
|
|
|
|
|
probe = ffmpeg.probe(ruta) |
|
|
|
|
|
|
|
|
audio_stream = next(stream for stream in probe['streams'] if stream['codec_type'] == 'audio') |
|
|
duracion_segundos = float(audio_stream['duration']) |
|
|
duracion_segundos = round(duracion_segundos, 2) |
|
|
|
|
|
except Exception as e: |
|
|
print(f"Error procesando {archivo}: {e}") |
|
|
duracion_segundos = "" |
|
|
|
|
|
writer.writerow([archivo, duracion_segundos, 'si', 'test del script']) |
|
|
|
|
|
print(f"Archivo generado: {salida_csv}") |
|
|
print(f"Procesados {len(archivos)} archivos MP3") |