First wire from video.db -> UI, kettui-style. - api/video/ : isolated Flask blueprint (registered at /api/video with one additive line in web_server.py). Reads only video.db; imports nothing from the music API or DB. - GET /api/video/dashboard -> VideoDatabase.dashboard_stats(): live library/ download/watchlist/wishlist counts (real 0s on an empty DB). - video-dashboard.js now fetches it and fills the stat cards + Watchlist/ Wishlist header badges (formatted bytes/speed); falls back to zeros on error. uptime/memory stay at markup defaults for now (not video-domain). - Tests: dashboard_stats counts (empty + populated), endpoint returns zeroed JSON via a Flask test client, blueprint exposes the route, and the video API imports nothing from music. 93 video/integrity tests green.
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
"""SoulSync — VIDEO side API package (isolated).
|
|
|
|
A SEPARATE Flask blueprint from the music API (api_v1). It reads only
|
|
database/video_library.db via VideoDatabase and imports nothing from the music
|
|
API or music database layer. Registered in web_server.py with a single additive
|
|
line at url_prefix '/api/video', so music routing is untouched.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import threading
|
|
|
|
from flask import Blueprint
|
|
|
|
from utils.logging_config import get_logger
|
|
|
|
logger = get_logger("video_api")
|
|
|
|
# Lazily-created, process-wide VideoDatabase handle. VideoDatabase itself guards
|
|
# schema init once-per-path, so this just avoids re-opening the wrapper.
|
|
_video_db = None
|
|
_video_db_lock = threading.Lock()
|
|
|
|
|
|
def get_video_db():
|
|
"""Return the shared VideoDatabase instance (created on first use)."""
|
|
global _video_db
|
|
if _video_db is None:
|
|
with _video_db_lock:
|
|
if _video_db is None:
|
|
from database.video_database import VideoDatabase
|
|
_video_db = VideoDatabase()
|
|
return _video_db
|
|
|
|
|
|
def create_video_blueprint() -> Blueprint:
|
|
"""Build the isolated /api/video blueprint with all video sub-routes."""
|
|
bp = Blueprint("video_api", __name__)
|
|
|
|
from .dashboard import register_routes as reg_dashboard
|
|
reg_dashboard(bp)
|
|
|
|
return bp
|