The video side gets its OWN automations at music-side parity, kept separate so
nothing on the music side breaks. First twin: Scan Video Library — tells the media
server to rescan the user's SELECTED video sections (movies/TV, never music), then
reads the result into video.db so freshly-downloaded media shows as owned.
Architecture (scope tags + video twins on the shared engine):
- Handler core/automation/handlers/video_scan_library.py — pure function with
injected I/O (server_refresh / run_video_scan); production lazily binds
refresh_video_server_sections() + the video scanner. Owns its own progress.
Lives on the SHARED automation side so it may import core.video (isolation only
forbids core/video & api/video from importing music, not the reverse).
- blocks.py gains a 'scope' tag ('both' generic / 'video' video-only / absent=music)
+ blocks_for_scope(). The music /api/automations/blocks now filters out video
blocks; new isolated /api/video/automations/blocks serves the video palette.
- automation_engine seeds 'Scan Video Library' (owned_by='video', schedule 6h) so
it appears ONLY on the video Automations page; ensure_system_automations now
honours owned_by + action_config. Music page excludes owned_by='video' rows.
kettui: seam-level tests for every handler path (happy/no-server/scan-error/never-
raises/mode), scope filtering (music excludes video, video gets generics, music
parity preserved), seeding (owned_by + mode), registration drift guard. 39 new
tests; full automation suite (288) + isolation guards green.
71 lines
2.4 KiB
Python
71 lines
2.4 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
|
|
from .scan import register_routes as reg_scan
|
|
from .library import register_routes as reg_library
|
|
from .libraries import register_routes as reg_libraries
|
|
from .poster import register_routes as reg_poster
|
|
from .enrichment import register_routes as reg_enrichment
|
|
from .detail import register_routes as reg_detail
|
|
from .search import register_routes as reg_search
|
|
from .discover import register_routes as reg_discover
|
|
from .calendar import register_routes as reg_calendar
|
|
from .watchlist import register_routes as reg_watchlist
|
|
from .wishlist import register_routes as reg_wishlist
|
|
from .youtube import register_routes as reg_youtube
|
|
from .downloads import register_routes as reg_downloads
|
|
from .automations import register_routes as reg_automations
|
|
reg_dashboard(bp)
|
|
reg_scan(bp)
|
|
reg_library(bp)
|
|
reg_libraries(bp)
|
|
reg_poster(bp)
|
|
reg_enrichment(bp)
|
|
reg_detail(bp)
|
|
reg_search(bp)
|
|
reg_discover(bp)
|
|
reg_calendar(bp)
|
|
reg_watchlist(bp)
|
|
reg_wishlist(bp)
|
|
reg_youtube(bp)
|
|
reg_downloads(bp)
|
|
reg_automations(bp)
|
|
|
|
return bp
|