Tauri 2 shell with a React/TypeScript interface and libmpv playback composed beneath the web view (DirectComposition on Windows). Shared code with per-OS platform modules and configs so macOS and Linux can follow. - Plex sign-in (browser, plex.tv/link or manual), server selection, Plex Home - Home, Movies and TV Shows (Discover, Library, Collections), search, people - Title pages with logos, ratings, cast, extras, seasons and episodes - Direct play with Plex conversion fallback, tracks, markers, autoplay - Metadata editing, artwork, fix match, refresh, analyze and deletion - Resumable offline downloads - App settings and Plex server administration with a live dashboard - Signed updater feed and Forgejo CI Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
208 lines
9 KiB
TypeScript
208 lines
9 KiB
TypeScript
import { useState } from 'react';
|
|
import * as api from '../../plex/api';
|
|
import type { Item } from '../../plex/types';
|
|
import { useServer } from '../../app/session';
|
|
import { invalidateItem, invalidateLibrary, useItem } from '../../app/queries';
|
|
import { openDialog } from '../../app/actions';
|
|
import { Dialog, toast, toastError } from '../../ui/overlays';
|
|
import { Button, PageLoader, Segmented } from '../../ui/primitives';
|
|
import { Icon } from '../../ui/Icon';
|
|
|
|
type Tab = 'general' | 'tags' | 'artwork';
|
|
|
|
const FIELDS: { key: string; label: string; types: string[]; multiline?: boolean; type?: string }[] = [
|
|
{ key: 'title', label: 'Title', types: ['movie', 'show', 'season', 'episode', 'collection'] },
|
|
{ key: 'titleSort', label: 'Sort title', types: ['movie', 'show', 'collection'] },
|
|
{ key: 'originalTitle', label: 'Original title', types: ['movie', 'show'] },
|
|
{ key: 'originallyAvailableAt', label: 'Release date', types: ['movie', 'show', 'episode'], type: 'date' },
|
|
{ key: 'contentRating', label: 'Content rating', types: ['movie', 'show', 'collection'] },
|
|
{ key: 'studio', label: 'Studio', types: ['movie', 'show'] },
|
|
{ key: 'tagline', label: 'Tagline', types: ['movie', 'show'] },
|
|
{ key: 'summary', label: 'Summary', types: ['movie', 'show', 'season', 'episode', 'collection'], multiline: true },
|
|
];
|
|
|
|
const TAGS: { key: string; label: string; source: keyof Item; types: string[] }[] = [
|
|
{ key: 'genre', label: 'Genres', source: 'genres', types: ['movie', 'show'] },
|
|
{ key: 'collection', label: 'Collections', source: 'collections', types: ['movie', 'show'] },
|
|
{ key: 'label', label: 'Labels', source: 'labels', types: ['movie', 'show', 'episode', 'season', 'collection'] },
|
|
{ key: 'director', label: 'Directors', source: 'directors', types: ['movie', 'episode'] },
|
|
{ key: 'writer', label: 'Writers', source: 'writers', types: ['movie', 'episode'] },
|
|
{ key: 'country', label: 'Countries', source: 'countries', types: ['movie', 'show'] },
|
|
];
|
|
|
|
function TagEditor({ label, values, onChange, locked, onLock }: { label: string; values: string[]; onChange: (v: string[]) => void; locked: boolean; onLock: () => void }) {
|
|
const [draft, setDraft] = useState('');
|
|
const add = () => {
|
|
const v = draft.trim();
|
|
if (v && !values.includes(v)) onChange([...values, v]);
|
|
setDraft('');
|
|
};
|
|
return (
|
|
<div className="field">
|
|
<span>
|
|
{label}
|
|
<LockToggle locked={locked} onClick={onLock} />
|
|
</span>
|
|
<div className="tag-editor">
|
|
{values.map((v) => (
|
|
<span key={v} className="chip">
|
|
{v}
|
|
<button aria-label={`Remove ${v}`} onClick={() => onChange(values.filter((x) => x !== v))}>
|
|
<Icon name="x" size={12} />
|
|
</button>
|
|
</span>
|
|
))}
|
|
<input
|
|
value={draft}
|
|
placeholder="Add…"
|
|
onChange={(e) => setDraft(e.target.value)}
|
|
onKeyDown={(e) => {
|
|
if (e.key === 'Enter' || e.key === ',') {
|
|
e.preventDefault();
|
|
add();
|
|
} else if (e.key === 'Backspace' && !draft && values.length) onChange(values.slice(0, -1));
|
|
}}
|
|
onBlur={add}
|
|
/>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function LockToggle({ locked, onClick }: { locked: boolean; onClick: () => void }) {
|
|
return (
|
|
<button type="button" className={`lock-toggle${locked ? ' on' : ''}`} onClick={onClick} title={locked ? 'Locked: refreshes keep this value' : 'Unlocked: refreshes may replace this value'}>
|
|
<Icon name={locked ? 'lock' : 'unlock'} size={12} />
|
|
</button>
|
|
);
|
|
}
|
|
|
|
export function EditMetadataDialog({ item: initial, onClose }: { item: Item; onClose: () => void }) {
|
|
const server = useServer();
|
|
const full = useItem(initial.id);
|
|
const item = full.data ?? initial;
|
|
const [tab, setTab] = useState<Tab>('general');
|
|
const [values, setValues] = useState<Record<string, string> | null>(null);
|
|
const [tags, setTags] = useState<Record<string, string[]> | null>(null);
|
|
const [locks, setLocks] = useState<Record<string, boolean>>({});
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
const fields = FIELDS.filter((f) => f.types.includes(item.type));
|
|
const tagFields = TAGS.filter((t) => t.types.includes(item.type));
|
|
const lockedFields: Record<string, boolean> = Object.fromEntries((item.raw?.Field ?? []).map((f: any) => [f.name, !!f.locked]));
|
|
|
|
if (full.data && !values) {
|
|
setValues(Object.fromEntries(fields.map((f) => [f.key, String(item.raw?.[f.key] ?? '')])));
|
|
setTags(Object.fromEntries(tagFields.map((t) => [t.key, ((item[t.source] as { tag: string }[]) ?? []).map((x) => x.tag)])));
|
|
setLocks(lockedFields);
|
|
}
|
|
|
|
const save = async () => {
|
|
if (!values || !tags) return;
|
|
setBusy(true);
|
|
try {
|
|
const changed: Record<string, string> = {};
|
|
for (const f of fields) if ((values[f.key] ?? '') !== String(item.raw?.[f.key] ?? '')) changed[f.key] = values[f.key];
|
|
const tagChanges: Record<string, { add: string[]; remove: string[] }> = {};
|
|
for (const t of tagFields) {
|
|
const before = ((item[t.source] as { tag: string }[]) ?? []).map((x) => x.tag);
|
|
const after = tags[t.key];
|
|
if (before.join('\u0000') !== after.join('\u0000')) tagChanges[t.key] = { add: after, remove: before.filter((b) => !after.includes(b)) };
|
|
}
|
|
const lockChanges: Record<string, boolean> = {};
|
|
for (const [k, v] of Object.entries(locks)) if (!!lockedFields[k] !== v) lockChanges[k] = v;
|
|
for (const k of [...Object.keys(changed), ...Object.keys(tagChanges)]) if (!(k in lockChanges)) lockChanges[k] = true;
|
|
if (!Object.keys(changed).length && !Object.keys(tagChanges).length && !Object.keys(lockChanges).length) {
|
|
onClose();
|
|
return;
|
|
}
|
|
await api.editMetadata(server, item, changed, tagChanges, lockChanges);
|
|
toast('Metadata saved', 'success');
|
|
invalidateItem(item.id);
|
|
invalidateLibrary();
|
|
onClose();
|
|
} catch (e) {
|
|
toastError(e);
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Dialog
|
|
title="Edit metadata"
|
|
subtitle={`${item.title}${item.librarySectionTitle ? ` · ${item.librarySectionTitle}` : ''}`}
|
|
onClose={onClose}
|
|
width={760}
|
|
className="edit-dialog"
|
|
footer={
|
|
<>
|
|
<span className="dialog-note">
|
|
<Icon name="lock" size={13} /> Edited fields are locked so metadata refreshes keep them.
|
|
</span>
|
|
<div className="actions">
|
|
<Button variant="ghost" onClick={onClose}>
|
|
Cancel
|
|
</Button>
|
|
<Button variant="primary" icon="check" busy={busy} onClick={save} disabled={!values}>
|
|
Save
|
|
</Button>
|
|
</div>
|
|
</>
|
|
}
|
|
>
|
|
<Segmented
|
|
value={tab}
|
|
onChange={setTab}
|
|
options={[
|
|
{ value: 'general', label: 'General' },
|
|
...(tagFields.length ? [{ value: 'tags' as Tab, label: 'Tags' }] : []),
|
|
{ value: 'artwork', label: 'Artwork' },
|
|
]}
|
|
className="dialog-tabs"
|
|
/>
|
|
{!values || !tags ? (
|
|
<PageLoader />
|
|
) : tab === 'general' ? (
|
|
<div className="field-grid">
|
|
{fields.map((f) => (
|
|
<label key={f.key} className="field" style={f.multiline || f.key === 'title' || f.key === 'tagline' ? { gridColumn: '1 / -1' } : undefined}>
|
|
<span>
|
|
{f.label}
|
|
<LockToggle locked={!!locks[f.key]} onClick={() => setLocks((l) => ({ ...l, [f.key]: !l[f.key] }))} />
|
|
</span>
|
|
{f.multiline ? (
|
|
<textarea value={values[f.key]} onChange={(e) => setValues({ ...values, [f.key]: e.target.value })} rows={6} />
|
|
) : (
|
|
<input type={f.type ?? 'text'} value={values[f.key]} onChange={(e) => setValues({ ...values, [f.key]: e.target.value })} />
|
|
)}
|
|
</label>
|
|
))}
|
|
</div>
|
|
) : tab === 'tags' ? (
|
|
<div>
|
|
{tagFields.map((t) => (
|
|
<TagEditor key={t.key} label={t.label} values={tags[t.key]} onChange={(v) => setTags({ ...tags, [t.key]: v })} locked={!!locks[t.key]} onLock={() => setLocks((l) => ({ ...l, [t.key]: !l[t.key] }))} />
|
|
))}
|
|
</div>
|
|
) : (
|
|
<div className="artwork-tab">
|
|
{(
|
|
[
|
|
['poster', 'Poster', item.thumb, 'poster'],
|
|
['art', 'Background', item.art, 'landscape'],
|
|
['clearLogo', 'Logo', item.logo, 'logo'],
|
|
] as const
|
|
).map(([type, label, path, shape]) => (
|
|
<button key={type} className={`artwork-choice ${shape}`} onClick={() => openDialog({ kind: 'artwork', item, type })}>
|
|
<div className="artwork-choice-img">{path ? <img src={server.image(path, shape === 'poster' ? 200 : 360, shape === 'poster' ? 300 : 200, { format: shape === 'logo' ? 'png' : 'jpeg' })} alt="" /> : <Icon name="image" size={24} />}</div>
|
|
<span>
|
|
{label} <Icon name="next" size={13} />
|
|
</span>
|
|
</button>
|
|
))}
|
|
</div>
|
|
)}
|
|
</Dialog>
|
|
);
|
|
}
|