Detect course roots per branch and add a category layer above them
The scanner no longer assumes courses sit at a fixed depth. It walks each branch and marks a folder is_course when it holds media directly or its children read as chapters (01_, 1. , Module 2, Week 3); everything above that is a category, and every folder still gets a course_id pointing at its nearest course for cheap rollups. An empty .course/.category marker file overrides the heuristic per folder. Also: - Roll up progress for the whole library in two grouped queries instead of one prefix-matched query per course/folder card. - Store folders/videos/quizzes paths as utf8mb4_bin so folders that differ only in case (CCNP Notes vs CCNP NOtes) aren't merged by a case-insensitive UNIQUE key. - migrateLibrarySchema() brings an older install's tables up to date at scan time, so there's no separate migration step. - Library UI gains a categories view alongside shelves/catalog; the continue-watching strip's play button now seeks to the saved position on open. Claude-Session: https://claude.ai/code/session_01FfMPJK7TQV18JhFv6yTKev
This commit is contained in:
+21
-4
@@ -31,18 +31,35 @@ CREATE TABLE IF NOT EXISTS app_meta (
|
||||
|
||||
-- One row per directory found under VIDEOS_ROOT.
|
||||
-- `path` is the relative path from VIDEOS_ROOT, e.g. "Course 1/Intro".
|
||||
--
|
||||
-- Paths are utf8mb4_bin: they identify a file on a case-sensitive filesystem,
|
||||
-- so "CCNP Notes" and "CCNP NOtes" are two directories, not one. Under the
|
||||
-- table's default (case-insensitive) collation the UNIQUE key merges them and
|
||||
-- the second tree silently overwrites the first.
|
||||
--
|
||||
-- `is_course` marks the folder the library shows as a course. Course roots sit
|
||||
-- at whatever depth the material happens to use — a top-level folder may be a
|
||||
-- category (Networking/Cisco/<course>) or a course in its own right — so the
|
||||
-- scanner works it out per branch rather than assuming a fixed depth; see
|
||||
-- markCourseRoots(). `course_id` is the nearest course at-or-above the folder
|
||||
-- (NULL for the categories above every course), which is what makes a course's
|
||||
-- rollup one grouped query instead of one query per course.
|
||||
CREATE TABLE IF NOT EXISTS folders (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
parent_id INT UNSIGNED NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
path VARCHAR(700) NOT NULL UNIQUE,
|
||||
path VARCHAR(700) COLLATE utf8mb4_bin NOT NULL UNIQUE,
|
||||
depth INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
sort_order INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
is_course TINYINT(1) NOT NULL DEFAULT 0,
|
||||
course_id INT UNSIGNED NULL,
|
||||
is_missing TINYINT(1) NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT fk_folders_parent FOREIGN KEY (parent_id)
|
||||
REFERENCES folders(id) ON DELETE CASCADE,
|
||||
INDEX idx_folders_parent (parent_id)
|
||||
INDEX idx_folders_parent (parent_id),
|
||||
INDEX idx_folders_course (course_id),
|
||||
INDEX idx_folders_is_course (is_course, is_missing)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS videos (
|
||||
@@ -50,7 +67,7 @@ CREATE TABLE IF NOT EXISTS videos (
|
||||
folder_id INT UNSIGNED NOT NULL,
|
||||
name VARCHAR(255) NOT NULL, -- display name, filename without .mp4
|
||||
filename VARCHAR(255) NOT NULL,
|
||||
path VARCHAR(700) NOT NULL UNIQUE, -- relative path incl. filename
|
||||
path VARCHAR(700) COLLATE utf8mb4_bin NOT NULL UNIQUE, -- relative path incl. filename
|
||||
size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
duration_seconds FLOAT NULL, -- filled in by the player on first load
|
||||
sort_order INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
@@ -69,7 +86,7 @@ CREATE TABLE IF NOT EXISTS quizzes (
|
||||
folder_id INT UNSIGNED NOT NULL,
|
||||
name VARCHAR(255) NOT NULL, -- filename without the _quiz_solved.txt suffix
|
||||
filename VARCHAR(255) NOT NULL,
|
||||
path VARCHAR(700) NOT NULL UNIQUE,
|
||||
path VARCHAR(700) COLLATE utf8mb4_bin NOT NULL UNIQUE,
|
||||
num_questions INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
sort_order INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
is_missing TINYINT(1) NOT NULL DEFAULT 0,
|
||||
|
||||
Reference in New Issue
Block a user