parent
							
								
									59a7fbdd82
								
							
						
					
					
						commit
						390a53186a
					
				
					 1 changed files with 8 additions and 8 deletions
				
			
		| 
						 | 
					@ -21,7 +21,7 @@ app.config.from_object(Config)
 | 
				
			||||||
app.config['WTF_I18N_ENABLED'] = False  # enables WTForms built-in translations
 | 
					app.config['WTF_I18N_ENABLED'] = False  # enables WTForms built-in translations
 | 
				
			||||||
bootstrap = Bootstrap(app)
 | 
					bootstrap = Bootstrap(app)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
attachment_filenames = {}
 | 
					download_filenames = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class DownloadForm(FlaskForm):
 | 
					class DownloadForm(FlaskForm):
 | 
				
			||||||
| 
						 | 
					@ -48,8 +48,8 @@ def download():
 | 
				
			||||||
        form.length.data = 60
 | 
					        form.length.data = 60
 | 
				
			||||||
    elif form.validate_on_submit():
 | 
					    elif form.validate_on_submit():
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            output_filename, attachment_filename = prepare_download(form)
 | 
					            output_filename, download_filename = prepare_download(form)
 | 
				
			||||||
            attachment_filenames[output_filename] = attachment_filename
 | 
					            download_filenames[output_filename] = download_filename
 | 
				
			||||||
            flash('Der Download sollte sofort starten.', 'success')
 | 
					            flash('Der Download sollte sofort starten.', 'success')
 | 
				
			||||||
            return render_template('download.html', form=form, filename=output_filename)
 | 
					            return render_template('download.html', form=form, filename=output_filename)
 | 
				
			||||||
        except ValueError as e:
 | 
					        except ValueError as e:
 | 
				
			||||||
| 
						 | 
					@ -73,14 +73,14 @@ def clean_out_dir():
 | 
				
			||||||
def download_file(filename):
 | 
					def download_file(filename):
 | 
				
			||||||
    """Download an output file"""
 | 
					    """Download an output file"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if filename not in attachment_filenames:
 | 
					    if filename not in download_filenames:
 | 
				
			||||||
        abort(404)
 | 
					        abort(404)
 | 
				
			||||||
    attachment_filename = attachment_filenames.pop(filename)
 | 
					    download_filename = download_filenames.pop(filename)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    clean_out_dir()
 | 
					    clean_out_dir()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return send_from_directory(app.config['OUT_DIR'], filename,
 | 
					    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):
 | 
					def prepare_download(form):
 | 
				
			||||||
| 
						 | 
					@ -123,7 +123,7 @@ def prepare_download(form):
 | 
				
			||||||
    # Let ffmpeg do the rest of the job
 | 
					    # Let ffmpeg do the rest of the job
 | 
				
			||||||
    _, output_filename = mkstemp(prefix='prolefeeder', suffix='.mp3', dir=app.config['OUT_DIR'])
 | 
					    _, output_filename = mkstemp(prefix='prolefeeder', suffix='.mp3', dir=app.config['OUT_DIR'])
 | 
				
			||||||
    output_filename = os.path.basename(output_filename)
 | 
					    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 = [
 | 
					    c = [
 | 
				
			||||||
        'ffmpeg', '-y',
 | 
					        'ffmpeg', '-y',
 | 
				
			||||||
| 
						 | 
					@ -137,7 +137,7 @@ def prepare_download(form):
 | 
				
			||||||
    app.logger.debug(' '.join(c))
 | 
					    app.logger.debug(' '.join(c))
 | 
				
			||||||
    subprocess.call(c)
 | 
					    subprocess.call(c)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return output_filename, attachment_filename
 | 
					    return output_filename, download_filename
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue