From 32c3a810b5592e44e3c2af8f27c6c4f9f28fd874 Mon Sep 17 00:00:00 2001 From: Effie Date: Sat, 3 Jun 2023 15:50:51 +1000 Subject: [PATCH] build_clips builds clips --- .gitignore | 5 +++-- build_clips.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ build_db.py | 2 +- build_pages.py | 2 +- 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 build_clips.py diff --git a/.gitignore b/.gitignore index bb70d96..789d5f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -songbook.sqlite -public/ \ No newline at end of file +/songbook.sqlite +/public/ +/clips/ \ No newline at end of file diff --git a/build_clips.py b/build_clips.py new file mode 100644 index 0000000..b5d18d8 --- /dev/null +++ b/build_clips.py @@ -0,0 +1,45 @@ +import sqlite3 +import os +import glob +import subprocess + +os.removedirs('clips') +os.mkdir('clips') + +db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) + +cur = db.cursor() + +for song, motif, start, duration in db.execute(''' + select + song_id, motif_id, start_ms, duration_ms + from + clip'''): + album, track = db.execute(''' + select + album_id, track + from + song_album + where + song_id = ? + order by + album_id desc limit 1''', (song,)).fetchone() + + # get source path + + album_folder = f'{album - 1:02}. *' + song_file = f'{track:03}. *.flac' + + source = glob.glob(f"/mnt/petal/media/Audio/ffxiv/{album_folder}/{song_file}")[0] + + print(source) + + # get clip filename + + destination = f'clips/{song:04}-{motif:03}.flac' + + print (destination) + + # call sox + + subprocess.run(["sox", source, destination, "trim", f'{start / 1000}', f'{duration / 1000}'], check = True) \ No newline at end of file diff --git a/build_db.py b/build_db.py index 07e46bf..737402f 100644 --- a/build_db.py +++ b/build_db.py @@ -58,7 +58,7 @@ cur.executemany( # import song x artist def creditparams(rows): for row in rows[1:]: - for index,artist in enumerate(row[5:], 5): + for index, artist in enumerate(row[5:], 5): if len(artist)>0: yield (row[0],artist,rows[0][index]) diff --git a/build_pages.py b/build_pages.py index dc7469f..04df5d1 100644 --- a/build_pages.py +++ b/build_pages.py @@ -13,7 +13,7 @@ for dirname in [ environment = jinja2.Environment(loader=jinja2.FileSystemLoader("templates/")) songplate = environment.get_template("songpage.jinja") -db = sqlite3.connect("songbook.sqlite") +db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) for song in db.execute("SELECT name FROM song"):