mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-05-07 05:32:52 +08:00
- 新增 events 模块,包括 handlers 和 signals 子模块 - 在 handlers 中实现 cleanup_temp_files 函数,用于清理转写临时文件 - 在 signals 中定义 transcription_finished 信号 - 修改 main.py,添加 startup_event 函数以注册事件处理器- 更新 WhisperTranscriber 类,增加 on_finish 方法并发送转写完成信号 - 在 base.py 中添加 TranscriberBase 类的 on_finish 方法占位符
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
import os
|
||
|
||
import uvicorn
|
||
from starlette.staticfiles import StaticFiles
|
||
from dotenv import load_dotenv
|
||
|
||
from app import create_app
|
||
from app.db.video_task_dao import init_video_task_table
|
||
from app.transcriber.transcriber_provider import get_transcriber
|
||
from events import register_handler
|
||
from ffmpeg_helper import ensure_ffmpeg_or_raise
|
||
|
||
load_dotenv()
|
||
|
||
# 读取 .env 中的路径
|
||
static_path = os.getenv('STATIC', '/static')
|
||
out_dir = os.getenv('OUT_DIR', './static/screenshots')
|
||
|
||
# 自动创建本地目录(static 和 static/screenshots)
|
||
static_dir = "static"
|
||
if not os.path.exists(static_dir):
|
||
os.makedirs(static_dir)
|
||
|
||
if not os.path.exists(out_dir):
|
||
os.makedirs(out_dir)
|
||
|
||
app = create_app()
|
||
app.mount(static_path, StaticFiles(directory=static_dir), name="static")
|
||
|
||
async def startup_event():
|
||
register_handler()
|
||
@app.on_event("startup")
|
||
async def startup_event():
|
||
register_handler()
|
||
ensure_ffmpeg_or_raise()
|
||
get_transcriber()
|
||
init_video_task_table()
|
||
|
||
if __name__ == "__main__":
|
||
port = int(os.getenv("BACKEND_PORT", 8000))
|
||
|
||
host = os.getenv("BACKEND_HOST", "0.0.0.0")
|
||
uvicorn.run("main:app", host=host, port=port, reload=True) |