""" Lister tous les noms de fichier d'un dossier Formater pour les affichier dans une liste """ import os from mutagen.mp3 import MP3 def mutagen_length(path): try: audio = MP3(path) length = audio.info.length return length except: return None # Chemin du répertoire que vous souhaitez explorer collection = 'phapthoai-2025' chemin = '/Users/phuoc/pyramid/cao_sunyata_media/TuyenTapNiSu/' + collection # Obtenir la liste de tous les fichiers et dossiers items = os.listdir(chemin) sorted_items = sorted(items) # Afficher le contenu print("
") n = 0 for filename in sorted_items: if filename != '.DS_Store': # get duration of mp3 file length = mutagen_length(chemin + '/' + filename) duration = str(int(length/60)) + ':' + str(int(length%60)) w = filename.split('-') s = w[0] + '. ' + w[1].replace('_',' ') title = ' '.join(elem.capitalize() for elem in s.split()) ligne = '

' ligne += '   %s (%s)

' % (collection, filename, title, duration) print(ligne) n += 1 print("
") print('Total %s ' % n) def mutagen_length(path): try: audio = MP3(path) length = audio.info.length return length except: return None