mirror of
https://gitlab.com/parroquia-san-leandro/cancionero-web.git
synced 2025-07-01 11:07:03 +02:00
initial commit
This commit is contained in:
commit
c8c7eae33c
16 changed files with 835 additions and 0 deletions
25
src/audio_scanner.py
Normal file
25
src/audio_scanner.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
from song_types import Audio
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
AUDIO_DIR = "audios/"
|
||||
|
||||
def find_audios(index):
|
||||
"""
|
||||
Finds all audios in a folder that match the given index.
|
||||
Audios must be in the format [index]_[YYYY]-[MM]-[DD].mp3
|
||||
:param index: An integer denoting the song's index
|
||||
: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_(\d{4}-[01]\d-[0-3]\d).mp3$" % index, f)
|
||||
if not isfile(full_file) or not re_date_match:
|
||||
continue
|
||||
date = datetime.strptime(re_date_match.group(1), "%Y-%m-%d")
|
||||
res.append(Audio(date, join("../", full_file)))
|
||||
return res
|
Loading…
Add table
Add a link
Reference in a new issue