Fix playback, account, download and library bugs found in review
All checks were successful
Validate Kaleido Desktop / validate (push) Successful in 1m22s

- Clear cached library data when the account or profile behind the
  server connection changes, not only on Home user switches.
- TitleArt falls back to the title when there is no server, so the
  player no longer crashes offline.
- Playback keeps the server it started on: progress, watched state and
  transcodes never go to a server selected later, a download only
  reports to its own server, and switching account or server ends a
  stream from the old one.
- Closing or replacing playback during setup can no longer start the
  file afterwards.
- Transcodes save the chosen audio/subtitle tracks on the server before
  starting (and name them in the request), apply the language and
  subtitle preferences, and keep the current tracks across quality
  changes.
- Offline playback saves its resume point and watched count in the
  download's metadata.
- Download tasks take over from a previous task for the same title only
  after it exits, and pause/remove stay wired to the current task.
- Downloads prefer a single-file version and refuse split ones instead
  of saving only part one.
- Download artwork is named per file, so episodes in one season folder
  no longer overwrite or delete each other's images.
- Library grids refetch loaded pages when the cache is invalidated.
- Request timeouts and cancellation also cover the response body.
- Hero rotation resumes after being scrolled back into view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-04 22:41:12 -07:00
parent c70aeede74
commit 8755d16735
9 changed files with 399 additions and 99 deletions

View file

@ -52,12 +52,16 @@ function sanitize(s: string) {
return s.replace(/[<>:"/\\|?*\u0000-\u001f]/g, '_').trim() || 'Untitled';
}
/** Trims metadata kept for offline display: no extras, related hubs or raw blobs. */
function slim(raw: any) {
/**
* Trims metadata kept for offline display: no extras, related hubs or raw blobs, and
* only the version downloaded, so its streams describe the file that plays.
*/
function slim(raw: any, mediaIndex: number) {
const { Extras, Related, OnDeck, ...rest } = raw ?? {};
void Extras;
void Related;
void OnDeck;
if (Array.isArray(rest.Media) && rest.Media[mediaIndex]) rest.Media = [rest.Media[mediaIndex]];
return rest;
}
@ -102,9 +106,12 @@ export const useDownloads = create<DownloadsState>((set, get) => ({
try {
await get().init();
const item = await api.metadata(server, input.id);
const media = item.media[0];
// A download is one file. A version split across several (CD1, CD2) would be
// kept as its first part only, so prefer a version in one piece.
const media = item.media.find((m) => m.parts.length === 1) ?? item.media[0];
const part = media?.parts[0];
if (!part) throw new Error('This title has no downloadable file.');
if (media.parts.length > 1) throw new Error('This title is split across several files, which Kaleido can’t download yet.');
const id = get().idFor(item.id);
if (get().items.some((d) => d.id === id && d.status !== 'failed')) {
toast('This title is already in Downloads.');
@ -129,7 +136,7 @@ export const useDownloads = create<DownloadsState>((set, get) => ({
url: server.signed(part.key, { download: 1 }),
folder,
fileName: sanitize(baseName),
meta: { serverId: server.machineId, serverName: server.name, ratingKey: item.id, partKey: part.key, raw: slim(item.raw) } satisfies DownloadMeta,
meta: { serverId: server.machineId, serverName: server.name, ratingKey: item.id, partKey: part.key, raw: slim(item.raw, item.media.indexOf(media)) } satisfies DownloadMeta,
assets,
},
});