From eb6024573e002cba6d765b3eee166ecfa64c88f9 Mon Sep 17 00:00:00 2001 From: Quick <31828688+Quick104@users.noreply.github.com> Date: Sun, 7 Jun 2026 15:57:05 -0400 Subject: [PATCH] feat(audiobooks): make audiobook libraries first-class catalog items (#73) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * docs(audiobooks): design spec for plugin absorption Plan to absorb silo-plugin-audiobooks into silo-server as a first-party feature. Audiobooks land in silo's existing SPA; ABS clients connect directly. Hard constraints: reuse existing tables (media_items, media_files, user_watch_progress, user_playback_sessions, people, item_people, library_collections); only two new tables (abs_sessions, podcast_feeds) and at most one column add (media_libraries.kind); silo's main :8080 listener handles ABS Socket.io natively. Out of scope: audiobook requests flow, smart collections, share links, external recommender, custom metadata providers, separate audiobook SPA. Co-Authored-By: Claude Opus 4.7 (1M context) * docs(audiobooks): implementation plan sub-plan 1 (discovery + schema) First of six sub-plans for the absorption. Six tasks: a discovery audit that resolves the spec's Risk questions, four idempotent SQL migrations (abs_sessions, podcast_feeds, media_libraries.kind, audiobooks.enabled feature flag), and an empty-but-compiling internal/audiobooks package scaffolded into cmd/silo. Lands as a strict no-op for users (feature flag defaults to false). Co-Authored-By: Claude Opus 4.7 (1M context) * docs(audiobooks): discovery findings for absorption sub-plan 1 Locks schema/code decisions for migrations 139-142 and downstream sub-plans. Resolves open Risk questions from the absorption design spec. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): migration 139 add abs_sessions table Parallel of jellycompat_sessions for Audiobookshelf-compatible clients. Lets ABS mobile/desktop apps maintain a device-bound session that silo's audiobooks/abs handlers will validate. Co-Authored-By: Claude Opus 4.7 (1M context) * style(audiobooks): match codebase conventions in migration 139 Lowercases type keywords in the abs_sessions CREATE TABLE body to match neighboring migrations, fixes the client_version column alignment, and replaces the misleading "parallel to jellycompat_sessions" header comment with a more accurate description of the table's role. Cosmetic only — the running schema is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): migration 140 add podcast_feeds table Side table on media_items for RSS-subscribed podcasts. Holds feed URL, ETag/Last-Modified for conditional fetches, last-refresh timestamp, and the per-feed refresh interval consumed by the upcoming podcastfeed.Refresher scheduled task. Co-Authored-By: Claude Opus 4.7 (1M context) * style(audiobooks): uppercase PRIMARY KEY in migration 140 Aligns with the codebase convention (type keywords lowercase, constraint keywords uppercase) established in migration 139's post-style-fix form. Cosmetic only — running schema is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) * chore(audiobooks): migration 141 no-op for media_folders.type Sub-plan 1 originally reserved migration 141 to add a 'kind' column to media_libraries discriminating audiobook/podcast libraries. Discovery audit (sub-plan 1 Task 1) found that the actual table is media_folders and it already has a type text NOT NULL column with no CHECK constraint or enum, so 'audiobooks' and 'podcasts' can be added as future values without DDL. Landing this migration as a documented no-op preserves the version numbering audit trail and pins the decision in git history. The matching down migration is also a no-op. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): migration 142 add audiobooks.enabled flag Server-settings row that gates the absorbed audiobooks feature. Defaults to 'false' so sub-plan 1 lands as a strict no-op; subsequent sub-plans branch on this flag and operators flip it to 'true' at cutover. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): scaffold internal/audiobooks package Empty-but-compiling Service that reads the audiobooks.enabled feature flag from server_settings. Wired into cmd/silo so the package is referenced from the binary; no routes mounted, no scheduled tasks registered, no DB writes. Subsequent sub-plans hang scanner branches, ABS handlers, Socket.io, podcast refresher, and SPA pages off this Service. Co-Authored-By: Claude Opus 4.7 (1M context) * style(audiobooks): cosmetic cleanups in scaffolded package Two pre-emptive cleanups flagged by code review before sub-plan 2 copies the patterns: 1. Sort the internal/audiobooks import after internal/adminjob in cmd/silo/main.go (alphabetical). 2. Drop the redundant "audiobooks: " prefix from the Enabled() error wrap; matches how every other top-level service package (watchstate, scanqueue, metadata, etc.) formats errors. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) * docs(audiobooks): implementation plan sub-plan 2 (scanner) Second of six sub-plans. 10 tasks: PersonKind constants for Author and Narrator, audio-extension recognizer, library-type helpers, a walkLogicalTree refactor (movieLibrary bool -> typed walkMode), chapter extraction via ffprobe, single-file and multi-file audiobook parsers, scanner write path producing media_items.type='audiobook', and a filesystem podcast parser (RSS deferred to sub-plan 5). Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): add Author and Narrator PersonKind constants Discovery audit confirmed item_people.kind is unconstrained smallint with values 1-6 in use. Reserve 7 = Author, 8 = Narrator for audiobook people-links written by the upcoming scanner branches. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): add audio-extension recognizer for scanner Mirrors the existing videoExtensions/SupportsVideoFile pair. Used by upcoming audiobook and podcast scanner branches to filter directory walks. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): library-type recognizers for scanner dispatch isAudiobookLibraryType and isPodcastLibraryType match singular and plural forms case-insensitively, mirroring isMovieLibraryType. Used by upcoming scanner walk branches (Task 4) that filter audio files into audiobook and podcast libraries. Co-Authored-By: Claude Opus 4.7 (1M context) * refactor(scanner): replace movieLibrary bool with typed walkMode Lets walkLogicalTree dispatch on multiple library shapes (video, movie, audiobook, podcast) without proliferating boolean flags. Behavior for existing video and movie libraries is unchanged; audiobook and podcast modes will be consumed by the upcoming audiobook.go and podcast.go parsers in later tasks of this sub-plan. walkModeFor() derives the mode from a media_folders.type string; unknown types default to walkModeVideo to preserve prior behavior for any caller still passing a raw type. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): expose ffprobe format tags on ProbeData The audiobook scanner needs format-level tags (title, artist, album, date) for media_items metadata; ffprobe already parses them in ffprobeFormat.Tags but ProbeData previously discarded them. Add FormatTags map[string]string to ProbeData, populate it in convertProbeData via a new normalizeFormatTags helper that lowercases keys and trims values. Adds a fixture audiobook .m4b with embedded chapters (Intro/Outro) and format tags, and a test that verifies ProbeFile() returns both correctly. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): parser for single-file audiobook folders parseAudiobookFolder reads tags + chapters via the existing ProbeFile (now that Task 5 exposes FormatTags on ProbeData) and produces a parsedAudiobook struct. Title falls back from "title" tag to "album"; author from "artist" -> "album_artist" -> "composer"; series from "album" -> "series" -> "mvnm" (Movement Name, used by some MP4 tools). Year parsed from "date" or "year" tags, tolerating ISO dates and parenthesized forms. Single-file case only; multi-file folders (one audio file per chapter) return a placeholder error and arrive in Task 7. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): multi-file audiobook folder support Folders containing N audio files (one per chapter/part) get one parsedAudiobookFile per file; each file's chapter list is synthesized as a single chapter with title = filename stem. Title/author/series/ year come from the first file's tags. Also drops the duplicate pickFirstNonEmpty helper added in Task 6 in favor of the existing firstNonEmpty already in probe.go. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): scanner write path produces audiobook media_items ScanAudiobookFolder walks an audiobooks-typed media folder and treats each immediate subdirectory as one audiobook. For each parsed audiobook it upserts: - one media_items row with type='audiobook' - one media_files row per audio file (with chapters JSONB) - author/narrator links in item_people (kind=7, kind=8) Adds itemRepo and personRepo to the Scanner struct, wired from fileRepo.Pool() in NewScanner — no constructor signature change needed. ScanFolder dispatches to this path when folder.Type='audiobooks', bypassing the per-file movie/TV pipeline because audiobooks are folder-scoped entities. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): filesystem podcast scanner ScanPodcastFolder walks a podcasts-typed media folder, treating each subdirectory as a podcast show and each audio file inside as an episode. Writes media_items.type='podcast' + episodes rows + media_files rows. RSS-subscribed feeds (podcast_feeds table) arrive in sub-plan 5; this task covers filesystem-only ingestion. ScanFolder dispatches to this path when folder.Type='podcasts'. Co-Authored-By: Claude Opus 4.7 (1M context) * docs(audiobooks): implementation plan sub-plan 5 (podcasts) Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): expose audiobooks/podcasts library types in admin UI Adds 'Audiobooks' and 'Podcasts' options to the library-type dropdown in the admin libraries page so operators can flag a folder as an audiobook or podcast library. Extends contentLevelsForType() so the admin UI's downstream filtering treats those types correctly (audiobook -> ['audiobook'], podcasts -> ['podcast', 'podcast_episode']). Backend scanner branches for these types were already wired in sub-plan 2. Co-Authored-By: Claude Opus 4.7 (1M context) * chore(migrations): renumber 139_abs_sessions to 147 for origin/main merge origin/main adds 139_media_requests at the same number our local audiobook branch had used for abs_sessions. Renumber ours to 147 to free up 139 for the upstream migration. The schema_versions row is updated in lockstep on the running database so the migrator sees the abs_sessions migration as already applied at its new version. Migrations 140-146 (podcast feeds, media_folders kind noop, audiobook feature flag, abs playback sessions, podcast episode guid, audiobook series, audiobook title cleanup) stay where they are — they don't collide with anything on origin/main. Co-Authored-By: Claude Opus 4.7 (1M context) * chore(migrations): renumber 140_podcast_feeds to 157 for origin/main merge origin/main added 140_user_permissions at the same version this branch had used for podcast_feeds. Renumber ours to 157 (next free above the collections-unify migration at 156) so 140 is free for the upstream migration. schema_versions on the running database is updated in lockstep so the migrator sees podcast_feeds as already applied at its new version. Same pattern as d59c1cb (renumber 139_abs_sessions to 147 for the prior main merge). Pending migrations after this rename: 132 (downloaded subtitles admin index, main), 140 (user_permissions, main), and 156 (unify_user_collections, this branch). Co-Authored-By: Claude Opus 4.7 (1M context) * chore(migrations): renumber 141_media_folders_kind_noop to 159 for origin/main merge Same shape as eb8f67d (the 140→157 renumber from the previous main merge). origin/main added 141_episode_title_sort_index at the same version this branch had used for media_folders_kind_noop. Renumber ours to 159 (next free above the audiobook_series truncate at 158) so 141 is open for the upstream migration. schema_versions on the running database is updated in lockstep so the migrator sees media_folders_kind_noop as already applied at its new version. Pending migrations on silo-prod after this rename: 141 (episode_title_sort_index, main) and any other newer ones from main that the branch hasn't picked up yet. Co-Authored-By: Claude Opus 4.7 (1M context) * chore(migrations): renumber 142_audiobooks_feature_flag to 160 for origin/main merge Companion to 3c6f062's 141 renumber — origin/main also added 142_episode_catalog_entries (alongside 141_episode_title_sort_index) at a version this branch had used for the audiobooks feature flag. Renumber ours to 160 so 142 is open for the upstream migration; schema_versions on silo-prod is updated in lockstep so the migrator sees audiobooks_feature_flag as already applied at its new version. This was the only remaining collision (verified by checking for duplicate version prefixes across migrations/). Co-Authored-By: Claude Opus 4.7 (1M context) * fix(audiobooks): address foundation review comments * fix(audiobooks): tighten scanner identity handling * fix(audiobooks): propagate scanner cancellation * chore(audiobooks): adopt goose migration layout * docs(audiobooks): implementation plan sub-plan 3 (API + frontend MVP) Third of six sub-plans. 9 tasks: three REST endpoints (list/detail/ progress), TanStack Query hooks + types, three React pages (Library/Detail/Player), and navigation integration. Scoped to MVP — author/series indices, smart collections, share links, and other nice-to-haves from the spec are deferred. Streaming reuses silo's existing /api/v1/stream/{session_id}; no new transcode code. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): list endpoint at GET /api/v1/audiobooks Paginated list of media_items with type='audiobook' scoped to the caller's accessible libraries via the existing access filter. Mirrors silo's existing list-style handlers for movies and series. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): detail endpoint at GET /api/v1/audiobooks/{id} Returns the media_items row, its media_files (with chapters JSONB), author/narrator extracted from item_people (kinds 7/8), and the caller's per-profile listening progress from user_watch_progress. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): progress endpoint at POST /api/v1/audiobooks/{id}/progress UPSERTs user_watch_progress for the caller's (user_id, profile_id, content_id). Body carries position_seconds; clients are expected to post every 5-10s during playback plus on pause/seek (matching silo's existing video progress cadence). Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): frontend types and TanStack Query hooks TypeScript types match the JSON shapes from the new /api/v1/audiobooks endpoints (list, detail, progress). Three hooks: useAudiobookLibrary (list), useAudiobook (detail), and useReportAudiobookProgress (mutation that invalidates the detail query on success so progress updates reflect immediately). Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): library grid page at /audiobooks Renders a paginated grid of audiobook cards using the useAudiobookLibrary hook. Each card links to /audiobooks/book/{id}. Cards show poster, title, and year; falls back to a "No cover" placeholder when the audiobook has no poster_url. Empty state hints to operators that they need to set a library's type to 'audiobooks'. Routes themselves are wired in Task 8 (navigation integration). Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): detail page with chapter list Renders cover, title, author, narrator, year, and overview alongside a chapter list. Clicking a chapter opens an inline sticky AudiobookPlayer at that chapter's start. A "Resume" button restarts playback at the saved progress position if present. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): HTML5 audio player with chapter navigation Single-file audiobook playback for MVP. Multi-file queuing arrives in a follow-up. Streams via the existing /api/v1/direct-download GET endpoint. Position is reported to /api/v1/audiobooks/{id}/progress every 10s while playing plus on pause/seek/end. Skip-30s, playback rate select, chapter list panel. Co-Authored-By: Claude Opus 4.7 (1M context) * feat(audiobooks): wire navigation and routes Adds an Audiobooks entry to the sidebar and registers the two new routes (/audiobooks for the library grid, /audiobooks/book/:id for detail). The player renders inline inside the detail page; no dedicated player route is required for MVP. Co-Authored-By: Claude Opus 4.7 (1M context) * fix(audiobooks): address native API review comments * feat(audiobooks): add ABS compatibility and polish * fix(audiobooks): stabilize ABS playback progress reporting * fix(audiobooks): clean up ABS branch review fixes * chore(audiobooks): adopt goose layout for ABS migrations * fix(audiobooks): align player seek bar props * feat(audiobooks): make libraries first-class catalog items * feat(admin): add server restart endpoint * fix(audiobooks): address review comment findings --------- Co-authored-by: RXWatcher <14085001+RXWatcher@users.noreply.github.com> Co-authored-by: Claude Opus 4.7 (1M context) --- Dockerfile | 2 +- cmd/silo/main.go | 151 +- docker-compose.yml | 3 + .../2026-05-27-abs-wire-shape-verification.md | 138 + .../plans/2026-05-24-audiobook-ui-redesign.md | 3072 +++++++++++++ ...udiobooks-absorption-1-discovery-schema.md | 916 ++++ ...6-05-24-audiobooks-absorption-2-scanner.md | 1075 +++++ ...udiobooks-absorption-3-api-and-frontend.md | 326 ++ .../2026-05-24-audiobooks-absorption-4-abs.md | 148 + ...-05-24-audiobooks-absorption-5-podcasts.md | 35 + ...2026-05-26-abs-bookmarks-implementation.md | 1596 +++++++ ...bs-collections-playlists-implementation.md | 4087 +++++++++++++++++ ...26-abs-phase-0-login-and-critical-fixes.md | 1778 +++++++ ...5-26-abs-phase1-closeout-implementation.md | 2068 +++++++++ ...26-abs-smart-collections-implementation.md | 2531 ++++++++++ ...6-05-27-audiobook-catalog-filter-fields.md | 187 + ...026-05-27-audiobook-series-data-cleanup.md | 123 + .../2026-05-27-catalog-facet-typeahead.md | 143 + .../2026-05-27-collections-unify-1-schema.md | 314 ++ ...5-27-collections-unify-2-smartcoll-lift.md | 274 ++ ...-05-27-collections-unify-3-abs-adapters.md | 515 +++ ...-27-collections-unify-4-section-recipes.md | 711 +++ .../2026-06-06-audiobooks-stacked-pr-split.md | 174 + ...026-05-24-audiobooks-discovery-findings.md | 153 + ...2026-05-24-audiobook-ui-redesign-design.md | 447 ++ ...2026-05-24-audiobooks-absorption-design.md | 382 ++ .../specs/2026-05-26-abs-bookmarks-design.md | 262 ++ ...-05-26-abs-collections-playlists-design.md | 523 +++ ...026-05-26-abs-implementation-fix-design.md | 384 ++ .../2026-05-26-abs-phase1-closeout-design.md | 344 ++ ...2026-05-26-abs-smart-collections-design.md | 377 ++ ...27-unified-audiobook-collections-design.md | 295 ++ go.mod | 23 + go.sum | 56 +- internal/api/handlers/catalog.go | 85 + internal/api/handlers/catalog_resources.go | 2 +- internal/api/handlers/libraries.go | 4 +- internal/api/handlers/library_collections.go | 7 + internal/api/handlers/server_control.go | 139 + internal/api/handlers/server_control_test.go | 156 + internal/api/router.go | 27 +- internal/audiobooks/abs/access_log.go | 96 + .../audiobooks/abs/author_series_handler.go | 92 + .../abs/author_series_handler_test.go | 103 + internal/audiobooks/abs/bookmarks.go | 54 + .../audiobooks/abs/bookmarks_envelope_test.go | 45 + internal/audiobooks/abs/bookmarks_handler.go | 182 + .../audiobooks/abs/bookmarks_handler_test.go | 511 +++ internal/audiobooks/abs/collapse.go | 86 + internal/audiobooks/abs/collections.go | 83 + .../abs/collections_envelope_test.go | 55 + .../audiobooks/abs/collections_handler.go | 435 ++ .../abs/collections_handler_test.go | 588 +++ .../abs/continue_listening_handler.go | 54 + .../abs/continue_listening_handler_test.go | 91 + internal/audiobooks/abs/extras_handlers.go | 255 + internal/audiobooks/abs/file_handler.go | 228 + .../abs/file_handler_public_track_test.go | 183 + internal/audiobooks/abs/filter.go | 135 + internal/audiobooks/abs/handler.go | 750 +++ internal/audiobooks/abs/items_handler.go | 182 + internal/audiobooks/abs/jwt.go | 91 + internal/audiobooks/abs/libraries_handler.go | 894 ++++ .../audiobooks/abs/libraries_metadata_test.go | 109 + .../audiobooks/abs/listening_stats_handler.go | 107 + .../abs/listening_stats_handler_test.go | 104 + internal/audiobooks/abs/login.go | 536 +++ .../audiobooks/abs/login_envelope_test.go | 147 + internal/audiobooks/abs/login_logout_test.go | 128 + internal/audiobooks/abs/login_ratelimit.go | 103 + .../audiobooks/abs/login_refresh_race_test.go | 164 + internal/audiobooks/abs/login_refresh_test.go | 249 + internal/audiobooks/abs/me_handler.go | 67 + internal/audiobooks/abs/minified.go | 100 + internal/audiobooks/abs/play_response.go | 528 +++ internal/audiobooks/abs/play_resume_test.go | 90 + internal/audiobooks/abs/playlists.go | 72 + .../audiobooks/abs/playlists_envelope_test.go | 61 + internal/audiobooks/abs/playlists_handler.go | 635 +++ .../audiobooks/abs/playlists_handler_test.go | 713 +++ internal/audiobooks/abs/progress.go | 442 ++ .../audiobooks/abs/progress_internal_test.go | 20 + internal/audiobooks/abs/rss_feeds.go | 42 + internal/audiobooks/abs/rss_feeds_handler.go | 239 + .../audiobooks/abs/rss_feeds_handler_test.go | 221 + internal/audiobooks/abs/smart_collections.go | 62 + .../abs/smart_collections_envelope_test.go | 48 + .../abs/smart_collections_handler.go | 416 ++ .../abs/smart_collections_handler_test.go | 385 ++ internal/audiobooks/abs/types.go | 212 + internal/audiobooks/abs_bookmark_store.go | 160 + internal/audiobooks/abs_collection_store.go | 236 + .../audiobooks/abs_playback_session_store.go | 269 ++ internal/audiobooks/abs_playlist_store.go | 247 + internal/audiobooks/abs_progress_store.go | 214 + internal/audiobooks/abs_rss_feed_store.go | 108 + internal/audiobooks/abs_session_store.go | 158 + .../audiobooks/abs_smart_collection_store.go | 136 + internal/audiobooks/abssocket/server.go | 226 + internal/audiobooks/abssocket/server_test.go | 98 + internal/audiobooks/access_resolver.go | 51 + internal/audiobooks/config.go | 94 + internal/audiobooks/cred_validator.go | 150 + internal/audiobooks/cred_validator_test.go | 68 + internal/audiobooks/doc.go | 10 + internal/audiobooks/enrichment.go | 712 +++ internal/audiobooks/enrichment_test.go | 126 + internal/audiobooks/media_store.go | 762 +++ internal/audiobooks/podcastfeed/refresher.go | 355 ++ .../audiobooks/podcastfeed/refresher_test.go | 285 ++ internal/audiobooks/podcastfeed/store.go | 144 + internal/audiobooks/recommender.go | 92 + internal/audiobooks/service.go | 194 + internal/audiobooks/service_test.go | 76 + internal/audiobooks/smartcoll/evaluator.go | 481 ++ .../audiobooks/smartcoll/evaluator_test.go | 143 + internal/audiobooks/smartcoll/query.go | 322 ++ internal/audiobooks/smartcoll/query_test.go | 115 + internal/auth/session.go | 13 +- internal/catalog/browse.go | 282 +- internal/catalog/catalog_parser.go | 2 +- internal/catalog/catalog_resolver.go | 233 +- internal/catalog/catalog_resolver_test.go | 32 +- internal/catalog/detail.go | 423 ++ internal/catalog/detail_audiobook_test.go | 42 + internal/catalog/item_repo.go | 22 + internal/catalog/query_builder.go | 66 + internal/catalog/query_builder_test.go | 120 + internal/catalog/query_definition.go | 13 +- internal/catalog/query_definition_test.go | 12 + internal/collections/templates/templates.go | 7 +- internal/config/config.go | 43 +- internal/config/db_loader.go | 10 + internal/config/db_loader_test.go | 18 + internal/imagecache/imagecache.go | 185 +- internal/imagecache/imagecache_test.go | 24 +- internal/metadata/plugin_provider.go | 4 + internal/models/media.go | 14 + internal/models/media_test.go | 18 + internal/playback/directplay.go | 12 + internal/recommendations/embeddings/text.go | 125 +- .../recommendations/embeddings/text_test.go | 31 + internal/recommendations/personal.go | 10 +- internal/recommendations/repo.go | 63 +- internal/recommendations/similar.go | 10 +- internal/scanner/audio_extensions.go | 26 + internal/scanner/audio_extensions_test.go | 25 + internal/scanner/audiobook.go | 254 + internal/scanner/audiobook_cover.go | 78 + internal/scanner/audiobook_scan.go | 913 ++++ internal/scanner/audiobook_test.go | 455 ++ internal/scanner/podcast.go | 97 + internal/scanner/podcast_scan.go | 250 + internal/scanner/podcast_test.go | 169 + internal/scanner/probe.go | 15 + internal/scanner/probe_audiobook_test.go | 54 + internal/scanner/scanner.go | 193 +- internal/scanner/scanner_test.go | 40 + .../audiobook_fixtures/multi_file/part1.mp3 | Bin 0 -> 20602 bytes .../audiobook_fixtures/multi_file/part2.mp3 | Bin 0 -> 20602 bytes .../audiobook_fixtures/multi_file/part3.mp3 | Bin 0 -> 20602 bytes .../audiobook_fixtures/single_book/book.m4b | Bin 0 -> 3318 bytes .../testdata/podcast_fixtures/show_a/ep1.mp3 | Bin 0 -> 12550 bytes .../testdata/podcast_fixtures/show_a/ep2.mp3 | Bin 0 -> 12550 bytes .../testdata/podcast_fixtures/show_a/ep3.mp3 | Bin 0 -> 12550 bytes internal/scanner/types.go | 1 + internal/sections/defaults.go | 8 + internal/sections/defaults_test.go | 62 + .../tasks/sync_audiobook_metadata.go | 53 + .../taskmanager/tasks/sync_podcast_feeds.go | 54 + migrations/sql/143_abs_playback_sessions.sql | 34 + migrations/sql/144_podcast_episode_guid.sql | 31 + migrations/sql/145_audiobook_series.sql | 35 + .../sql/146_audiobook_title_cleanup.sql | 56 + migrations/sql/147_abs_sessions.sql | 37 + migrations/sql/148_abs_bookmarks.sql | 40 + migrations/sql/149_abs_user_collections.sql | 35 + migrations/sql/150_abs_collection_items.sql | 22 + migrations/sql/151_abs_playlists.sql | 33 + migrations/sql/152_abs_playlist_items.sql | 26 + migrations/sql/153_abs_smart_collections.sql | 34 + ...user_watch_progress_hide_from_continue.sql | 16 + migrations/sql/155_abs_rss_feeds.sql | 35 + migrations/sql/156_unify_user_collections.sql | 252 + migrations/sql/157_podcast_feeds.sql | 33 + .../sql/158_audiobook_series_truncate.sql | 34 + .../sql/159_media_folders_kind_noop.sql | 29 + .../sql/160_audiobooks_feature_flag.sql | 14 + migrations/sql/161_abs_security_hardening.sql | 45 + ...1414_add_audiobookshelf_compat_enabled.sql | 17 + ...65643_remove_unused_abs_proxy_settings.sql | 6 + migrations/unify_user_collections_test.go | 33 + scripts/dedup_audiobooks.py | 236 + web/src/api/types.ts | 65 +- web/src/components/AddToCollectionDialog.tsx | 192 + web/src/components/AppSidebar.tsx | 4 + web/src/components/ContinueWatchingCard.tsx | 15 +- web/src/components/ItemCard.tsx | 4 +- web/src/components/ItemGrid.tsx | 11 +- web/src/components/RealtimeEventsProvider.tsx | 7 +- web/src/components/SectionItemCard.tsx | 4 +- .../admin/libraries/LibraryForm.tsx | 11 +- .../components/catalog/CatalogFilterBar.tsx | 1 + .../components/catalog/CatalogFilterSheet.tsx | 12 + .../catalog/CatalogFiltersPanel.test.tsx | 6 + .../catalog/CatalogFiltersPanel.tsx | 7 + .../components/catalog/catalogFilterBadges.ts | 24 + .../CollectionGuidedRulesEditor.test.tsx | 36 + .../CollectionGuidedRulesEditor.tsx | 351 +- .../collections/CollectionRulesEditor.tsx | 5 +- .../ManualCollectionItemsEditor.tsx | 188 +- .../sections/EditableSectionRows.tsx | 5 +- .../sections/SectionEditorDrawer.tsx | 5 +- web/src/components/ui/facet-search-select.tsx | 228 + web/src/hooks/queries/catalog.ts | 30 + web/src/hooks/queries/collections.ts | 44 + web/src/hooks/queries/progress.ts | 38 +- web/src/lib/audiobooks/types.ts | 17 + web/src/lib/querySortOptions.ts | 59 +- .../ItemDetail/AudiobookContent.test.tsx | 145 + web/src/pages/ItemDetail/AudiobookContent.tsx | 320 ++ web/src/pages/ItemDetail/DetailHero.tsx | 63 +- .../pages/ItemDetail/components/ActionBar.tsx | 16 + web/src/pages/ItemDetail/index.test.tsx | 3 +- web/src/pages/ItemDetail/index.tsx | 9 +- web/src/pages/LibraryBrowse.test.tsx | 24 + web/src/pages/LibraryBrowse.tsx | 26 +- .../admin-settings/AdminSettingsLayout.tsx | 14 +- .../CompatibilityProxiesSettings.test.tsx | 48 + ...s.tsx => CompatibilityProxiesSettings.tsx} | 61 +- .../components/ChaptersSection.test.tsx | 66 + .../audiobooks/components/ChaptersSection.tsx | 169 + .../audiobooks/components/NarratorCard.tsx | 28 + .../audiobooks/components/NarratorPicker.tsx | 80 + .../audiobooks/components/RelatedRail.tsx | 53 + .../audiobooks/player/AudiobookPlayer.tsx | 70 + .../audiobooks/player/CoverExpandTile.tsx | 27 + .../pages/audiobooks/player/MiniBar.test.tsx | 89 + web/src/pages/audiobooks/player/MiniBar.tsx | 157 + .../audiobooks/player/NowListening.test.tsx | 85 + .../pages/audiobooks/player/NowListening.tsx | 180 + .../player/useAudiobookPlayback.test.ts | 141 + .../audiobooks/player/useAudiobookPlayback.ts | 445 ++ web/src/pages/catalogSearchParams.ts | 5 +- web/src/pages/libraryPageSearchParams.test.ts | 51 + web/src/pages/libraryPageSearchParams.ts | 25 +- .../player/components/CircleButton.test.tsx | 36 + web/src/player/components/CircleButton.tsx | 48 + web/src/player/components/PlayerControls.tsx | 47 +- .../player/components/SleepTimerMenu.test.tsx | 37 + web/src/player/components/SleepTimerMenu.tsx | 116 + web/src/player/components/SpeedMenu.test.tsx | 29 + web/src/player/components/SpeedMenu.tsx | 95 + 253 files changed, 50703 insertions(+), 446 deletions(-) create mode 100644 docs/superpowers/notes/2026-05-27-abs-wire-shape-verification.md create mode 100644 docs/superpowers/plans/2026-05-24-audiobook-ui-redesign.md create mode 100644 docs/superpowers/plans/2026-05-24-audiobooks-absorption-1-discovery-schema.md create mode 100644 docs/superpowers/plans/2026-05-24-audiobooks-absorption-2-scanner.md create mode 100644 docs/superpowers/plans/2026-05-24-audiobooks-absorption-3-api-and-frontend.md create mode 100644 docs/superpowers/plans/2026-05-24-audiobooks-absorption-4-abs.md create mode 100644 docs/superpowers/plans/2026-05-24-audiobooks-absorption-5-podcasts.md create mode 100644 docs/superpowers/plans/2026-05-26-abs-bookmarks-implementation.md create mode 100644 docs/superpowers/plans/2026-05-26-abs-collections-playlists-implementation.md create mode 100644 docs/superpowers/plans/2026-05-26-abs-phase-0-login-and-critical-fixes.md create mode 100644 docs/superpowers/plans/2026-05-26-abs-phase1-closeout-implementation.md create mode 100644 docs/superpowers/plans/2026-05-26-abs-smart-collections-implementation.md create mode 100644 docs/superpowers/plans/2026-05-27-audiobook-catalog-filter-fields.md create mode 100644 docs/superpowers/plans/2026-05-27-audiobook-series-data-cleanup.md create mode 100644 docs/superpowers/plans/2026-05-27-catalog-facet-typeahead.md create mode 100644 docs/superpowers/plans/2026-05-27-collections-unify-1-schema.md create mode 100644 docs/superpowers/plans/2026-05-27-collections-unify-2-smartcoll-lift.md create mode 100644 docs/superpowers/plans/2026-05-27-collections-unify-3-abs-adapters.md create mode 100644 docs/superpowers/plans/2026-05-27-collections-unify-4-section-recipes.md create mode 100644 docs/superpowers/plans/2026-06-06-audiobooks-stacked-pr-split.md create mode 100644 docs/superpowers/plans/artifacts/2026-05-24-audiobooks-discovery-findings.md create mode 100644 docs/superpowers/specs/2026-05-24-audiobook-ui-redesign-design.md create mode 100644 docs/superpowers/specs/2026-05-24-audiobooks-absorption-design.md create mode 100644 docs/superpowers/specs/2026-05-26-abs-bookmarks-design.md create mode 100644 docs/superpowers/specs/2026-05-26-abs-collections-playlists-design.md create mode 100644 docs/superpowers/specs/2026-05-26-abs-implementation-fix-design.md create mode 100644 docs/superpowers/specs/2026-05-26-abs-phase1-closeout-design.md create mode 100644 docs/superpowers/specs/2026-05-26-abs-smart-collections-design.md create mode 100644 docs/superpowers/specs/2026-05-27-unified-audiobook-collections-design.md create mode 100644 internal/api/handlers/server_control.go create mode 100644 internal/api/handlers/server_control_test.go create mode 100644 internal/audiobooks/abs/access_log.go create mode 100644 internal/audiobooks/abs/author_series_handler.go create mode 100644 internal/audiobooks/abs/author_series_handler_test.go create mode 100644 internal/audiobooks/abs/bookmarks.go create mode 100644 internal/audiobooks/abs/bookmarks_envelope_test.go create mode 100644 internal/audiobooks/abs/bookmarks_handler.go create mode 100644 internal/audiobooks/abs/bookmarks_handler_test.go create mode 100644 internal/audiobooks/abs/collapse.go create mode 100644 internal/audiobooks/abs/collections.go create mode 100644 internal/audiobooks/abs/collections_envelope_test.go create mode 100644 internal/audiobooks/abs/collections_handler.go create mode 100644 internal/audiobooks/abs/collections_handler_test.go create mode 100644 internal/audiobooks/abs/continue_listening_handler.go create mode 100644 internal/audiobooks/abs/continue_listening_handler_test.go create mode 100644 internal/audiobooks/abs/extras_handlers.go create mode 100644 internal/audiobooks/abs/file_handler.go create mode 100644 internal/audiobooks/abs/file_handler_public_track_test.go create mode 100644 internal/audiobooks/abs/filter.go create mode 100644 internal/audiobooks/abs/handler.go create mode 100644 internal/audiobooks/abs/items_handler.go create mode 100644 internal/audiobooks/abs/jwt.go create mode 100644 internal/audiobooks/abs/libraries_handler.go create mode 100644 internal/audiobooks/abs/libraries_metadata_test.go create mode 100644 internal/audiobooks/abs/listening_stats_handler.go create mode 100644 internal/audiobooks/abs/listening_stats_handler_test.go create mode 100644 internal/audiobooks/abs/login.go create mode 100644 internal/audiobooks/abs/login_envelope_test.go create mode 100644 internal/audiobooks/abs/login_logout_test.go create mode 100644 internal/audiobooks/abs/login_ratelimit.go create mode 100644 internal/audiobooks/abs/login_refresh_race_test.go create mode 100644 internal/audiobooks/abs/login_refresh_test.go create mode 100644 internal/audiobooks/abs/me_handler.go create mode 100644 internal/audiobooks/abs/minified.go create mode 100644 internal/audiobooks/abs/play_response.go create mode 100644 internal/audiobooks/abs/play_resume_test.go create mode 100644 internal/audiobooks/abs/playlists.go create mode 100644 internal/audiobooks/abs/playlists_envelope_test.go create mode 100644 internal/audiobooks/abs/playlists_handler.go create mode 100644 internal/audiobooks/abs/playlists_handler_test.go create mode 100644 internal/audiobooks/abs/progress.go create mode 100644 internal/audiobooks/abs/progress_internal_test.go create mode 100644 internal/audiobooks/abs/rss_feeds.go create mode 100644 internal/audiobooks/abs/rss_feeds_handler.go create mode 100644 internal/audiobooks/abs/rss_feeds_handler_test.go create mode 100644 internal/audiobooks/abs/smart_collections.go create mode 100644 internal/audiobooks/abs/smart_collections_envelope_test.go create mode 100644 internal/audiobooks/abs/smart_collections_handler.go create mode 100644 internal/audiobooks/abs/smart_collections_handler_test.go create mode 100644 internal/audiobooks/abs/types.go create mode 100644 internal/audiobooks/abs_bookmark_store.go create mode 100644 internal/audiobooks/abs_collection_store.go create mode 100644 internal/audiobooks/abs_playback_session_store.go create mode 100644 internal/audiobooks/abs_playlist_store.go create mode 100644 internal/audiobooks/abs_progress_store.go create mode 100644 internal/audiobooks/abs_rss_feed_store.go create mode 100644 internal/audiobooks/abs_session_store.go create mode 100644 internal/audiobooks/abs_smart_collection_store.go create mode 100644 internal/audiobooks/abssocket/server.go create mode 100644 internal/audiobooks/abssocket/server_test.go create mode 100644 internal/audiobooks/access_resolver.go create mode 100644 internal/audiobooks/config.go create mode 100644 internal/audiobooks/cred_validator.go create mode 100644 internal/audiobooks/cred_validator_test.go create mode 100644 internal/audiobooks/doc.go create mode 100644 internal/audiobooks/enrichment.go create mode 100644 internal/audiobooks/enrichment_test.go create mode 100644 internal/audiobooks/media_store.go create mode 100644 internal/audiobooks/podcastfeed/refresher.go create mode 100644 internal/audiobooks/podcastfeed/refresher_test.go create mode 100644 internal/audiobooks/podcastfeed/store.go create mode 100644 internal/audiobooks/recommender.go create mode 100644 internal/audiobooks/service.go create mode 100644 internal/audiobooks/service_test.go create mode 100644 internal/audiobooks/smartcoll/evaluator.go create mode 100644 internal/audiobooks/smartcoll/evaluator_test.go create mode 100644 internal/audiobooks/smartcoll/query.go create mode 100644 internal/audiobooks/smartcoll/query_test.go create mode 100644 internal/catalog/detail_audiobook_test.go create mode 100644 internal/models/media_test.go create mode 100644 internal/scanner/audio_extensions.go create mode 100644 internal/scanner/audio_extensions_test.go create mode 100644 internal/scanner/audiobook.go create mode 100644 internal/scanner/audiobook_cover.go create mode 100644 internal/scanner/audiobook_scan.go create mode 100644 internal/scanner/audiobook_test.go create mode 100644 internal/scanner/podcast.go create mode 100644 internal/scanner/podcast_scan.go create mode 100644 internal/scanner/podcast_test.go create mode 100644 internal/scanner/probe_audiobook_test.go create mode 100644 internal/scanner/testdata/audiobook_fixtures/multi_file/part1.mp3 create mode 100644 internal/scanner/testdata/audiobook_fixtures/multi_file/part2.mp3 create mode 100644 internal/scanner/testdata/audiobook_fixtures/multi_file/part3.mp3 create mode 100644 internal/scanner/testdata/audiobook_fixtures/single_book/book.m4b create mode 100644 internal/scanner/testdata/podcast_fixtures/show_a/ep1.mp3 create mode 100644 internal/scanner/testdata/podcast_fixtures/show_a/ep2.mp3 create mode 100644 internal/scanner/testdata/podcast_fixtures/show_a/ep3.mp3 create mode 100644 internal/taskmanager/tasks/sync_audiobook_metadata.go create mode 100644 internal/taskmanager/tasks/sync_podcast_feeds.go create mode 100644 migrations/sql/143_abs_playback_sessions.sql create mode 100644 migrations/sql/144_podcast_episode_guid.sql create mode 100644 migrations/sql/145_audiobook_series.sql create mode 100644 migrations/sql/146_audiobook_title_cleanup.sql create mode 100644 migrations/sql/147_abs_sessions.sql create mode 100644 migrations/sql/148_abs_bookmarks.sql create mode 100644 migrations/sql/149_abs_user_collections.sql create mode 100644 migrations/sql/150_abs_collection_items.sql create mode 100644 migrations/sql/151_abs_playlists.sql create mode 100644 migrations/sql/152_abs_playlist_items.sql create mode 100644 migrations/sql/153_abs_smart_collections.sql create mode 100644 migrations/sql/154_user_watch_progress_hide_from_continue.sql create mode 100644 migrations/sql/155_abs_rss_feeds.sql create mode 100644 migrations/sql/156_unify_user_collections.sql create mode 100644 migrations/sql/157_podcast_feeds.sql create mode 100644 migrations/sql/158_audiobook_series_truncate.sql create mode 100644 migrations/sql/159_media_folders_kind_noop.sql create mode 100644 migrations/sql/160_audiobooks_feature_flag.sql create mode 100644 migrations/sql/161_abs_security_hardening.sql create mode 100644 migrations/sql/20260607161414_add_audiobookshelf_compat_enabled.sql create mode 100644 migrations/sql/20260607165643_remove_unused_abs_proxy_settings.sql create mode 100644 migrations/unify_user_collections_test.go create mode 100644 scripts/dedup_audiobooks.py create mode 100644 web/src/components/AddToCollectionDialog.tsx create mode 100644 web/src/components/ui/facet-search-select.tsx create mode 100644 web/src/lib/audiobooks/types.ts create mode 100644 web/src/pages/ItemDetail/AudiobookContent.test.tsx create mode 100644 web/src/pages/ItemDetail/AudiobookContent.tsx create mode 100644 web/src/pages/admin-settings/CompatibilityProxiesSettings.test.tsx rename web/src/pages/admin-settings/{JellyfinSettings.tsx => CompatibilityProxiesSettings.tsx} (62%) create mode 100644 web/src/pages/audiobooks/components/ChaptersSection.test.tsx create mode 100644 web/src/pages/audiobooks/components/ChaptersSection.tsx create mode 100644 web/src/pages/audiobooks/components/NarratorCard.tsx create mode 100644 web/src/pages/audiobooks/components/NarratorPicker.tsx create mode 100644 web/src/pages/audiobooks/components/RelatedRail.tsx create mode 100644 web/src/pages/audiobooks/player/AudiobookPlayer.tsx create mode 100644 web/src/pages/audiobooks/player/CoverExpandTile.tsx create mode 100644 web/src/pages/audiobooks/player/MiniBar.test.tsx create mode 100644 web/src/pages/audiobooks/player/MiniBar.tsx create mode 100644 web/src/pages/audiobooks/player/NowListening.test.tsx create mode 100644 web/src/pages/audiobooks/player/NowListening.tsx create mode 100644 web/src/pages/audiobooks/player/useAudiobookPlayback.test.ts create mode 100644 web/src/pages/audiobooks/player/useAudiobookPlayback.ts create mode 100644 web/src/player/components/CircleButton.test.tsx create mode 100644 web/src/player/components/CircleButton.tsx create mode 100644 web/src/player/components/SleepTimerMenu.test.tsx create mode 100644 web/src/player/components/SleepTimerMenu.tsx create mode 100644 web/src/player/components/SpeedMenu.test.tsx create mode 100644 web/src/player/components/SpeedMenu.tsx diff --git a/Dockerfile b/Dockerfile index bdeee00c..acfac7ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -54,7 +54,7 @@ RUN apt-get update && \ RUN mkdir -p /tmp/silo-transcode COPY --from=build /silo /usr/local/bin/silo COPY third_party/jellyfin-web/ /srv/jellyfin-web/ -EXPOSE 8080 8096 +EXPOSE 8080 8096 13378 HEALTHCHECK --interval=15s --timeout=5s --start-period=10s --retries=3 \ CMD curl -f http://localhost:${PORT:-8080}/api/v1/health || exit 1 ENTRYPOINT ["silo"] diff --git a/cmd/silo/main.go b/cmd/silo/main.go index 00430c35..93d52829 100644 --- a/cmd/silo/main.go +++ b/cmd/silo/main.go @@ -18,9 +18,12 @@ import ( "sort" "strconv" "strings" + "sync/atomic" "syscall" "time" + "github.com/go-chi/chi/v5" + chimiddleware "github.com/go-chi/chi/v5/middleware" "github.com/google/uuid" "github.com/hashicorp/go-hclog" "github.com/jackc/pgx/v5/pgxpool" @@ -34,6 +37,8 @@ import ( "github.com/Silo-Server/silo-server/internal/adminjob" "github.com/Silo-Server/silo-server/internal/api" "github.com/Silo-Server/silo-server/internal/api/handlers" + "github.com/Silo-Server/silo-server/internal/audiobooks" + "github.com/Silo-Server/silo-server/internal/audiobooks/podcastfeed" "github.com/Silo-Server/silo-server/internal/auth" "github.com/Silo-Server/silo-server/internal/autoscan" "github.com/Silo-Server/silo-server/internal/cache" @@ -421,6 +426,8 @@ func main() { appCtx, appCancel := context.WithCancel(ctx) defer appCancel() + restartReqCh := make(chan struct{}, 1) + var restartRequested atomic.Bool eventBus := cache.NewEventBus(cfg.Redis.URL) logStreamHub := logstream.NewHub(nodeID, eventBus) @@ -521,6 +528,19 @@ func main() { OpsLogRepo: opsRepo, FFmpegLogSink: playback.NewSlogFFmpegLogSink(slog.Default(), nodeID), PublicURL: os.Getenv("SILO_PUBLIC_URL"), + RequestServerRestart: func(context.Context) error { + if !restartRequested.CompareAndSwap(false, true) { + return handlers.ErrServerRestartAlreadyRequested + } + restartReqCh <- struct{}{} + return nil + }, + } + audiobooksService := audiobooks.New(&audiobooksSettingsAdapter{repo: settingsRepo}) + absCompatEnabled, err := audiobooksService.ABSCompatEnabled(appCtx) + if err != nil { + slog.Warn("Audiobookshelf compatibility disabled; failed to read setting", "err", err) + absCompatEnabled = false } adminJobCancelRegistry := adminjob.NewCancelRegistry() deps.AdminJobCancelRegistry = adminJobCancelRegistry @@ -868,6 +888,7 @@ func main() { var groupClaimRepo *catalog.GroupClaimRepository var seasonRepo *catalog.SeasonRepository var episodeRepo *catalog.EpisodeRepository + var audiobookEnricher *audiobooks.Enricher if needsWorkers && deps.DB != nil && deps.FileRepo != nil { chainRepo := metadata.NewChainRepository(deps.DB) skippedRootRepo = metadata.NewSkippedRootRepository(deps.DB) @@ -938,6 +959,18 @@ func main() { personRefreshService = metadata.NewPersonRefreshService(deps.DB, pluginResolver, personRepo) personRefreshService.SetImageResolver(imageResolver) + // Wire the audiobook enricher. It uses the same plugin resolver and chain + // repo as the movie/TV pipeline, but resolves providers at + // content_level='audiobook' and sweeps items directly rather than via a queue. + audiobookEnricher = audiobooks.NewEnricher( + deps.DB, + chainRepo, + pluginResolver, + itemRepo, + personRepo, + providerIDRepo, + ) + // Always wire the image resolver so plugin-prefixed URLs (e.g. // metadb://) can be resolved to presigned HTTP URLs in API responses. metadataService.SetImageResolver(imageResolver) @@ -948,10 +981,17 @@ func main() { imageCacher := imagecache.New(deps.S3Public) metadataService.SetImageCacher(imageCacher) metadataService.SetAutoCacheImages(cfg.Metadata.CacheImages) + if deps.Scanner != nil { + deps.Scanner.SetImageCacher(imageCacher) + } if cfg.Metadata.CacheImages { personRefreshService.SetImageCacher(imageCacher) slog.Info("metadata image caching enabled") } + if audiobookEnricher != nil { + audiobookEnricher.SetImageCacher(imageCacher) + audiobookEnricher.SetFFmpegPath(scanner.FFmpegPathFromFFprobe(scanner.FFprobePathFromFFmpeg(cfg.Playback.FFmpegPath))) + } } matchWorker = metadata.NewMatchWorker(metadataService, deps.FileRepo, cfg.Matcher.Workers, cfg.Matcher.BatchSize, 30*time.Second) @@ -1487,6 +1527,10 @@ func main() { historyReconciler := watchstate.NewHistoryReconciler(deps.DB, historyResolver) taskMgr.Register(tasks.NewRepairProviderIDIntegrityTask(metadata.NewProviderIDIntegrityRepairer(deps.DB), historyReconciler)) taskMgr.Register(tasks.NewReconcileWatchHistoryTask(historyReconciler)) + taskMgr.Register(tasks.NewSyncPodcastFeedsTask(podcastfeed.New(), podcastfeed.NewDBStore(deps.DB))) + if audiobookEnricher != nil { + taskMgr.Register(tasks.NewSyncAudiobookMetadataTask(audiobookEnricher)) + } if pluginInstallationStore != nil && pluginRuntimeConfigStore != nil && pluginService != nil { pluginTasks, err := plugins.NewTaskRegistryWithTypedResolver(pluginInstallationStore, pluginRuntimeConfigStore, pluginService).Tasks(appCtx) if err != nil { @@ -1503,6 +1547,57 @@ func main() { slog.Info("task manager started") } + // Build the ABS-compatible REST + Socket.io handler when a DB pool is + // available. Routes are mounted at the root level by NewRouter (not under + // /api/v1/) so ABS clients resolve /login, /api/*, /abs/api/*, and + // /abs/socket.io/* without path prefix hacks. + if absCompatEnabled && deps.DB != nil { + absUserRepo := auth.NewUserRepository(deps.DB) + absSessionRepo := auth.NewSessionRepository(deps.DB) + absJWTService := auth.NewJWTService( + cfg.Auth.JWTSecret, + cfg.Auth.AccessTokenExpiry, + cfg.Auth.RefreshTokenExpiry, + ) + absAuthSvc := auth.NewService( + auth.NewLocalProvider(absUserRepo, absSessionRepo), + absJWTService, + absSessionRepo, + absUserRepo, + nil, // invite codes: not needed for ABS compat + nil, // settings: not needed here + nil, // user store: not needed here + ) + absItemRepo := catalog.NewItemRepository(deps.DB) + absEpisodeRepo := catalog.NewEpisodeRepository(deps.DB) + absSeasonRepo := catalog.NewSeasonRepository(deps.DB) + absPersonRepo := catalog.NewPersonRepository(deps.DB) + var absFileFetcher catalog.FileVersionFetcher + if deps.FileRepo != nil { + absFileFetcher = deps.FileRepo + } + absDetailSvc := catalog.NewDetailService(absItemRepo, absEpisodeRepo, absSeasonRepo, absPersonRepo, absFileFetcher) + if deps.ImageResolver != nil { + absDetailSvc.SetImageResolver(deps.ImageResolver) + } + absHDeps := audiobooks.ABSHandlerDeps{ + Pool: deps.DB, + Items: absItemRepo, + Files: deps.FileRepo, + Settings: settingsRepo, + Auth: &audiobooks.SiloCredValidator{ + Auth: absAuthSvc, + Pool: deps.DB, + }, + AccessResolver: audiobooks.NewABSAccessResolver(absUserRepo, userStoreProvider), + Recs: recommendations.NewRepo(deps.DB), + Detail: absDetailSvc, + } + absH := audiobooksService.BuildABSHandler(absHDeps) + deps.ABSHandler = absH + } + _ = audiobooksService + if deps.DB != nil && pluginInstallationStore != nil && pluginRuntimeConfigStore != nil && deps.PluginService != nil { userRepo := auth.NewUserRepository(deps.DB) sessionRepo := auth.NewSessionRepository(deps.DB) @@ -1624,6 +1719,11 @@ func main() { metricsMux := http.NewServeMux() metricsMux.Handle("/metrics", promhttp.Handler()) metricsMux.Handle("/api/", router) + // ABS-compat is NOT mounted on the main listener — see the "ABS compat + // listener" block below. It binds its own port so the discovery probes + // (/ping, /healthcheck, /status, /init, /login, /socket.io) own the URL + // space without collision with silo's SPA fallback. Mirrors how the + // Jellyfin compat server is set up at :8096. metricsMux.Handle("/", server.FrontendHandler()) // Step 9: Start background workers (if needed). @@ -1846,6 +1946,28 @@ func main() { compatSrv.IdleTimeout = 120 * time.Second } + // ABS-compat listener — dedicated http.Server bound to its own port + // (default :13378) that hosts the Audiobookshelf-compatible API. + // Mirrors the Jellyfin compat layout above. The ABS handler mounts + // onto a fresh chi router here so /ping, /healthcheck, /status, /login, + // /socket.io, etc. own the URL space at the root — no SPA fallback, + // no collision with silo's /api/v1. + var absSrv *http.Server + if (mode == "integrated" || mode == "api") && deps.ABSHandler != nil && cfg.AudiobookshelfCompat.Listen != "" { + absRouter := chi.NewRouter() + absRouter.Use(chimiddleware.Recoverer) + absRouter.Use(chimiddleware.Compress(5)) + deps.ABSHandler.Mount(absRouter) + absSrv = &http.Server{ + Addr: cfg.AudiobookshelfCompat.Listen, + Handler: absRouter, + ReadHeaderTimeout: 10 * time.Second, + ReadTimeout: 60 * time.Second, + WriteTimeout: 0, + IdleTimeout: 120 * time.Second, + } + } + // Run non-critical startup work in the background so it doesn't delay the // HTTP listener from accepting connections. Steps run sequentially and stop // early if the app context is cancelled (shutdown). @@ -1870,7 +1992,7 @@ func main() { }() } - errCh := make(chan error, 2) + errCh := make(chan error, 3) go func() { slog.Info("HTTP server listening", "addr", cfg.Server.Listen) if listenErr := srv.ListenAndServe(); listenErr != nil && listenErr != http.ErrServerClosed { @@ -1885,6 +2007,14 @@ func main() { } }() } + if absSrv != nil { + go func() { + slog.Info("ABS compat server listening", "addr", absSrv.Addr) + if listenErr := absSrv.ListenAndServe(); listenErr != nil && listenErr != http.ErrServerClosed { + errCh <- fmt.Errorf("abs compat server error: %w", listenErr) + } + }() + } // Step 11: Wait for termination signal. sigCh := make(chan os.Signal, 1) @@ -1895,6 +2025,9 @@ func main() { case sig := <-sigCh: appCancel() slog.Info("received signal, shutting down", "signal", sig) + case <-restartReqCh: + appCancel() + slog.Info("server restart requested, shutting down") case serverErr := <-errCh: appCancel() slog.Error("server error, shutting down", "error", serverErr) @@ -1914,6 +2047,11 @@ func main() { slog.Error("jellyfin compat shutdown error", "error", shutdownErr) } } + if absSrv != nil { + if shutdownErr := absSrv.Shutdown(shutdownCtx); shutdownErr != nil { + slog.Error("abs compat shutdown error", "error", shutdownErr) + } + } // 2. Clean up stale sessions. if sessionCleaner != nil { @@ -2264,3 +2402,14 @@ func mapFolderTypeToMediaType(t string) string { return "mixed" } } + +// audiobooksSettingsAdapter bridges catalog.ServerSettingsRepo (which +// exposes Get) to the audiobooks.SettingsReader interface (which +// requires GetString). The two signatures are identical modulo name. +type audiobooksSettingsAdapter struct { + repo *catalog.ServerSettingsRepo +} + +func (a *audiobooksSettingsAdapter) GetString(ctx context.Context, key string) (string, error) { + return a.repo.Get(ctx, key) +} diff --git a/docker-compose.yml b/docker-compose.yml index 8eab93af..9b4c83c6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,11 +43,14 @@ services: ports: - "${PORT:-8090}:8080" - "${JF_PORT:-8096}:8096" + - "${ABS_PORT:-13378}:13378" volumes: - ${MEDIA_ROOT:?Set MEDIA_ROOT in .env to the host media path}:${MEDIA_CONTAINER_ROOT:-/mnt/media}:ro + - ${MEDIA_BOOKS_ROOT:-${MEDIA_ROOT}}:${MEDIA_BOOKS_CONTAINER_ROOT:-${MEDIA_CONTAINER_ROOT:-/mnt/media}/books}:ro - ${SILO_DATA_ROOT:-/opt/silo}/plugins:/var/lib/silo/plugins - ${SILO_DATA_ROOT:-/opt/silo}/transcode:/tmp/silo-transcode - ${SILO_DATA_ROOT:-/opt/silo}/catalog-seeds:/catalog-seeds:ro + - ${SILO_DATA_ROOT:-/opt/silo}/audiobook-covers:/var/lib/silo/audiobook-covers - /proc/meminfo:/host/proc/meminfo:ro depends_on: postgres: diff --git a/docs/superpowers/notes/2026-05-27-abs-wire-shape-verification.md b/docs/superpowers/notes/2026-05-27-abs-wire-shape-verification.md new file mode 100644 index 00000000..173e3a0a --- /dev/null +++ b/docs/superpowers/notes/2026-05-27-abs-wire-shape-verification.md @@ -0,0 +1,138 @@ +# ABS Wire-Shape Verification (post collections-unify cutover) + +Breadcrumbs for the next person debugging an ABS endpoint wire-shape issue +after the canonical-tables cutover (migration 156 + commits `0dc830e`, +`8c7fe1b`, `b64ce17`). + +The Go in-memory structs (`abs.Collection`, `abs.Playlist`, +`abs.SmartCollection`, `abs.CollectionItem`, `abs.PlaylistItem`) have **no +`json:"..."` struct tags**. The JSON wire contract is defined entirely by +the `*ToABS()` map-builder helpers in `internal/audiobooks/abs/`. As long as +the store layer populates the struct fields with the same values, the wire +shape is preserved. The rewrites in `0dc830e`, `8c7fe1b`, `b64ce17` did NOT +modify the emitters — only the SQL-backed store implementations. + +## Envelope tests — which one guards which endpoint + +Run with `go test ./internal/audiobooks/abs/ -run Envelope -v -count=1`. + +| Test file | Functions | Guards | +|---|---|---| +| `collections_envelope_test.go` | `TestCollectionEnvelope_HasRequiredKeys`, `TestCollectionListShape_OmitsBooks` | `collectionToABS` keys; list-shape (no `books`) vs detail-shape (with `books`) for `GET /api/collections`, `GET /api/collections/{id}`, `GET /api/libraries/{id}/collections`, and all POST/PATCH/DELETE collection endpoints | +| `playlists_envelope_test.go` | `TestPlaylistEnvelope_HasRequiredKeys`, `TestPlaylistEnvelope_OmitsCoverPathWhenEmpty`, `TestPlaylistListShape_OmitsItems` | `playlistToABS` keys; list-shape (no `items`) vs detail-shape (with `items`); `coverPath` is omitted when `CoverItem == ""` — covers `GET /api/playlists`, `GET /api/playlists/{id}`, `GET /api/libraries/{id}/playlists`, batch and item-add/remove endpoints | +| `smart_collections_envelope_test.go` | `TestSmartCollectionEnvelope_HasRequiredKeys`, `TestSmartCollectionEnvelope_EmptyQueryDef` | `smartCollectionToABS` keys; `queryDef` decoded from raw JSONB bytes into nested object, empty bytes → `{}` — covers `GET /api/me/smart-collections`, `GET /api/me/smart-collections/{id}`, POST/PATCH equivalents | +| `bookmarks_envelope_test.go` | `TestBookmarkEnvelope_HasRequiredKeys` | Bookmarks emitter (separate from this cutover, not affected by migration 156) | +| `login_envelope_test.go` | `TestLoginEnvelope_HasRequiredKeys` and three xReturnTokens / displayName variants | Login envelope (not affected by migration 156) | + +In addition, handler-level round-trip tests live in +`playlists_handler_test.go` and `bookmarks_handler_test.go`. There is NO +snapshot/goldenfile harness in the repo today — these envelope tests are +the primary regression guard. + +## Manual live-DB diff procedure + +For a pre/post-deploy wire-shape verification against a live silo, see the +plan's Task 5 "manual verification" section at +`docs/superpowers/plans/2026-05-27-collections-unify-3-abs-adapters.md` +(§ `Task 5: Wire-shape regression test`). Summary: + +1. Pre-cutover, seed one of each (collection, playlist with item, + smart collection) via the old `abs_*` tables, then capture each list + endpoint's response to `/tmp/wire_before_.json` using a curl + against the running silo with a valid ABS bearer token (HS256 JWT — + minted by the login flow, NOT the raw `abs_sessions.token` value). +2. Apply migration 156. Seed equivalent rows in `user_personal_collections` + with the same IDs and content. Capture again to + `/tmp/wire_after_.json`. +3. `diff /tmp/wire_before_.json /tmp/wire_after_.json` for each + `kind in {collections,playlists,smart_collections}`. Expected: empty + diff. + +This is an MR-description-level manual step, not a committed test. + +## Intentionally-zero fields after the rewrite + +These wire keys are still emitted, but the store always populates the +in-memory field with the zero value because the canonical +`user_personal_collections` schema has no analog column (per spec §6 of the +collections-unify plan). They are NOT bugs — do not "fix" them by reaching +for some other column. + +| In-memory field | Wire key | Zero value | Spec ref | Disposition | +|---|---|---|---|---| +| `abs.Playlist.CoverItem` | `coverPath` | `""` (key omitted entirely when empty — see `playlistToABS`) | spec §6.1 | Dropped. PATCH `coverPath` body field is silently ignored by the store. Cover regeneration from first-item poster is the chosen long-term path. | +| `abs.SmartCollection.Color` | `color` | `""` (key always emitted as empty string) | spec §6.3 | Deferred. No column on `user_personal_collections`. Wire key stays present for client compatibility. | +| `abs.SmartCollection.IsPinned` | `isPinned` | `false` (key always emitted) | spec §6.2 | Deferred. Same rationale. | + +If you're adding a "Pin this smart collection" feature later, the column +needs to land in a new migration on `user_personal_collections` first; +don't try to thread it through some adjacent column. + +## Canonical mapping — struct field → source column + +The full pre-cutover wire contract was captured in a working note that does +not persist (`/tmp/abs_wire_contract.md`). The essentials are reproduced +here so the next maintainer doesn't have to re-derive them. + +All three struct families now read from `user_personal_collections` +(and `user_personal_collection_items` for collections + playlists), +discriminated by `collection_type IN ('manual','playlist','smart')`. + +### `abs.Collection` (`collection_type = 'manual'`) + +| Field | Source column | +|---|---| +| ID | `user_personal_collections.id` | +| UserID | `user_personal_collections.user_id::text` (column is `integer`) | +| ProfileID | `user_personal_collections.profile_id` | +| Name | `user_personal_collections.name` | +| Description | `user_personal_collections.description` | +| IsPublic | `user_personal_collections.is_shared` | +| CreatedAt | `user_personal_collections.created_at` | +| UpdatedAt | `user_personal_collections.updated_at` | + +`abs.CollectionItem` reads `user_personal_collection_items` with +`sub_item_id = ''` filter (the manual-collection sentinel established in +migration 156 step 1). LibraryItemID ← `media_item_id`. ORDER BY +`added_at ASC`. + +### `abs.Playlist` (`collection_type = 'playlist'`) + +Same column mapping as `abs.Collection` (modulo `collection_type` filter) +EXCEPT `CoverItem` which is always `""` — see "Intentionally-zero fields" +above. + +`abs.PlaylistItem` reads `user_personal_collection_items` with NO +`sub_item_id` filter (playlists can carry episode entries). Mapping: +LibraryItemID ← `media_item_id`, EpisodeID ← `sub_item_id`, +Position ← `position`. ORDER BY `position ASC, added_at ASC`. + +### `abs.SmartCollection` (`collection_type = 'smart'`) + +Same column mapping as `abs.Collection` EXCEPT: + +- `Color`, `IsPinned` → always zero (see above). +- `QueryDef` ← `user_personal_collections.query_definition` (JSONB → `[]byte` + round-trip; column is `NOT NULL DEFAULT '{}'::jsonb` per migration 016). + +No items table — smart-collection membership is evaluated at request time +via the `smartcoll` package. + +### Wire-shape quirks worth remembering + +- Collection/Playlist emit `lastUpdate` (NOT `updatedAt`). SmartCollection + emits `updatedAt`. Cross-struct inconsistency, carry forward verbatim. +- All timestamps are `UnixMilli()` int64, NOT RFC3339 strings. +- `ProfileID` is carried in memory but NEVER emitted on the wire — it's + scope/auth only. +- The list vs detail shape distinction is implicit: list responses pass + `nil` for the items/books slice; the emitter then omits the key + entirely. Clients differentiate on key presence. + +## Verification status (2026-05-27) + +- All 13 envelope tests pass (run: `go test ./internal/audiobooks/abs/ + -run Envelope -v -count=1`). +- Full audiobooks test suite passes (`go test ./internal/audiobooks/... + -short -count=1 -timeout 120s`). +- Live-DB diff was NOT executed in CI — see manual procedure above. diff --git a/docs/superpowers/plans/2026-05-24-audiobook-ui-redesign.md b/docs/superpowers/plans/2026-05-24-audiobook-ui-redesign.md new file mode 100644 index 00000000..c00d6b81 --- /dev/null +++ b/docs/superpowers/plans/2026-05-24-audiobook-ui-redesign.md @@ -0,0 +1,3072 @@ +# Audiobook UI Redesign Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Bring the audiobook detail page and player to visual + interaction parity with Silo's video player, translated for audio, per the [design spec](../specs/2026-05-24-audiobook-ui-redesign-design.md). + +**Architecture:** Extract `CircleButton` and add new menu primitives (`SpeedMenu`, `SleepTimerMenu`) into `web/src/player/components/` so both players consume the same source of truth. Split today's monolithic `AudiobookPlayer.tsx` into a state hook (`useAudiobookPlayback`) plus two chrome components (`MiniBar`, `NowListening`) under `web/src/pages/audiobooks/player/`. The same `