mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-05-07 08:12:47 +08:00
- 实现本地视频上传和处理功能 - 新增 LocalDownloader 类处理本地视频 - 更新前端界面支持本地视频选择 - 添加视频封面提取和保存功能 - 优化后端路由支持本地视频上传
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
import os
|
||
|
||
import uvicorn
|
||
from starlette.staticfiles import StaticFiles
|
||
from dotenv import load_dotenv
|
||
|
||
from app.db.model_dao import init_model_table
|
||
from app.db.provider_dao import init_provider_table
|
||
from app.utils.logger import get_logger
|
||
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
|
||
|
||
logger = get_logger(__name__)
|
||
load_dotenv()
|
||
|
||
# 读取 .env 中的路径
|
||
static_path = os.getenv('STATIC', '/static')
|
||
out_dir = os.getenv('OUT_DIR', './static/screenshots')
|
||
|
||
# 自动创建本地目录(static 和 static/screenshots)
|
||
static_dir = "static"
|
||
uploads_dir = "uploads"
|
||
if not os.path.exists(static_dir):
|
||
os.makedirs(static_dir)
|
||
if not os.path.exists(uploads_dir):
|
||
os.makedirs(uploads_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")
|
||
app.mount("/uploads", StaticFiles(directory=uploads_dir), name="uploads")
|
||
async def startup_event():
|
||
register_handler()
|
||
@app.on_event("startup")
|
||
async def startup_event():
|
||
register_handler()
|
||
ensure_ffmpeg_or_raise()
|
||
get_transcriber(transcriber_type=os.getenv("TRANSCRIBER_TYPE","fast-whisper"))
|
||
init_video_task_table()
|
||
init_provider_table()
|
||
init_model_table()
|
||
|
||
if __name__ == "__main__":
|
||
port = int(os.getenv("BACKEND_PORT", 8000))
|
||
host = os.getenv("BACKEND_HOST", "0.0.0.0")
|
||
logger.info(f"Starting server on {host}:{port}")
|
||
uvicorn.run("main:app", host=host, port=port, reload=False) |