👷🏻♀️ make sources something to configure
This commit is contained in:
parent
488ae1aa71
commit
40e1f51faf
3 changed files with 43 additions and 25 deletions
|
@ -86,24 +86,9 @@ def download_file(filename):
|
|||
def prepare_download(form):
|
||||
"""Prepare a download given the user's request form"""
|
||||
|
||||
def start_time_for_source_fn(fn):
|
||||
return datetime.strptime(fn, 'qfhi-%Y%m%d-%H%M.mp3')
|
||||
|
||||
def length_for_source_fn(fn):
|
||||
size = os.stat(os.path.join(app.config['DATA_DIR'], fn)).st_size
|
||||
length = timedelta(minutes=size / (1000*app.config['KBITS']/8) / 60)
|
||||
return length
|
||||
|
||||
# Get a sorted list of all source files with start time and length
|
||||
sources = []
|
||||
for fn in os.listdir(app.config['DATA_DIR']):
|
||||
try:
|
||||
start_time = start_time_for_source_fn(fn)
|
||||
length = length_for_source_fn(fn)
|
||||
sources.append({'fn': fn, 'start_time': start_time, 'length': length})
|
||||
except ValueError:
|
||||
pass
|
||||
sources = sorted(sources, key=lambda s: s['start_time'])
|
||||
sources = sorted(Config.SOURCES, key=lambda s: s['start_time'])
|
||||
print(sources)
|
||||
|
||||
# Only interested in the source files from the start file
|
||||
start_index = None
|
||||
|
@ -128,8 +113,7 @@ def prepare_download(form):
|
|||
c = [
|
||||
'ffmpeg', '-y',
|
||||
'-ss', str(ss),
|
||||
'-i', 'concat:' + '|'.join(
|
||||
[os.path.join(app.config['DATA_DIR'], s['fn']) for s in sources]),
|
||||
'-i', 'concat:' + '|'.join(s['fn'] for s in sources),
|
||||
'-codec', 'copy',
|
||||
'-t', str(form.length.data * 60),
|
||||
os.path.join(app.config['OUT_DIR'], output_filename)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue