# 060 — My movies / My series in native Videos windows

Decision 5: the menu items open Kodi's Videos window with addon listings, so
the user gets every Estuary view, sorting, the side menu and the info dialog
exactly as with the Kodi library.

## 0. Requirement from a real Kodi crash (2026-10-01)

Kodi 21.3 crashes (SIGSEGV in `CPythonInvoker::stop`, 4 reports on 2026-10-01) when the user presses Back while a
plugin directory script is still running: the cancel stops the invoker at the very moment the script finishes. It is a
race inside Kodi, not in addon code; it cannot be fixed here, only made rarer. The old listings run the whole router
(~430 ms per screen, every Back re-runs the parent screen). **The L3 listings must therefore be served by a fast path
in `main.py` like the widgets (no router import, 50-130 ms)** and read from `meta` / the store; only data never seen
before is fetched inline once, as 030 §3 already decides (the service refresher keeps tracked series warm). Not reproduced with scripted key bursts
(only the real keyboard timing hits it), so judge the effect on real use.

## 1. Listings (`listings.py`, router `action=mlist`)

| Path | Content type | Items |
|------|--------------|-------|
| `…?action=mlist&kind=movies` | `movies` | My movies; playable canonical movie URLs (040 §2) |
| `…?action=mlist&kind=series` | `tvshows` | My series; folders → seasons |
| `…?action=mlist&kind=seasons&tmdb=<id>` | `seasons` | regular seasons 1..N, then "Speciály" (season 0) if TMDb has it |
| `…?action=mlist&kind=episodes&tmdb=<id>&s=<n>` | `episodes` | all episodes of the season; playable canonical URLs; unaired ones listed with "vyjde <date>" and a `skin_run` path that only shows the date |

Every item carries full `InfoTagVideo` from the metadata cache (title,
originaltitle, year, premiered/aired, plot, tagline, rating + votes, genres,
studios, countries, mpaa, duration, cast with thumbnails, director, writer,
tvshowtitle, season, episode, `uniqueid {'tmdb'}`, `mediatype`), art
(poster, fanart, landscape/thumb = episode still, clearlogo via
`TMDbLogo.resolve_logo` when cached), and state from the store:
`setPlaycount`, `setResumePoint(pos, total)`, `setLastPlayed`. Folders carry
the properties Estuary and Kodi read for counters and overlays:
`TotalEpisodes`, `WatchedEpisodes`, `UnWatchedEpisodes`, `TotalSeasons`,
`NumEpisodes` (aired regular episodes only).

Each item also gets property `milionar.tmdb`, `milionar.type`
(`movie`/`tv`/`season`/`episode`), `milionar.s`, `milionar.e` — used by the
info-dialog button and the context menu (080, 090).

## 2. Sorting and window behaviour

- Sort methods added in this order (first = default): movies — title, year,
  date added (`list_added_at`), rating, last played; series — title, year,
  date added, last played (series `last_activity_at`); episodes — episode.
- `xbmcplugin.setContent` as in §1 so Estuary picks the matching views and
  Kodi remembers the view per content type.
- Estuary's side-menu options that Kodi applies to plugin folders (view,
  sort, "hide watched" if Kodi applies its watched filter to plugin items)
  are verified in L3 and listed in the Result; nothing in the skin changes
  for them.
- `updateListing=false`, `cacheToDisc=false` (state must be fresh after
  every play or mark).

## 3. Opening from Home

- Main menu "Moje filmy" → `ActivateWindow(Videos,plugin://plugin.video.milionar/?action=mlist&kind=movies,return)`,
  "Moje seriály" → `…kind=series…` (070 §1).
- Widget row items for series open the seasons listing; episode and movie
  items play (or resume, Continue rows) — 070 §4.

## 4. Empty lists

Empty My movies / My series: one non-playable item "Zatím tu nic není —
přidejte filmy z hledání nebo z kontextového menu" whose click opens the
search (`skin_search`).

## 5. Other addon listings

The addon's existing listings of movies, series, seasons and episodes (TMDb,
ČSFD, collections, similar, favourites, AI, recently played) keep their
click behaviour (`default_movie_action` etc.) but get the same state on the
`InfoTagVideo` (ticks, progress) and the context menu of 080; every play
path in them goes through `mplay` (040 §2).

## 6. Result

Built 2026-10-01 (awaiting the user's test, **not yet accepted**):

- `wcs/library2/listings.py`, reached through the `main.py` fast path
  (`action=mlist&kind=movies|series|seasons|episodes`, `action=mupcoming`);
  no router import. Kodi-side times (JSON-RPC `Files.GetDirectory`, warm):
  movies 60-120 ms, series (13) 120-180 ms, seasons 60-80 ms, episodes 45-135 ms
  (the old screens: ~430 ms).
- Items: canonical play URLs, full `InfoTagVideo` from `meta` (title, original
  title, year, premiered, plot, tagline, rating + votes, genres, studios,
  countries, runtime, cast, directors, writers, `uniqueid tmdb`, `mediatype`),
  art (poster / thumb / fanart / landscape / clearlogo from the cache, never
  downloaded), state from the store (playcount, resume point, last played,
  date added), properties `milionar.type|tmdb|s|e`, series and season folders
  carry `TotalSeasons / TotalEpisodes / NumEpisodes / WatchedEpisodes /
  UnWatchedEpisodes` (aired regular episodes; season 0 only in its own
  folder). A series or movie whose `meta` entry is missing is shown from the
  list snapshot (title, overview, poster); seasons / episodes never seen
  before are fetched inline once (030 §3).
- Episodes are labelled `<n>. <title>`; an unaired one shows "(vyjde 22. 6.)",
  has no state, and a click only shows a notification (`mupcoming`).
  Specials come last in the season list ("Speciály").
- Sort methods as 060 §2 (series: title, year, date added, last played);
  `cacheToDisc=false`, `updateListing=false`. Empty list: one item that opens
  the search. A failing listing closes its directory with `succeeded=False`.
- Strings 32290-32293 in cs, sk, en.
- Found while checking the data: an autosave at 99 % could leave a resume
  point behind after a crash (Black Mirror S01E01 of the user shows 2661 of
  2674 s); `tracker._save` now skips positions past the watched mark (unit
  test; needs a Kodi restart to take effect). The existing row in the user's
  data was left untouched.
- **Tests: 118 green** (`test_listings.py`: 10 new, test_autoplay + 1; the
  stubs got `ListItem`, `InfoTagVideo`, `xbmcplugin` recorders).
- **Live:** the four listings return the user's 3 movies / 13 series, Black
  Mirror seasons (S1 ticked) and episodes with ticks, resume and last played;
  the series list opened in a real Videos window (`Container.Content =
  tvshows`, 13 items, sorted by name). Not yet captured: Poster / InfoWall
  views, the info dialog, the side-menu options (the user was using Kodi at
  that moment, so no more window driving).
- The addon menu's old "Moje filmy" / "Moje seriály" (`tmdb_added_movies` / `tmdb_added_series`) are redirected to these
  listings in `main.py` (user decision 2026-10-01, to shorten the window of the Kodi Back-press crash; 73-95 ms instead
  of ~430 ms).
- User decisions 2026-10-01 (after the redirect removed the old buttons): the buttons come back **on top of both
  lists**, pinned with `SpecialSort=top` so no sort method moves them: "Poradit se s AI (beta)" (only when the addon
  setting `menu_show_ai_chat` is on, as before), "Přidat film / seriál" (old `tmdb_add_movie` / `tmdb_add_series`),
  and, when the list is not empty, red "Smazat všechny ..." (old `tmdb_remove_all_*`, its confirm dialog). A movie
  click follows the old setting `default_movie_action` (Přehrát ihned = canonical play, Zobrazit detaily = our
  details dialog); series click opens the seasons. The **context menu waits for L5** (080): until then the lists only
  have Kodi's own menu.
- Skin change (user, 2026-10-01): the quality flags (video codec, resolution, HDR, aspect, audio codec, channels) of the
  MediaFlags include are hidden for items with `ListItem.Property(milionar.type)` (`xml/Includes.xml`, 6 conditions),
  because no source file is chosen before playing; date and duration stay (the duration comes from Kodi's stored stream
  details after a play, e.g. 02:32:21 instead of the TMDb 02:32:00). Kodi library items are unchanged.
- Same look as the Kodi library (user, 2026-10-01, compared by screenshots): series folders show "watched / total"
  instead of the year (skin: `ListLabel2Var`, `WatchedStatusVar`, `ItemStatusIconVar` in `Variables.xml` accept
  `ListItem.Property(milionar.type)` tv / season); season list starts with "* Všechny sezóny" (Kodi string 20366, all
  episodes as `1x01. Name`) and every season shows "watched / total" and the series plot; episodes are `01. Name`,
  rating on the right (skin), the episode still in the left panel (no `poster` art on episodes), sort method
  "unsorted" (Kodi rebuilds the row text from the tag title, so the title carries the number). Checked live:
  seasons, all-seasons list, per-season episodes; the series-list count was fixed afterwards (sort id 7 or 29) and not
  re-captured.
- Kodi crash (SIGSEGV in `CPythonInvoker::stop`) kept happening on 2026-10-01 (7 reports, also after the fast path):
  Kodi stops a plugin script that is just finishing when Back is pressed during the directory load. Not fixable in the
  addon; shorter scripts only make it rarer.
- Home menu items done early at the user's request (070 §1, menu part only): "Moje filmy" / "Moje seriály" after Pokračovat
  (menu ids 29000 / 30000, no widget rows yet = L4), Kodi's Filmy / Seriály hidden by default (`MilionarDefaultsV3`),
  toggles + reset in skin settings, skin strings 31916 / 31917 (cs, sk, en). Captured: the menu shows both items.
