diff --git a/build_clips.py b/build_clips.py index 6c2a66a..3544db5 100644 --- a/build_clips.py +++ b/build_clips.py @@ -1,11 +1,10 @@ import sqlite3 import os import glob -import subprocess import shutil +import sox shutil.rmtree('clips') -# os.removedirs('clips') os.mkdir('clips') db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) @@ -40,29 +39,36 @@ for song, motif, start, duration in db.execute(''' destination = f'clips/{song:04}-{motif:03}.flac' - print (destination) + print(destination) + + source_duration = sox.file_info.duration(source) # trim and fade start - if start / 1000 < 2: + if start < 2: trim_start = 0 - trim_duration = duration / 1000 + start / 1000 + 2 fade_in = 0 - fade_out = 2 else: - trim_start = start / 1000 - 2 - trim_duration = duration / 1000 + 4 + trim_start = start - 2 fade_in = 2 - fade_out = 2 # trim and fade end (to be continued) - + if source_duration - (start + duration ) < 2: + trim_end = None + fade_out = 0 + else: + trim_end = start + duration + 2 + fade_out = 2 # call sox - sox_args = [str(x) for x in ["sox", source, destination, - "trim", trim_start, trim_duration, - "fade", "t", fade_in, "-0", fade_out]] - print(' '.join(sox_args)) - subprocess.run(sox_args, check = True) \ No newline at end of file + tf = sox.Transformer() + tf.trim(trim_start, trim_end) + tf.fade(fade_in, fade_out, 't') + sox_status = tf.build_file(source, destination, return_output=True) + + # error check + + if sox_status != (0, '', ''): + print(sox_status) \ No newline at end of file diff --git a/db.sql b/db.sql index 3d993dc..7e15673 100644 --- a/db.sql +++ b/db.sql @@ -1,7 +1,9 @@ +PRAGMA foreign_keys = ON; + create table song( id int primary key, name text not null, - name_jp text, + name_jp text not null, unique(name,name_jp) ); @@ -15,7 +17,7 @@ create table album( create table artist( id int primary key, name text not null, - name_rm text + name_rm text not null ); create unique index ix_artist_name on artist( diff --git a/reference.ods b/reference.ods index d23a999..3bee5a0 100644 Binary files a/reference.ods and b/reference.ods differ diff --git a/reference_clips.ods b/reference_clips.ods index cc11f87..219c1af 100644 Binary files a/reference_clips.ods and b/reference_clips.ods differ