The code cited its plan instead of saying why: `E28 review J4`, `(R6 S3b)`, `S1 justified…`,
`deep-review round 5`. That plan lives in the private ops repo, so for every reader of this one the
citation was noise, and a sentence whose subject was the plan step ("round 2 showed…") hid its
lesson behind an id. Each one is gone and the "why" kept: a bare citation is deleted, a sentence
carrying a lesson is reworded around it ("a later attempt showed…").
Measured (`scripts/audit_metrics.py`, product code): 652 lines in 270 files carried an epic code by
the definition the next commit holds (507 / 241 by the old, two-digit-only one) -> 0. Across all
code, tests, scripts and configs: ~1100 epic-code lines plus ~320 sprint/round ids.
Behaviour unchanged, checked mechanically: every changed .py file has the same AST once docstrings
are blanked; css/sh/toml/yml/json files are identical once comments are stripped; the only
non-comment changes in TS/JS are test titles, one description string in a contract table, and five
ESLint messages, whose text is all the gates snapshot diff holds. Not touched: Markdown (docs and
the changelog keep their history), Alembic migrations, TV episode notation (`S2 · E5`), DESIGN.md
ids (`C1`, `B4`, `S3h`), tracker ids (`SEC-16`, `DX-17`).
One stale claim fixed on the way: test_hls_reaper's docstring said the player checkpoints "every
10 s whether or not it is playing", which plex/stream.py calls wrong; it now says what the code does.
74 lines
3.3 KiB
TypeScript
74 lines
3.3 KiB
TypeScript
import { useCallback, useMemo } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import Modal from "./ui/Modal";
|
|
import { api, type DownloadJob } from "../lib/api";
|
|
import { jobTitle } from "./downloadTitle";
|
|
import { exposeVideoToBackgroundPlay } from "../lib/browserBackgroundPlay";
|
|
import { useMediaLogRef } from "../lib/mediaLog";
|
|
|
|
// In-app player for a completed library item. We do NOT reuse PlayerModal (a cross-origin
|
|
// YouTube IFrame shell) or PlexPlayer (a Plex HLS/session shell): both are bound to their own domain
|
|
// APIs and can't point at a local file. Instead we reuse the shared a11y shell (`Modal`: focus-trap,
|
|
// ESC/back-to-close, scroll-lock, layer-stack, portal) and stream the local file into a NATIVE
|
|
// <video>/<audio controls> — the same element VideoEditor already plays this URL in. Downloads are a
|
|
// browser-native container (mp4/H.264/AAC + m4a/mp3), so native playback (seek via the range-aware
|
|
// /file endpoint, volume, fullscreen, speed) works with zero transcode; an uploaded media item may be
|
|
// any codec (best-effort playback).
|
|
export default function LibraryPlayer({ job, onClose }: { job: DownloadJob; onClose: () => void }) {
|
|
const { t } = useTranslation();
|
|
const fileUrl = useMemo(() => api.downloadFileUrl(job.id), [job.id]);
|
|
// Video vs audio-only comes from the stored media_kind (the single source every sibling reads —
|
|
// WatchPage/downloadRow/DownloadCenter) — NOT a re-derived container list, which would misclassify
|
|
// an uploaded audio file whose container is outside a hardcoded set (uploads accept any container).
|
|
// Only fall back to the old dimension+container heuristic for a legacy asset with a null media_kind.
|
|
const asset = job.asset;
|
|
const isAudio =
|
|
asset?.media_kind === "audio" ||
|
|
(asset?.media_kind == null &&
|
|
!(asset?.width && asset?.height) &&
|
|
!!asset?.container &&
|
|
["m4a", "mp3", "opus", "ogg", "wav", "flac", "aac"].includes(asset.container.toLowerCase()));
|
|
// Our self-hosted poster (always same-origin, never expires) is the primary; the source thumbnail is
|
|
// the fallback. Same precedence as the library-row thumbnail.
|
|
const poster = job.poster_url ? api.posterImageUrl(job.id) : (asset?.thumbnail_url ?? undefined);
|
|
const logMedia = useMediaLogRef("library");
|
|
const videoRef = useCallback(
|
|
(el: HTMLVideoElement | null) => {
|
|
exposeVideoToBackgroundPlay(el);
|
|
logMedia(el);
|
|
},
|
|
[logMedia],
|
|
);
|
|
|
|
return (
|
|
<Modal initialFocus="close" title={jobTitle(job)} onClose={onClose} maxWidth="max-w-4xl">
|
|
{isAudio ? (
|
|
<div className="flex flex-col items-center gap-4 py-2">
|
|
{poster ? (
|
|
<img
|
|
src={poster}
|
|
alt=""
|
|
className="w-40 h-40 rounded-xl object-cover border border-border"
|
|
/>
|
|
) : null}
|
|
<audio ref={logMedia} src={fileUrl} controls autoPlay className="w-full">
|
|
{t("downloads.player.unsupported")}
|
|
</audio>
|
|
</div>
|
|
) : (
|
|
<video
|
|
ref={videoRef}
|
|
src={fileUrl}
|
|
poster={poster}
|
|
controls
|
|
autoPlay
|
|
playsInline
|
|
className="w-full max-h-[70dvh] rounded-lg bg-black object-contain"
|
|
>
|
|
{t("downloads.player.unsupported")}
|
|
</video>
|
|
)}
|
|
</Modal>
|
|
);
|
|
}
|