fix(plex): an episode Plex has no number for is named by its title alone
The OS media title printed the missing number as "Enull", the player and info headers as a bare "E". One helper for the three lines.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
// @vitest-environment jsdom
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { episodeLine } from "./plexDetail";
|
||||
|
||||
describe("episodeLine", () => {
|
||||
it("names the episode by its season and number", () => {
|
||||
expect(episodeLine({ season_number: 2, episode_number: 7, title: "Pilot" })).toBe(
|
||||
"S2·E7 — Pilot",
|
||||
);
|
||||
});
|
||||
|
||||
it("is the title alone for an episode Plex has no number for", () => {
|
||||
expect(episodeLine({ season_number: 1, episode_number: null, title: "Special" })).toBe(
|
||||
"Special",
|
||||
);
|
||||
expect(episodeLine({ season_number: null, episode_number: 3, title: "Special" })).toBe(
|
||||
"Special",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -210,6 +210,17 @@ export function epLabel(ep?: PlexCard | null): string | undefined {
|
||||
return ep.title;
|
||||
}
|
||||
|
||||
/** An episode's line under its show's name: "S1·E4 — Title" — or the title alone when Plex has no
|
||||
* number for it (a special): a template literal printed the missing one as "Enull", JSX as "E". */
|
||||
export function episodeLine(ep: {
|
||||
season_number?: number | null;
|
||||
episode_number?: number | null;
|
||||
title: string;
|
||||
}): string {
|
||||
if (ep.season_number == null || ep.episode_number == null) return ep.title;
|
||||
return `S${ep.season_number}·E${ep.episode_number} — ${ep.title}`;
|
||||
}
|
||||
|
||||
// Plex names seasons in the library's language ("Season 1", "Specials"), so a Hungarian reader got
|
||||
// English there. A generic name is rebuilt from the number in the reader's language; a season
|
||||
// with a name of its own ("Book One: Water") keeps it.
|
||||
|
||||
Reference in New Issue
Block a user