From 0c5f6a0da1db32a7d72fe7e6d5bc3b0c75c4bf21 Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Sat, 12 Dec 2020 17:21:04 +0100 Subject: [PATCH] Add arguments to latex_scanner and update Makefile with some defaults. --- Makefile | 2 +- src/audio_scanner.py | 9 ++++---- src/latex_scanner.py | 52 +++++++++++++++++++++++++------------------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 3b6fd8a..3ab350d 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ public: public/index.html: static public public/audios \ res/index.html res/page.html \ res/song.html res/song_li.html res/song_redir.html - python3 src/latex_scanner.py + python3 src/latex_scanner.py --latex latex/cancionero.tex --audios audios public/audios: audios public rm -f public/audios diff --git a/src/audio_scanner.py b/src/audio_scanner.py index f4cd450..ba7fdb6 100644 --- a/src/audio_scanner.py +++ b/src/audio_scanner.py @@ -5,18 +5,17 @@ import re from datetime import datetime -AUDIO_DIR = "audios/" - -def find_audios(index): +def find_audios(index, audio_dir): """ 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 + :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) + 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 diff --git a/src/latex_scanner.py b/src/latex_scanner.py index 792ef58..440497e 100644 --- a/src/latex_scanner.py +++ b/src/latex_scanner.py @@ -1,8 +1,10 @@ -from song_types import * +from song_types import Chord, Line, Song, Verse +from song_types import readfile, join_list from audio_scanner import find_audios from os.path import join from pathlib import Path import shutil +import argparse import urllib.parse import os import re @@ -38,13 +40,14 @@ song_css = '\n\t