# Sanctuary Commander TODO Sanctuary Commander is the planned successor to Video Commander: a simple, web-based interface for managing sanctuary TVs and displaying dynamically added media. The current implementation provides the web interface, media storage, and an FFplay-based player with unified playback selection; device control is still future work. ## Completed foundations - [x] Set up a Flask web server with configuration loaded from `config.json`. - [x] Organize implemented pages into Flask blueprints. - [x] Build a Bootstrap-based home page with controls grouped into common tools, playback, and media submission. - [x] Create the configured upload directory automatically when the server starts. - [x] Upload named static images (up to 100MB) to the configurable `Images` folder, show progress and navigation warnings, and return home after saving the file and media record. - [x] Add browser-side upload progress reporting and basic upload error feedback. - [x] Implement stream registration with a display name and URL. - [x] Provide a SQLite database wrapper and a database initialization script. - [x] Define the media catalog and weighted playback-option tables. - [x] Add a YouTube download jobs table storing each URL and its status: `pending`, `downloading`, `downloaded`, or `failed`. - [x] Store an optional fullscreen playback flag for registered streams. - [x] Remove the old preparation and component tables and slideshow scaffolding; retain the media and playback-option tables and their existing records. ## Finish the current workflows - [x] Link the home page to a unified media library with Play buttons, live selection indicators, media-type icons, and cached local image/video thumbnails. - [x] Delete media with a confirmation step, removing records/playback options and unshared files in managed storage while preserving outside/shared sources. - [ ] Connect the existing placeholder controls to backend actions. - [x] Add input validation for media names, duplicate names, stream URLs, and uploaded files. - [ ] Ensure upload destinations remain inside the configured upload directory. - [x] Handle missing form fields, missing files, and storage/database failures with useful error messages. - [x] Close request-scoped database connections when requests finish. ## Playback and media preparation - [x] Implement fullscreen FFPlay-based playback with error-only FFplay logging. - [x] Display uploaded static images when selected as active or default media. - [x] Play registered stream URIs using the player. - [ ] Apply compatible stored playback options without overriding fullscreen or logging rules. - [x] Upload named local video files (up to 5GB) to the shared video storage folder, show upload progress and navigation warnings, and return home after saving. - [x] Play uploaded local video files when selected as active or default media. - [x] Download YouTube videos ahead of time for later playback using queued jobs. - [x] Implement a download worker that updates job status from `pending` to `downloading` to `downloaded` after the file is saved successfully. - [x] Store requested media names on jobs and register successful downloads in the media catalog using the final local file path. - [x] Configure download storage (default: `Videos`) and return failed attempts to pending for retry with logged errors. - [x] Add a web workflow for submitting YouTube URLs and desired media names. - [x] List pending, downloading, and failed jobs, with an opt-in checkbox to include completed jobs. - [x] Persist per-job retry counts and mark jobs failed once they exceed the configured retry limit (default: three retries after the initial attempt). - [ ] Add increasing retry backoff and recovery of jobs left downloading after a forced termination. - [ ] Design a new approach to media preparation tracking, including the role of the existing `media_preparing` flag; do not restore the old preparation table. - [ ] Implement background media preparation using the new tracking approach. - [ ] Surface preparation status in the web interface. - [x] Poll active/default media every two seconds, prioritizing active media and falling back to default media or a fullscreen black screen. - [x] Add web controls for changing active media atomically, with status matching the player's active/default priority. - [ ] Add web controls for changing default media. - [ ] Implement the Disable Video and Blackout Screen controls. - [ ] Detect USB media and make it available for playback. ## TV and device control - [ ] Integrate with Home Assistant. - [ ] Implement TV power controls. - [ ] Implement TV volume controls. - [ ] Implement TV input selection. - [ ] Connect the home-page TV controls to the integration. ## End goals and readiness - [ ] Provide one browser-based location for TV control and media playback. - [ ] Let users prepare and submit content dynamically rather than maintaining a static media configuration file. - [ ] Keep everyday operation simple for less technically experienced users. - [ ] Document installation, dependencies, configuration, and normal operation. - [ ] Add automated coverage for upload, stream-registration, preparation, playback, and device-control workflows as they are implemented. - [ ] Define appropriate access controls and a production deployment setup before exposing upload or device-control endpoints beyond a trusted environment.