68 lines
1.4 KiB
Python
68 lines
1.4 KiB
Python
import sqlite3
|
|
import os
|
|
import glob
|
|
import subprocess
|
|
import shutil
|
|
|
|
shutil.rmtree('clips')
|
|
# 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)
|
|
|
|
# trim and fade start
|
|
|
|
if start / 1000 < 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
|
|
fade_in = 2
|
|
fade_out = 2
|
|
|
|
# trim and fade end (to be continued)
|
|
|
|
|
|
|
|
# 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) |