From c9b08690bf72ed29370cf9c8cb8c020776fbf031 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 08:13:27 +0000 Subject: [PATCH 1/2] feat(series): seasons named after their arc with Absolute numbering TMDB names some seasons ("S01 - Arc East Blue" for One Piece). Snug now keeps those names (without the repeated "S01 - ", English when untranslated, none for a plain "Season 2") and shows them as the season title when the Series uses Absolute numbering; SxxEyy series keep "Season 1". The MCP series tool returns them too. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MqWWDVUrBRBWJQpmfke2gN --- GLOSSARY.md | 2 +- apps/server/drizzle/0013_season_names.sql | 7 + apps/server/drizzle/meta/0013_snapshot.json | 1246 +++++++++++++++++ apps/server/drizzle/meta/_journal.json | 7 + .../src/modules/catalog/domain/series.ts | 2 + .../drizzle-catalog-repository.test.ts | 30 + .../drizzle-catalog-repository.ts | 13 +- .../modules/catalog/infrastructure/schema.ts | 13 + .../infrastructure/tmdb-client.test.ts | 19 +- .../catalog/infrastructure/tmdb-client.ts | 23 +- apps/server/src/modules/mcp/tools.ts | 3 +- .../application/tracking-service.test.ts | 8 + .../tracking/application/tracking-service.ts | 7 +- apps/web/src/components/series/season.tsx | 6 +- apps/web/src/i18n/en.tsx | 2 +- apps/web/src/i18n/fr.tsx | 2 +- packages/shared/src/index.ts | 2 + 17 files changed, 1379 insertions(+), 13 deletions(-) create mode 100644 apps/server/drizzle/0013_season_names.sql create mode 100644 apps/server/drizzle/meta/0013_snapshot.json create mode 100644 apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.test.ts diff --git a/GLOSSARY.md b/GLOSSARY.md index ca76564..9e8efdf 100644 --- a/GLOSSARY.md +++ b/GLOSSARY.md @@ -23,7 +23,7 @@ An Episode's rank across the whole Series: the Episodes of every earlier season, _Avoid_: Global number, overall number **Absolute numbering**: -A User's choice, Series by Series, to address its Episodes by their Absolute number ("Ep. 1100") rather than `SxxEyy`, wherever a person reads them. Meant for Anime. +A User's choice, Series by Series, to address its Episodes by their Absolute number ("Ep. 1100") rather than `SxxEyy`, wherever a person reads them, and its seasons by their own name on TMDB ("Arc East Blue") when they have one. Meant for Anime. _Avoid_: Anime mode **Day**: diff --git a/apps/server/drizzle/0013_season_names.sql b/apps/server/drizzle/0013_season_names.sql new file mode 100644 index 0000000..5c3b4a9 --- /dev/null +++ b/apps/server/drizzle/0013_season_names.sql @@ -0,0 +1,7 @@ +CREATE TABLE `seasons` ( + `series_id` integer NOT NULL, + `number` integer NOT NULL, + `name` text NOT NULL, + PRIMARY KEY(`series_id`, `number`), + FOREIGN KEY (`series_id`) REFERENCES `series`(`tmdb_id`) ON UPDATE no action ON DELETE cascade +); diff --git a/apps/server/drizzle/meta/0013_snapshot.json b/apps/server/drizzle/meta/0013_snapshot.json new file mode 100644 index 0000000..e941cbd --- /dev/null +++ b/apps/server/drizzle/meta/0013_snapshot.json @@ -0,0 +1,1246 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "02529d90-5a89-4d05-9f9f-c68c4b354ca8", + "prevId": "ce171b12-fc79-4655-af81-2cad40bb2a1f", + "tables": { + "app_settings": { + "name": "app_settings", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "episodes": { + "name": "episodes", + "columns": { + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "air_date": { + "name": "air_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "runtime": { + "name": "runtime", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "episodes_series_id_series_tmdb_id_fk": { + "name": "episodes_series_id_series_tmdb_id_fk", + "tableFrom": "episodes", + "tableTo": "series", + "columnsFrom": [ + "series_id" + ], + "columnsTo": [ + "tmdb_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "episodes_series_id_season_number_pk": { + "columns": [ + "series_id", + "season", + "number" + ], + "name": "episodes_series_id_season_number_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "seasons": { + "name": "seasons", + "columns": { + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "seasons_series_id_series_tmdb_id_fk": { + "name": "seasons_series_id_series_tmdb_id_fk", + "tableFrom": "seasons", + "tableTo": "series", + "columnsFrom": [ + "series_id" + ], + "columnsTo": [ + "tmdb_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "seasons_series_id_number_pk": { + "columns": [ + "series_id", + "number" + ], + "name": "seasons_series_id_number_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "series": { + "name": "series", + "columns": { + "tmdb_id": { + "name": "tmdb_id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "tvdb_id": { + "name": "tvdb_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "year": { + "name": "year", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "overview": { + "name": "overview", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "''" + }, + "poster_path": { + "name": "poster_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "backdrop_path": { + "name": "backdrop_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ended": { + "name": "ended", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "fetched_at": { + "name": "fetched_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "account": { + "name": "account", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "feed_token": { + "name": "feed_token", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "feed_token_token_unique": { + "name": "feed_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "feed_token_user_id_user_id_fk": { + "name": "feed_token_user_id_user_id_fk", + "tableFrom": "feed_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mcp_token": { + "name": "mcp_token", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "mcp_token_token_unique": { + "name": "mcp_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "mcp_token_user_id_user_id_fk": { + "name": "mcp_token_user_id_user_id_fk", + "tableFrom": "mcp_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "session_token_unique": { + "name": "session_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email_verified": { + "name": "email_verified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "user_email_unique": { + "name": "user_email_unique", + "columns": [ + "email" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user_preferences": { + "name": "user_preferences", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "data": { + "name": "data", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "user_preferences_user_id_user_id_fk": { + "name": "user_preferences_user_id_user_id_fk", + "tableFrom": "user_preferences", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "verification": { + "name": "verification", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "watchlist_token": { + "name": "watchlist_token", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "watchlist_token_token_unique": { + "name": "watchlist_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "watchlist_token_user_id_user_id_fk": { + "name": "watchlist_token_user_id_user_id_fk", + "tableFrom": "watchlist_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "webhook_token": { + "name": "webhook_token", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "webhook_token_token_unique": { + "name": "webhook_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "webhook_token_user_id_user_id_fk": { + "name": "webhook_token_user_id_user_id_fk", + "tableFrom": "webhook_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "jellyfin_events": { + "name": "jellyfin_events", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "received_at": { + "name": "received_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "outcome": { + "name": "outcome", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payload": { + "name": "payload", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "jellyfin_events_user_id_user_id_fk": { + "name": "jellyfin_events_user_id_user_id_fk", + "tableFrom": "jellyfin_events", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "jellyfin_series": { + "name": "jellyfin_series", + "columns": { + "jellyfin_series_id": { + "name": "jellyfin_series_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "tmdb_id": { + "name": "tmdb_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "jellyfin_users": { + "name": "jellyfin_users", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "jellyfin_user_id": { + "name": "jellyfin_user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "jellyfin_users_user_id_user_id_fk": { + "name": "jellyfin_users_user_id_user_id_fk", + "tableFrom": "jellyfin_users", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "episode_alerts": { + "name": "episode_alerts", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sent_at": { + "name": "sent_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "episode_alerts_user_id_user_id_fk": { + "name": "episode_alerts_user_id_user_id_fk", + "tableFrom": "episode_alerts", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "episode_alerts_user_id_series_id_season_number_pk": { + "columns": [ + "user_id", + "series_id", + "season", + "number" + ], + "name": "episode_alerts_user_id_series_id_season_number_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "push_subscriptions": { + "name": "push_subscriptions", + "columns": { + "endpoint": { + "name": "endpoint", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "p256dh": { + "name": "p256dh", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "auth": { + "name": "auth", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "push_subscriptions_user_id_user_id_fk": { + "name": "push_subscriptions_user_id_user_id_fk", + "tableFrom": "push_subscriptions", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "ratings": { + "name": "ratings", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "episode": { + "name": "episode", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "rating": { + "name": "rating", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "ratings_user_id_series_id_season_episode_pk": { + "columns": [ + "user_id", + "series_id", + "season", + "episode" + ], + "name": "ratings_user_id_series_id_season_episode_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tracked_series": { + "name": "tracked_series", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "saving_target": { + "name": "saving_target", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "absolute_numbering": { + "name": "absolute_numbering", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "added_at": { + "name": "added_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "tracked_series_user_id_user_id_fk": { + "name": "tracked_series_user_id_user_id_fk", + "tableFrom": "tracked_series", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "tracked_series_user_id_series_id_pk": { + "columns": [ + "user_id", + "series_id" + ], + "name": "tracked_series_user_id_series_id_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "watches": { + "name": "watches", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "watched_at": { + "name": "watched_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "watches_user_id_series_id_season_number_pk": { + "columns": [ + "user_id", + "series_id", + "season", + "number" + ], + "name": "watches_user_id_series_id_season_number_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/apps/server/drizzle/meta/_journal.json b/apps/server/drizzle/meta/_journal.json index 34e1f73..00b67a9 100644 --- a/apps/server/drizzle/meta/_journal.json +++ b/apps/server/drizzle/meta/_journal.json @@ -92,6 +92,13 @@ "when": 1793647652521, "tag": "0012_jellyfin_users", "breakpoints": true + }, + { + "idx": 13, + "version": "6", + "when": 1794211910011, + "tag": "0013_season_names", + "breakpoints": true } ] } \ No newline at end of file diff --git a/apps/server/src/modules/catalog/domain/series.ts b/apps/server/src/modules/catalog/domain/series.ts index b75006c..159ab15 100644 --- a/apps/server/src/modules/catalog/domain/series.ts +++ b/apps/server/src/modules/catalog/domain/series.ts @@ -17,6 +17,8 @@ export interface Series { ended: boolean; /** Regular seasons only; specials (season 0) are not tracked. */ episodes: Episode[]; + /** Season number → its own name on TMDB ("Arc East Blue"), only for seasons named more than "Season 1". */ + seasonNames?: Record; fetchedAt: Date; } diff --git a/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.test.ts b/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.test.ts new file mode 100644 index 0000000..f477b35 --- /dev/null +++ b/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.test.ts @@ -0,0 +1,30 @@ +import { expect, test } from "bun:test"; +import type { Series } from "@/modules/catalog/domain/series"; +import { testDb } from "@/shared/testing"; +import { DrizzleCatalogRepository } from "./drizzle-catalog-repository"; + +const onePiece = (seasonNames: Record): Series => ({ + tmdbId: 37854, + tvdbId: 81797, + name: "One Piece", + year: 1999, + overview: "", + posterPath: null, + backdropPath: null, + ended: false, + episodes: [ + { season: 1, number: 1, name: "Je suis Luffy !", airDate: "1999-10-20", runtime: 24 }, + { season: 2, number: 62, name: "Laboon", airDate: "2001-03-21", runtime: 24 }, + ], + seasonNames, + fetchedAt: new Date("2026-11-09T00:00:00Z"), +}); + +test("season names are saved with the Series, and replaced on the next refresh", async () => { + const repo = new DrizzleCatalogRepository(testDb().db); + await repo.save(onePiece({ 1: "Arc East Blue", 2: "Arc Grand Line" })); + expect((await repo.get(37854))?.seasonNames).toEqual({ 1: "Arc East Blue", 2: "Arc Grand Line" }); + + await repo.save(onePiece({ 1: "Arc East Blue" })); + expect((await repo.get(37854))?.seasonNames).toEqual({ 1: "Arc East Blue" }); +}); diff --git a/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.ts b/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.ts index 2776781..8f75f57 100644 --- a/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.ts +++ b/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.ts @@ -1,7 +1,7 @@ import { and, asc, eq, inArray, lt } from "drizzle-orm"; import type { Db } from "@/shared/db"; import type { CatalogRepository, Episode, Series } from "@/modules/catalog/domain/series"; -import { episodes, series } from "./schema"; +import { episodes, seasons, series } from "./schema"; export class DrizzleCatalogRepository implements CatalogRepository { constructor(private readonly db: Db) {} @@ -15,7 +15,7 @@ export class DrizzleCatalogRepository implements CatalogRepository { if (!tmdbIds.length) return result; const ids = [...tmdbIds]; const rows = this.db.select().from(series).where(inArray(series.tmdbId, ids)).all(); - for (const row of rows) result.set(row.tmdbId, { ...row, episodes: [] }); + for (const row of rows) result.set(row.tmdbId, { ...row, episodes: [], seasonNames: {} }); const eps = this.db .select() .from(episodes) @@ -23,14 +23,21 @@ export class DrizzleCatalogRepository implements CatalogRepository { .orderBy(asc(episodes.season), asc(episodes.number)) .all(); for (const { seriesId, ...ep } of eps) result.get(seriesId)?.episodes.push(ep satisfies Episode); + for (const season of this.db.select().from(seasons).where(inArray(seasons.seriesId, ids)).all()) { + const names = result.get(season.seriesId)?.seasonNames; + if (names) names[season.number] = season.name; + } return result; } - async save({ episodes: eps, ...row }: Series) { + async save({ episodes: eps, seasonNames = {}, ...row }: Series) { this.db.transaction((tx) => { tx.insert(series).values(row).onConflictDoUpdate({ target: series.tmdbId, set: row }).run(); tx.delete(episodes).where(eq(episodes.seriesId, row.tmdbId)).run(); if (eps.length) tx.insert(episodes).values(eps.map((episode) => ({ ...episode, seriesId: row.tmdbId }))).run(); + tx.delete(seasons).where(eq(seasons.seriesId, row.tmdbId)).run(); + const named = Object.entries(seasonNames).map(([number, name]) => ({ seriesId: row.tmdbId, number: Number(number), name })); + if (named.length) tx.insert(seasons).values(named).run(); }); } diff --git a/apps/server/src/modules/catalog/infrastructure/schema.ts b/apps/server/src/modules/catalog/infrastructure/schema.ts index d1f35e0..c91b2f4 100644 --- a/apps/server/src/modules/catalog/infrastructure/schema.ts +++ b/apps/server/src/modules/catalog/infrastructure/schema.ts @@ -27,6 +27,19 @@ export const episodes = sqliteTable( (t) => [primaryKey({ columns: [t.seriesId, t.season, t.number] })], ); +/** Seasons TMDB gives a name of their own ("Arc East Blue"); a season named "Season 1" has no row. */ +export const seasons = sqliteTable( + "seasons", + { + seriesId: integer("series_id") + .notNull() + .references(() => series.tmdbId, { onDelete: "cascade" }), + number: integer("number").notNull(), + name: text("name").notNull(), + }, + (t) => [primaryKey({ columns: [t.seriesId, t.number] })], +); + /** Instance-wide settings (e.g. the TMDB key). */ export const appSettings = sqliteTable("app_settings", { key: text("key").primaryKey(), diff --git a/apps/server/src/modules/catalog/infrastructure/tmdb-client.test.ts b/apps/server/src/modules/catalog/infrastructure/tmdb-client.test.ts index 772899c..9245dc8 100644 --- a/apps/server/src/modules/catalog/infrastructure/tmdb-client.test.ts +++ b/apps/server/src/modules/catalog/infrastructure/tmdb-client.test.ts @@ -1,6 +1,6 @@ import { expect, test } from "bun:test"; import type { Series } from "@/modules/catalog/domain/series"; -import { withEnglishFallback } from "./tmdb-client"; +import { seasonName, withEnglishFallback } from "./tmdb-client"; const series = (overview: string, names: string[]): Series => ({ tmdbId: 1, @@ -30,3 +30,20 @@ test("translations are kept", () => { expect(merged.overview).toBe("Un enfant disparaît…"); expect(merged.episodes[1]?.name).toBe("Mensonges"); }); + +test("a season keeps its own name, without the number TMDB sometimes repeats in it", () => { + expect(seasonName("S01 - Arc East Blue")).toBe("Arc East Blue"); + expect(seasonName("Book One: Water")).toBe("Book One: Water"); + expect(seasonName("Saison 2")).toBeNull(); + expect(seasonName("Season 12")).toBeNull(); + expect(seasonName("S03 - Saison 3")).toBeNull(); + expect(seasonName(" ")).toBeNull(); +}); + +test("season names TMDB has not translated fall back to English", () => { + const merged = withEnglishFallback( + { ...series("", []), seasonNames: { 1: "Arc East Blue" } }, + { ...series("", []), seasonNames: { 1: "East Blue", 2: "Entering into the Grand Line" } }, + ); + expect(merged.seasonNames).toEqual({ 1: "Arc East Blue", 2: "Entering into the Grand Line" }); +}); diff --git a/apps/server/src/modules/catalog/infrastructure/tmdb-client.ts b/apps/server/src/modules/catalog/infrastructure/tmdb-client.ts index 63710b9..f72a990 100644 --- a/apps/server/src/modules/catalog/infrastructure/tmdb-client.ts +++ b/apps/server/src/modules/catalog/infrastructure/tmdb-client.ts @@ -24,7 +24,7 @@ interface TmdbShow { status: string; networks: { name: string }[]; origin_country: string[]; - seasons: { season_number: number }[]; + seasons: { season_number: number; name?: string | null }[]; external_ids?: { tvdb_id: number | null }; [appended: `season/${number}`]: { episodes: TmdbEpisode[] } | undefined; } @@ -72,11 +72,24 @@ export async function isValidTmdbKey(key: string): Promise { /** TMDB's placeholder when an episode has no translated title ("Épisode 5", "Folge 5"…). */ const GENERIC_EPISODE_NAME = /^(episode|épisode|episodio|episódio|folge|aflevering|odcinek|エピソード)\s*\d+$/i; -/** Fills what TMDB has not translated (empty overview, placeholder episode names) from English. */ +/** TMDB's default season name, "Season 2" in each language: it says nothing the number doesn't. */ +const GENERIC_SEASON_NAME = /^(season|saison|staffel|temporada|stagione|seizoen|sezon|series|シーズン)\s*\d+$/i; + +/** + * A season's own name, or null when TMDB only numbers it. Drops a leading "S01 - ", which repeats the number: + * "S01 - Arc East Blue" → "Arc East Blue". + */ +export function seasonName(name: string): string | null { + const own = name.trim().replace(/^S\d+\s*[-–—:]\s*/i, ""); + return own && !GENERIC_SEASON_NAME.test(own) ? own : null; +} + +/** Fills what TMDB has not translated (empty overview, placeholder episode and season names) from English. */ export function withEnglishFallback(localized: Series, english: Series): Series { const englishNames = new Map(english.episodes.map((episode) => [`${episode.season}x${episode.number}`, episode.name])); return { ...localized, + seasonNames: { ...english.seasonNames, ...localized.seasonNames }, overview: localized.overview || english.overview, posterPath: localized.posterPath ?? english.posterPath, backdropPath: localized.backdropPath ?? english.backdropPath, @@ -109,6 +122,11 @@ export class TmdbClient implements SeriesSource { private async fetchIn(tmdbId: number, language: string): Promise { const show = await this.get(`/tv/${tmdbId}`, { language, append_to_response: "external_ids" }); const seasons = show.seasons.map((season) => season.season_number).filter((number) => number > 0); + const seasonNames: Record = {}; + for (const season of show.seasons) { + const name = season.season_number > 0 ? seasonName(season.name ?? "") : null; + if (name) seasonNames[season.season_number] = name; + } const release = releaseOf( show.networks.map((network) => network.name), show.origin_country, @@ -136,6 +154,7 @@ export class TmdbClient implements SeriesSource { backdropPath: show.backdrop_path, ended: show.status === "Ended" || show.status === "Canceled", episodes, + seasonNames, fetchedAt: new Date(), }; } diff --git a/apps/server/src/modules/mcp/tools.ts b/apps/server/src/modules/mcp/tools.ts index e66c24b..32d4bd7 100644 --- a/apps/server/src/modules/mcp/tools.ts +++ b/apps/server/src/modules/mcp/tools.ts @@ -206,7 +206,7 @@ export function registerTools( "series", { description: - "One series in detail, tracked or not: its seasons and episodes, the day each one was first watched (watchedAt, null when not watched), the next one. An episode's name is null when the user's spoiler shield hides it: don't look the title up elsewhere. Episodes carry their absolute number across seasons; with absoluteNumbering, the user calls them by it (\"episode 1156\").", + "One series in detail, tracked or not: its seasons (with their own name when TMDB gives one, e.g. a story arc) and episodes, the day each one was first watched (watchedAt, null when not watched), the next one. An episode's name is null when the user's spoiler shield hides it: don't look the title up elsewhere. Episodes carry their absolute number across seasons; with absoluteNumbering, the user calls them by it (\"episode 1156\").", inputSchema: { tmdbId }, annotations: { readOnlyHint: true }, }, @@ -229,6 +229,7 @@ export function registerTools( rating: detail.rating, seasons: detail.seasons.map((season) => ({ number: season.number, + name: season.name, rating: season.rating, episodes: season.episodes.map((episode) => ({ number: episode.number, diff --git a/apps/server/src/modules/tracking/application/tracking-service.test.ts b/apps/server/src/modules/tracking/application/tracking-service.test.ts index 0f76d44..38fd42a 100644 --- a/apps/server/src/modules/tracking/application/tracking-service.test.ts +++ b/apps/server/src/modules/tracking/application/tracking-service.test.ts @@ -222,3 +222,11 @@ test("Absolute numbering is kept per User and Series, and the Episodes carry the await tracking.numberAbsolutely("u", 1, false); expect((await tracking.library("u"))[0]?.absoluteNumbering).toBe(false); }); + +test("the detail names the seasons TMDB names, and leaves the others to their number", async () => { + const show = series(1, false, ["2026-10-01", "2026-10-08"]); + show.episodes = show.episodes.map((episode, index) => (index === 1 ? { ...episode, season: 2, number: 1 } : episode)); + show.seasonNames = { 1: "Arc East Blue" }; + const detail = await setup([show]).detail("u", 1); + expect(detail.seasons.map((season) => [season.number, season.name])).toEqual([[1, "Arc East Blue"], [2, null]]); +}); diff --git a/apps/server/src/modules/tracking/application/tracking-service.ts b/apps/server/src/modules/tracking/application/tracking-service.ts index 99aa25d..8ecb20d 100644 --- a/apps/server/src/modules/tracking/application/tracking-service.ts +++ b/apps/server/src/modules/tracking/application/tracking-service.ts @@ -245,7 +245,12 @@ export class TrackingService { const numbered = numberAbsolutely(series.episodes); const seasons = new Map(); for (const episode of series.episodes) { - const season = seasons.get(episode.season) ?? { number: episode.season, rating: tracked.ratingOf(episode.season), episodes: [] }; + const season = seasons.get(episode.season) ?? { + number: episode.season, + name: series.seasonNames?.[episode.season] ?? null, + rating: tracked.ratingOf(episode.season), + episodes: [], + }; season.episodes.push({ ...numbered(episode), watched: tracked.hasWatched(episode), diff --git a/apps/web/src/components/series/season.tsx b/apps/web/src/components/series/season.tsx index b21e11b..353476a 100644 --- a/apps/web/src/components/series/season.tsx +++ b/apps/web/src/components/series/season.tsx @@ -28,6 +28,8 @@ export function Season({ series, season }: { series: SeriesDetail; season: Seaso const current = series.next?.season ?? series.seasons.at(-1)?.number; const showProgress = aired > 0 && (seasonProgress === "all" || season.number === current); const base = `/series/${series.seriesId}`; + // With Absolute numbering, Episodes no longer say their season: its own name ("Arc East Blue") reads better. + const title = (series.absoluteNumbering && season.name) || t.series.season(season.number); const toggle = useMutation({ mutationFn: (e: { number: number; watched: boolean }) => @@ -58,7 +60,7 @@ export function Season({ series, season }: { series: SeriesDetail; season: Seaso aria-expanded={open} className="flex min-w-0 flex-1 items-center gap-3 py-4 pl-5 text-left" > -

{t.series.season(season.number)}

+

{title}

{t.series.episodesWatched(watched, season.episodes.length)} {series.tracked && showRatings && ( @@ -72,7 +74,7 @@ export function Season({ series, season }: { series: SeriesDetail; season: Seaso