The label said "without length" but the count held only live videos, so a video not fetched yet, or gone before it was, was left out of the sum and named nowhere. The server's `Video.without_length` and the client's `isWithoutLength` are now one rule (no length, whatever the live status), and the field, the key and the helpers are named for what they count. The comments that still quoted "+N live" say the current copy.
20 lines
1.1 KiB
TypeScript
20 lines
1.1 KiB
TypeScript
// A total of video lengths and the videos it cannot hold. The server decides what a length is (a
|
|
// YouTube "length" past a day is a 24/7 stream's archive reporting the years it has run, and the API
|
|
// sends none for it: `catalog.models.LENGTH_MAX_S`), so this side keeps no copy of that limit. It only
|
|
// names what a sum left out: every video with no length — live, an archive, or not fetched yet — as the
|
|
// server's `Video.without_length` counts it for the totals it sums itself. The two rules are the same,
|
|
// so the count and the sum never disagree about what was left out.
|
|
import type { TFunction } from "i18next";
|
|
import type { Video } from "../../lib/api/feed";
|
|
|
|
export function isWithoutLength(v: Pick<Video, "duration_seconds">): boolean {
|
|
return v.duration_seconds == null;
|
|
}
|
|
|
|
/** "12 hr 5 min +2 without length": `total` is the formatted sum ("" when nothing summed), `leftOut`
|
|
* the count it left out. Empty when both are. */
|
|
export function withLeftOutCount(total: string, leftOut: number, t: TFunction): string {
|
|
const suffix = leftOut > 0 ? t("card.withoutLength", { count: leftOut }) : "";
|
|
return [total, suffix].filter(Boolean).join(" ");
|
|
}
|