# Extended trackers and enhanced server tracking

Animetail parity rows T1–T13 (stages 11 and 12). All adapters, sign-in flows, stored state and
synchronization are shared Kotlin (`services/tracking`), compiled for Android, iOS, desktop and web.
Every integration uses credentials the user enters; no client IDs, secrets or API keys are bundled.
Protocols follow the pinned Animetail adapters (commit `d0eab5d6`) and the providers' documentation;
they are tested at the HTTP boundary with Ktor `MockEngine` fixtures, not against live accounts.

## Providers

| Provider | Sync id | Media | Sign-in | `id:` lookup | Remote unbind |
|---|---|---|---|---|---|
| MangaUpdates | 10 | manga/novel | username + password → session token (`PUT /v1/account/login`) | series id | list delete |
| Shikimori | 11 | anime, manga/novel | own OAuth app: client id/secret + authorization code → access/refresh token | numeric id | `DELETE user_rates/{id}` |
| Bangumi | 12 | anime, manga/novel | personal access token, or own OAuth app code exchange (refreshable) | subject id | none (API has no delete) |
| Hikka | 13 | anime, manga/novel | own client reference/secret + request reference → secret (`auth` header, expires) | slug | `DELETE /watch/{slug}` or `/read/{type}/{slug}` |
| MangaBaka | 14 | manga/novel | personal access token (`mb-…`, `x-api-key`) | series id | `DELETE /v1/my/library/{id}` |
| TMDB | 15 | anime-type entries (movies, TV) | own v3 API key → request token approved in browser → session | `id:N`, `id:tv/N`, `id:movie/N` | watchlist and rating removed |
| Komga | 20 | manga | server URL + API key (`X-API-Key`) or username/password (Basic) | server item id | — |
| Kavita | 21 | manga | server URL + API key → plugin JWT (re-authenticates once on 401) | series id | — |
| Suwayomi | 22 | manga | server URL + optional Basic credentials | manga id | — |
| Jellyfin | 23 | anime | server URL + username/password → access token (`AuthenticateByName`) | item id | — |

Settings → Tracking lists every tracker (except the metadata server tracker). Trackers with their
own sign-in open a credentials dialog showing the provider's rejection message; the original
AniList/Kitsu/MAL/SIMKL/Trakt token dialog is unchanged. Manage trackers covers all signed-in
trackers. Local scores of the new trackers use 0–10 and are converted to each provider's scale
(MangaBaka 0–100, TMDB 0.5–10). Tracks, credentials (`DbTrackPreference.oauth` + JSON
`TrackerCredentials` in `prefs`) and the auto-bind preference go through the existing backup,
sync and library tracker filter/grouping/score paths keyed by sync id; credentials are only
exported with sensitive backups. The tracker library (ranking browse) keeps its Mangayomi providers.

## Remote synchronization

The repository stores every local change first, then notifies `TrackerAccounts`, which runs the
remote call in the profile scope (serialized, failures logged without touching local state):

- **Bind** (detail tracking search result or `id:`): fetch the provider's list entry or create it
  (PlanToRead/PlanToWatch when nothing is read locally). An existing remote entry's status, progress
  and score are adopted.
- **Edit** (Manage trackers): progress, status and score are pushed; the provider's response is stored.
- **Reading**: with *Update progress after reading* on, marking chapters/episodes read pushes progress.
  Local progress never moves backwards on marking read.
- **Detail open**: bound remote trackers are refreshed. "Smart sync": the higher of local and remote
  progress wins and local progress the provider is behind on is pushed.
- **Unbind**: a dialog offers *Unbind locally* or *Also remove from service*.

The original five adapters keep their local-only bind/update behavior; they gained `id:` lookup.

## Enhanced (server) tracking — Komga, Kavita, Suwayomi, Jellyfin

Animetail `EnhancedTracker` semantics (`accept(source)`, `match(entry)`, auto-bind, two-way sync):

- `accept`: the source name contains the provider name (Suwayomi also *Tachidesk*), or the source's
  base/API URL host equals the configured server host. Yokan cannot read extension class names or
  extension credentials, so the server is entered in the tracker's own sign-in.
- `match`: the server item id is parsed from the title's source link (Mihon/Aniyomi and Mangayomi
  shapes: Komga `/api/v1/series|readlists/<id>`, Kavita `/Series/<id>` or `seriesId=`, Suwayomi
  `/manga/<id>`, Jellyfin `/Items/<id>` or `Id=`) and fetched from the configured server.
- Adding a title to the library binds every signed-in server tracker that accepts its source.
  The detail tracking search resolves the title's own entry instead of searching.
- Progress is a chapter/episode **number**: the last chapter of the continuous read run is pushed
  (Komga `read-progress/tachiyomi`, Kavita `mark-chapter-until-as-read`, Suwayomi chapter
  `markPrevRead`, Jellyfin `UserPlayedItems` for each episode up to it). Remote progress marks local
  chapters/episodes with numbers up to it read.

## Automatic binding when adding to the library

*Track when adding to library* (off by default, `features.tracking.autoBindOnAdd`): for every
signed-in tracker that supports the media type, the title's name is searched and bound only when
exactly one result has the same normalized title (letters/digits, case-insensitive). Ambiguous or
missing matches bind nothing. Server trackers always auto-bind as above.

## Platform blockers

- **OAuth redirects** use the existing `yokan://tracker/<provider>` path: Android delivers the
  callback into the dialog. Desktop, iOS and web have no `yokan://` dispatcher, so the user pastes the
  authorization code or the callback URL from the browser address bar (Shikimori, Bangumi OAuth,
  Hikka). TMDB needs no paste: approve in the browser, then Save.
- **Web (CORS, checked 2026-10-18 with preflight requests):** Shikimori (`shikimori.io`; `shikimori.one`
  redirects there), Bangumi API, MangaBaka API and TMDB allow any origin. Bangumi's OAuth token endpoint
  sends no CORS headers, so web users must use a personal access token. Hikka's API returns no
  `Access-Control-Allow-Origin` for other origins: Hikka cannot work in the browser. MangaUpdates
  answered 403 to every request from the verification host (edge filtering), so its browser CORS
  behavior is unverified. Self-hosted servers must enable CORS for the Yokan origin and allow the
  `Authorization`, `X-API-Key` or `X-Emby-*` headers; an HTTPS page cannot reach `http://` LAN servers.
  Browsers ignore the `User-Agent` header the adapters send.
- **Images**: Komga/Suwayomi/Jellyfin cover URLs need the server to serve images without auth;
  Kavita covers are omitted so the API key never lands in a stored URL.
- Suwayomi uses the REST v1 API (deprecated upstream in favor of GraphQL); servers in UI-login or
  cookie auth modes are not supported. Jellyfin uses the current `/Items/{id}?userId=` and
  `/UserPlayedItems/{id}` routes (10.9+).
