import re from os import listdir from os.path import isfile, join from datetime import datetime from model import Audio def find_audios(index, audio_dir): """ Finds all audios in a folder that match the given index. Audios must be in the format [index].[songname].mp3 :param index: An integer denoting the song's index :param audio_dir: The directory where the songs can be found :return: A list of matching Audio objects """ res = [] for f in listdir(audio_dir): full_file = join(audio_dir, f) re_date_match = re.match(r"^%03d\..*\.mp3$" % index, f) if not isfile(full_file) or not re_date_match: continue res.append(Audio(join("../", full_file))) return res