server.py
1.5 KB
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
61
62
63
64
import time
from flask import Flask, request, render_template_string
import convert_webp_2_mp4
app = Flask(__name__)
# 定义 HTML 页面模板
HTML_TEMPLATE = """
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Simple Form</title>
</head>
<body>
<h1>输入表单</h1>
<form method="POST" action="/submit">
<label for="input1">命令:</label>
<input type="text" id="input1" name="input1" placeholder="输入目录名或文件名"><br><br>
<input type="text" id="input2" name="input2" placeholder="crf(1-35,越高质量越差,文件越小)"><br><br>
<button type="submit">提交</button>
</form>
{% if output %}
<h2>命令输出:</h2>
<pre>{{ output }}</pre>
{% endif %}
</body>
</html>
"""
# 处理用户提交的函数
def on_user_submit(file_or_dir,crf):
convert_webp_2_mp4.p_crf = crf
convert_webp_2_mp4.check_file_or_dir(f"mp4gift/{file_or_dir}",f"crf-{crf}-{time.time()}")
return "转换完成"
# 首页路由
@app.route('/')
def index():
return render_template_string(HTML_TEMPLATE)
# 提交处理路由
@app.route('/submit', methods=['POST'])
def submit():
# 获取用户输入的命令
file_or_dir = request.form.get('input1')
crf = request.form.get('input2')
# 调用处理函数
output = on_user_submit(file_or_dir, crf)
# 将输出渲染到页面
return render_template_string(HTML_TEMPLATE, output=output)
if __name__ == '__main__':
app.run(port=5000,host="0.0.0.0")