👷🏽‍♂️ use send_from_directory's download_name

fixes #3.
stable
neingeist 2 years ago
parent 59a7fbdd82
commit 390a53186a

@ -21,7 +21,7 @@ app.config.from_object(Config)
app.config['WTF_I18N_ENABLED'] = False # enables WTForms built-in translations
bootstrap = Bootstrap(app)
attachment_filenames = {}
download_filenames = {}
class DownloadForm(FlaskForm):
@ -48,8 +48,8 @@ def download():
form.length.data = 60
elif form.validate_on_submit():
try:
output_filename, attachment_filename = prepare_download(form)
attachment_filenames[output_filename] = attachment_filename
output_filename, download_filename = prepare_download(form)
download_filenames[output_filename] = download_filename
flash('Der Download sollte sofort starten.', 'success')
return render_template('download.html', form=form, filename=output_filename)
except ValueError as e:
@ -73,14 +73,14 @@ def clean_out_dir():
def download_file(filename):
"""Download an output file"""
if filename not in attachment_filenames:
if filename not in download_filenames:
abort(404)
attachment_filename = attachment_filenames.pop(filename)
download_filename = download_filenames.pop(filename)
clean_out_dir()
return send_from_directory(app.config['OUT_DIR'], filename,
as_attachment=True, attachment_filename=attachment_filename)
download_name=download_filename, as_attachment=True)
def prepare_download(form):
@ -123,7 +123,7 @@ def prepare_download(form):
# Let ffmpeg do the rest of the job
_, output_filename = mkstemp(prefix='prolefeeder', suffix='.mp3', dir=app.config['OUT_DIR'])
output_filename = os.path.basename(output_filename)
attachment_filename = '{}_{}.mp3'.format(form.start_time.data, form.length.data)
download_filename = '{}_{}.mp3'.format(form.start_time.data, form.length.data)
c = [
'ffmpeg', '-y',
@ -137,7 +137,7 @@ def prepare_download(form):
app.logger.debug(' '.join(c))
subprocess.call(c)
return output_filename, attachment_filename
return output_filename, download_filename
if __name__ == '__main__':

Loading…
Cancel
Save