From 390a53186ac7357ff4e864c004410f44b969b8ce Mon Sep 17 00:00:00 2001 From: neingeist Date: Sun, 5 Dec 2021 12:32:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=F0=9F=8F=BD=E2=80=8D=E2=99=82?= =?UTF-8?q?=EF=B8=8F=20use=20send=5Ffrom=5Fdirectory's=20download=5Fname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #3. --- prolefeeder.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/prolefeeder.py b/prolefeeder.py index d0cda23..5da0a0e 100644 --- a/prolefeeder.py +++ b/prolefeeder.py @@ -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__':