'MAX_CONTENT_LENGTH': 50 * 1024 * 1024,
'BOOTSTRAP_SERVE_LOCAL': True,
'BOOTSTRAP_QUERYSTRING_REVVING': True,
+ 'ALLOWED_EXTENSIONS' : ['mp3', 'ogg'],
})
app.config.from_envvar('FEMTOBLACK_SETTINGS', silent=True)
@app.route('/')
def index():
- files = [p.name for p in pathlib.Path(app.config['UPLOAD_FOLDER']).iterdir() if p.is_file()]
+ """Affiche la liste des fichiers `.ogg` pour lesquel nous avons un
+ fichier `.json` a côté (fichier d’analyse).
+
+ """
+ files = []
+
+ for p in pathlib.Path(app.config['UPLOAD_FOLDER']).iterdir():
+ (filename, ext) = os.path.splitext(p.name)
+ json_file = os.path.join(app.config['UPLOAD_FOLDER'], "{}.json".format(p.name))
+
+ if p.is_file() and ext[1:] in app.config['ALLOWED_EXTENSIONS'] and os.path.exists(json_file):
+ files.append(p.name)
+
return render_template('index.html', files=files)
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
def allowed_file(filename):
- ALLOWED_EXTENSIONS = ['mp3', 'ogg']
- return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
+ return '.' in filename and filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS']
if request.method == 'POST':
f = request.files['file']