# Anime season records

Parity stage 5 (diff rows E1, E11). Follows Animetail's pinned contract:
[AnimeSource](https://github.com/Animetailapp/Animetail/blob/d0eab5d6237dd09ebdb21a63fff5b66097c91087/source-api/src/main/kotlin/eu/kanade/tachiyomi/animesource/AnimeSource.kt),
`FetchType` and `SAnime.season_number`, and
[LocalAnimeSource](https://github.com/Animetailapp/Animetail/blob/d0eab5d6237dd09ebdb21a63fff5b66097c91087/source-local/src/main/kotlin/tachiyomi/source/local/entries/anime/LocalAnimeSource.kt).

## Model

A title has a fetch type: **Episodes** (default, every existing title) or **Seasons**.
A Seasons title has no episodes of its own; each season is a separate title record with
`parentId` pointing at it and an optional `seasonNumber` (unknown/-1 is stored as null).
Seasons may themselves be Seasons titles. Season records keep their own episodes,
progress, bookmarks, history and downloads.

- Library, home and local-library lists show top-level titles only. Seasons are opened
  from their show's detail page; Back returns to the show.
- Season records are not favorites by default. Cache cleanup (`cleanDatabase`, browsed-title
  pruning) keeps seasons whose parent chain reaches a library title; once the show leaves
  the library they are ordinary cached titles again.
- Room v16 adds `manga.parentId`, `manga.fetchType` (default `Episodes`) and
  `manga.seasonNumber`; the same migration adds `chapter.fillerOverride` (stage 6).
- Native backups and hub documents carry the fields. Older backups/documents decode
  with Episodes/null defaults. Backup merge remaps `parentId` to merged IDs and never
  turns an incoming season into a library entry. Legacy Mangayomi exports omit the
  fields; legacy pulls keep local values.

## Detail screen

A Seasons title shows a keyed **Seasons** list instead of the episode list, in season
number then name order. Each row shows the cover, season label, watched/total count and
a progress bar; tapping opens the season's own detail page, and the play button resumes
its first unwatched episode. The show's Resume/Start button resumes the first season
with an unwatched episode. Compact and wide layouts use the same rows.

## Sources

- JavaScript: `getDetail(url)` may return `fetch_type: "Seasons"` (or `fetchType`, or
  ordinal `0`). The client then calls optional `getSeasonList(url)` or reads an inline
  `seasons` array. Each season accepts the listing aliases plus `season_number` and
  `fetch_type`. Lists are capped at 500; repeated URLs keep the first; a non-array is an error.
- Mihon: when `getDetailsAnime` reports `fetch_type: "Seasons"`, the client sends
  `getSeasonList` with `animeData.url` instead of `getEpisodeList`.
- The bundled Android bridge (`vendor/yokan-ext`) adds `FetchType`, `SAnime.fetch_type`
  and `season_number` (default getters, so binaries built against older interfaces
  link and report Episodes/-1), `AnimeSource.getSeasonList` (default empty) and the
  `getSeasonList` method. External desktop/iOS/web bridge binaries must forward the
  same fields; ones that omit `fetch_type` keep Episodes behavior.
- Refreshing a Seasons title (detail screen or library update) upserts its seasons:
  existing season records, or a previously browsed non-library title with the same
  source URL, are reused; seasons missing from a response are kept. The library
  updater then refreshes each season (nesting capped at four levels), so new episodes
  are recorded as updates of that season.
- Offline fallback returns the stored seasons of a Seasons title.

## Local library

Anime folders follow `LocalAnimeFetchTypeManager.find`: a folder containing a video or
archive file is an Episodes title; otherwise, a folder with non-hidden subfolders is a
Seasons title and each subfolder becomes a season record (`<show>/<season>`),
recursively. Season numbers come from recognized folder names (`Season 2`, `S02`).
Hidden folders are skipped. Yokan keeps its one-level flattening for Episodes titles:
a folder with root episodes still includes its immediate subfolders' episodes, with
the per-season selector. Download-layout type folders (`Anime`, `Manga`, …) directly
under a library root keep their existing title discovery. Backends without
immediate-child listings keep previous links unchanged.

Upgrading existing libraries:
- A folder previously scanned as one flattened title because of a root image becomes a
  Seasons title. Its episodes move to the season records with the same IDs, progress,
  bookmarks, history and updates.
- Season folders previously listed as separate titles keep their IDs and progress and
  are linked under a new show record. If one was in the library, the show joins the
  library once with its categories; later removals are respected.

Behavior difference from upstream: Yokan's local folders already flatten one subfolder
level for Episodes titles; upstream does too. Upstream treats every top-level folder
without root video as a Seasons title, so grouping folders (`Anime/Action/<show>`) also
become Seasons titles here.

## Verification

Verification passed 167 desktop checks, 84 Kotlin/Wasm browser tests and 17 Android bridge unit checks without failures/errors/skips, and all four targets compiled (shared stage 5/6 run). Tests cover the Room v15→16
migration/reopen, JS/Mihon decoding and bounds, repository and updater season refresh,
cleanup, backup remapping, legacy export, the detail ViewModel season list, real desktop
folders (progress/history move, library inheritance, rescan stability) and a real OPFS
scan. Bridge tests cover season forwarding and a class compiled against the older
interface. Native-device UI and external bridges are unverified. Season-list
filters/sort (diff row E2) are not implemented.
