Move a single season of a TV show (#4)
CI / test (push) Successful in 1m14s

Shows can be expanded to list their seasons, each with its size and its own Dry run / Move buttons. A season joins the same show on the other
server, so finished seasons can go to the big server while the current one stays on the fast one.

- Source exports a season from the show folder, with a manifest of just that season's folder plus the show's loose non-video files. Refuses
  seasons with no folder of their own, or whose folder holds otherseasons' episodes.
- Destination finds the show by provider ID, then name. If it already has the show, the show's own files are skipped (Job.skip_files) and
  never overwritten; otherwise they come with the season. Refuses if the season folder already exists.
- Only episode watch state is carried for a season.
- Source trashes just the season folder; after the last season, the leftover show folder joins it in the same trash entry if no videos
  remain. The chosen trash entry is saved so a re-run after a crash finishes in the same place.
- New GET /seasons (UI and peer). Fake Jellyfin gains season items.
- e2e tests: season into a new show, into an existing show, last season leaving, destination already has the season, misfiled episodes.
This commit is contained in:
IxianPixel committed 2026-11-06 17:02:40 +00:00
1 parent 25a743b350
commit 484ac50508
21 files changed
+959 -111

No files matched your search

+92 -16
View File
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { api, bytes, type Library, type LibraryItem, type Side } from './api';
import { api, bytes, type Library, type LibraryItem, type Movable, type SeasonItem, type Side } from './api';
interface Props {
localName: string;
@@ -20,6 +20,8 @@
let notice = $state<string | null>(null);
let sort = $state<'name' | 'size'>('name');
let open = $state<Record<string, boolean>>({}); // shows with seasons expanded
type Seasons = { loading: true } | { error: string } | { list: SeasonItem[] };
let seasons = $state<Record<string, Seasons>>({});
const sourceName = $derived(side === 'local' ? localName : peerName);
const destName = $derived(side === 'local' ? peerName : localName);
@@ -55,6 +57,27 @@
}, 2000);
}
async function toggleSeasons(item: LibraryItem) {
open[item.id] = !open[item.id];
const have = seasons[item.id];
if (!open[item.id] || (have && 'list' in have)) return;
seasons[item.id] = { loading: true };
try {
seasons[item.id] = { list: await api.seasons(side, item.id) };
} catch (e) {
seasons[item.id] = { error: (e as Error).message };
}
}
function partFor(item: LibraryItem, s: SeasonItem) {
return item.size?.parts.find((p) => p.name === s.folder);
}
/** Folders in the show that aren't a season Jellyfin knows, e.g. extras. */
function otherParts(item: LibraryItem, list: SeasonItem[]) {
return (item.size?.parts ?? []).filter((p) => !list.some((s) => s.folder === p.name));
}
function loose(item: LibraryItem): number {
if (!item.size) return 0;
return item.size.bytes - item.size.parts.reduce((n, p) => n + p.bytes, 0);
@@ -99,6 +122,8 @@
function choose(s: Side) {
if (s === side) return;
side = s;
open = {};
seasons = {};
loadLibraries(s);
}
@@ -118,7 +143,7 @@
return () => clearTimeout(timer);
});
async function move(item: LibraryItem, dryRun: boolean) {
async function move(item: Movable, dryRun: boolean) {
busy = item.id;
notice = null;
error = null;
@@ -187,9 +212,9 @@
<span class="name">{item.name}</span>
{#if item.year}<span class="muted">{item.year}</span>{/if}
{#if item.path}<div class="path mono muted" title={item.path}>{item.path}</div>{/if}
{#if item.kind === 'Series' && item.size?.parts.length}
<button class="disclose" aria-expanded={!!open[item.id]} onclick={() => (open[item.id] = !open[item.id])}>
{open[item.id] ? 'Hide' : 'Show'} sizes by season ({item.size.parts.length})
{#if item.kind === 'Series'}
<button class="disclose" aria-expanded={!!open[item.id]} onclick={() => toggleSeasons(item)}>
{open[item.id] ? 'Hide' : 'Show'} seasons
</button>
{/if}
</div>
@@ -205,17 +230,47 @@
</button>
</div>
</div>
{#if open[item.id] && item.size}
<table class="parts">
<tbody>
{#each item.size.parts as p (p.name)}
<tr><td>{p.name}</td><td class="muted">{fileCount(p.files)}</td><td class="num">{bytes(p.bytes)}</td></tr>
{/each}
{#if loose(item) > 0}
<tr><td class="muted">Other files in the show folder</td><td></td><td class="num">{bytes(loose(item))}</td></tr>
{/if}
</tbody>
</table>
{#if open[item.id]}
{@const st = seasons[item.id]}
{#if !st || 'loading' in st}
<p class="seasons-msg muted">Loading seasons…</p>
{:else if 'error' in st}
<p class="seasons-msg error">{st.error}</p>
{:else}
<table class="parts">
<tbody>
{#each st.list as season (season.id)}
{@const part = partFor(item, season)}
{@const what = { id: season.id, name: `${item.name} – ${season.name}` }}
<tr>
<td>{season.name}</td>
<td class="muted">{part ? fileCount(part.files) : ''}</td>
<td class="num">{part ? bytes(part.bytes) : ''}</td>
<td class="acts">
{#if season.path}
<button class="small" disabled={busy === season.id} onclick={() => move(what, true)} title="Check and plan without copying anything">
Dry run
</button>
<button class="small primary" disabled={busy === season.id} onclick={() => move(what, false)}>
Move season →
</button>
{:else}
<span class="muted small-text" title="Its episodes sit directly in the show folder">No folder of its own; move the whole show</span>
{/if}
</td>
</tr>
{:else}
<tr><td colspan="4" class="muted">Jellyfin lists no seasons for this show.</td></tr>
{/each}
{#each otherParts(item, st.list) as p (p.name)}
<tr class="muted"><td>{p.name}</td><td>{fileCount(p.files)}</td><td class="num">{bytes(p.bytes)}</td><td class="small-text">Moves with the whole show</td></tr>
{/each}
{#if loose(item) > 0}
<tr class="muted"><td>Show files (NFO, artwork)</td><td></td><td class="num">{bytes(loose(item))}</td><td class="small-text">Copied with a season if {destName} doesn't have the show</td></tr>
{/if}
</tbody>
</table>
{/if}
{/if}
</li>
{/each}
@@ -314,7 +369,28 @@
.parts .num {
text-align: right;
font-variant-numeric: tabular-nums;
}
.parts td {
vertical-align: middle;
white-space: nowrap;
}
.parts td.small-text {
white-space: normal;
}
.parts .acts {
padding-right: 0;
white-space: nowrap;
}
.seasons-msg {
margin: 0.5rem 0 0 3.5rem;
font-size: 0.88rem;
}
button.small {
padding: 0.2rem 0.6rem;
font-size: 0.82rem;
}
.small-text {
font-size: 0.8rem;
}
.list li:first-child {
border-top: none;
+1 -1
View File
@@ -74,7 +74,7 @@
}
function kindLabel(e: TrashEntry): string {
if (e.kind === 'Series') return 'TV';
if (e.kind === 'Series' || e.kind === 'Season') return 'TV';
if (e.kind === 'Movie') return 'Film';
return '—';
}
+20 -2
View File
@@ -57,6 +57,22 @@ export interface LibraryItem {
size: FolderSize | null;
}
export interface SeasonItem {
id: string;
name: string;
number: number | null;
/** Null when the season has no folder of its own; it can't move alone. */
path: string | null;
/** The season's folder name inside the show folder. */
folder: string | null;
}
/** Anything that can be moved: a movie, a show or a season. */
export interface Movable {
id: string;
name: string;
}
export type Stage =
| 'Created'
| 'ExportReady'
@@ -101,7 +117,7 @@ export interface TrashEntry {
id: string;
name: string;
/** Missing for items trashed before v0.2.0. */
kind: 'Movie' | 'Series' | null;
kind: 'Movie' | 'Series' | 'Season' | null;
library: string;
folder: string;
moved_at: string | null;
@@ -149,7 +165,9 @@ export const api = {
'GET',
`/items?${new URLSearchParams({ node, library, ...(search ? { search } : {}) })}`,
),
move: (from: Side, item: LibraryItem, dry_run: boolean) =>
seasons: (node: Side, series: string) =>
call<SeasonItem[]>('GET', `/seasons?${new URLSearchParams({ node, series })}`),
move: (from: Side, item: Movable, dry_run: boolean) =>
call<Job>('POST', '/moves', { from, item_id: item.id, name: item.name, dry_run }),
jobs: () => call<JobsView>('GET', '/jobs'),
retry: (id: string) => call<Job>('POST', `/jobs/${id}/retry`),