45 lines
953 B
Python
45 lines
953 B
Python
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) |