forked from ftarlao/check-media-integrity
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
executable file
·60 lines (48 loc) · 1.89 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/local/bin/python3
from flask import Flask, render_template, request, redirect, url_for, Response, stream_with_context, send_file
import os
import subprocess
app = Flask(__name__)
# Define the paths
BASE_PATH = '/media/videos'
CSV_PATH = '/app/logs'
def list_folders(path):
folders = []
for entry in os.scandir(path):
if entry.is_dir():
subfolders = list_folders(entry.path)
folders.append({
'name': entry.name,
'path': entry.path,
'subfolders': subfolders
})
return folders
def list_csv_files(path):
return [entry.name for entry in os.scandir(path) if entry.is_file() and entry.name.endswith('.csv')]
@app.route('/', methods=['GET', 'POST'])
def index():
folders = list_folders(BASE_PATH)
csv_files = list_csv_files(CSV_PATH)
if request.method == 'POST':
selected_folders = request.form.getlist('folders')
return redirect(url_for('stream_output', folders=selected_folders))
return render_template('index.html', folders=folders, csv_files=csv_files, command_output="")
@app.route('/stream')
def stream_output():
selected_folders = request.args.getlist('folders')
command = ['/app/check_mi.py', '-m', '-r'] + selected_folders
def generate():
with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) as process:
for line in process.stdout:
yield f"data: {line}\n\n"
for line in process.stderr:
yield f"data: {line}\n\n"
process.wait()
return Response(stream_with_context(generate()), mimetype='text/event-stream')
@app.route('/csv')
def csv_viewer():
file_name = request.args.get('file')
file_path = os.path.join(CSV_PATH, file_name)
return send_file(file_path)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True, port=5566)