badl/backend/__init__.py

47 lines
926 B
Python
Raw Normal View History

2023-03-04 18:18:39 +08:00
from bottle import request, response, Bottle, static_file
2023-02-21 19:56:22 +08:00
from manager import Manager
from json import dumps
2023-03-05 00:17:20 +08:00
import webview
2023-02-21 19:56:22 +08:00
manager = Manager()
app = Bottle()
2023-03-04 18:18:39 +08:00
@app.get("/")
def frontend():
return static_file("index.html", root="frontend/dist")
@app.get("/<filepath:path>")
def frontend(filepath):
return static_file(filepath, root="frontend/dist")
2023-02-21 19:56:22 +08:00
@app.post("/video")
def add_videos():
2023-02-23 21:43:58 +08:00
nvlist = request.json["nvlist"].split()
manager.add_videos_by_number(nvlist)
2023-02-21 19:56:22 +08:00
return "OK"
@app.get("/progress")
def get_progress():
response.content_type = "application/json"
return dumps(manager.get_progress())
2023-03-04 18:18:39 +08:00
@app.get("/download")
2023-02-21 19:56:22 +08:00
def download():
2023-03-04 18:18:39 +08:00
manager.download()
2023-03-04 13:53:05 +08:00
return "OK"
2023-03-04 18:18:39 +08:00
2023-03-05 00:17:20 +08:00
@app.get("/path")
2023-03-04 18:18:39 +08:00
def get_path():
2023-03-05 00:26:02 +08:00
result = webview.active_window().create_file_dialog(
dialog_type=webview.FOLDER_DIALOG
)
2023-03-05 00:17:20 +08:00
if result:
manager.path = result[0]
2023-03-05 00:06:04 +08:00
return manager.path