badl/backend/__init__.py
2023-03-04 18:18:39 +08:00

44 lines
865 B
Python

from bottle import request, response, Bottle, static_file
from manager import Manager
from json import dumps
from pathlib import Path
from tkinter import filedialog as fd
manager = Manager()
app = Bottle()
@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")
@app.post("/video")
def add_videos():
nvlist = request.json["nvlist"].split()
manager.add_videos_by_number(nvlist)
return "OK"
@app.get("/progress")
def get_progress():
response.content_type = "application/json"
return dumps(manager.get_progress())
@app.get("/download")
def download():
manager.download()
return "OK"
@app.get("/path")
def get_path():
path = fd.askdirectory()
manager.path = path
return path