Improve ATV handling

This commit is contained in:
ponzischeme89
2026-05-27 07:21:24 +12:00
parent 9291a97df9
commit c3137a2bdf
14 changed files with 2206 additions and 391 deletions
+262 -99
View File
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Emby Thumbnail Generator</title>
<title>EmbyToolkit</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
@@ -13,13 +13,13 @@
--surface2: #1a2030;
--surface3: #222840;
--border: #252d3d;
--border-active: #4a6fff;
--border-active: #14b8a6;
--text: #e8ecf4;
--text-2: #8892a8;
--text-3: #4e5a70;
--accent: #4a6fff;
--accent-h: #6384ff;
--accent-glow: rgba(74,111,255,0.12);
--accent: #14b8a6;
--accent-h: #2dd4bf;
--accent-glow: rgba(20,184,166,0.12);
--green: #34d399;
--green-bg: rgba(52,211,153,0.08);
--red: #f87171;
@@ -33,62 +33,73 @@
font-family: 'DM Sans', sans-serif;
background: var(--bg);
color: var(--text);
min-height: 100vh;
min-height: 100svh;
overflow: auto;
display: flex;
flex-direction: column;
display: grid;
grid-template-columns: 220px 1fr;
height: 100vh;
height: 100svh;
overflow: hidden;
}
/* ── Header ── */
.header {
height: 56px;
padding: 0 24px;
/* ── App Nav Sidebar ── */
.app-nav {
display: flex;
align-items: center;
gap: 14px;
border-bottom: 1px solid var(--border);
flex-direction: column;
background: var(--surface);
flex-shrink: 0;
border-right: 1px solid var(--border);
overflow: hidden;
}
.header-logo {
width: 30px; height: 30px;
background: var(--accent);
border-radius: 7px;
display: grid; place-items: center;
font-weight: 700; font-size: 12px; color: #fff;
flex-shrink: 0;
}
.header h1 { font-size: 15px; font-weight: 600; letter-spacing: -0.02em; }
.header-nav {
.app-nav-brand {
padding: 18px 16px;
display: flex;
align-items: center;
gap: 8px;
margin-left: 10px;
gap: 10px;
border-bottom: 1px solid var(--border);
flex-shrink: 0;
}
.nav-link {
padding: 6px 10px;
border-radius: 999px;
border: 1px solid var(--border);
.app-nav-logo {
width: 32px; height: 32px;
background: var(--accent);
border-radius: 8px;
display: grid; place-items: center;
color: #fff;
flex-shrink: 0;
}
.app-nav-name {
font-size: 15px;
font-weight: 700;
letter-spacing: -0.03em;
}
.app-nav-items {
list-style: none;
padding: 8px;
flex: 1;
overflow-y: auto;
margin: 0;
}
.app-nav-item {
display: flex;
align-items: center;
gap: 10px;
padding: 9px 12px;
border-radius: 8px;
color: var(--text-2);
text-decoration: none;
font-size: 13px;
font-weight: 500;
transition: background 0.12s, color 0.12s;
margin-bottom: 1px;
}
.app-nav-item:hover { background: var(--surface2); color: var(--text); }
.app-nav-item.active { background: var(--accent); color: #fff; }
.app-nav-footer {
padding: 14px 16px;
border-top: 1px solid var(--border);
display: flex;
align-items: center;
gap: 7px;
font-size: 12px;
font-weight: 600;
transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.nav-link:hover {
background: var(--surface2);
color: var(--text);
}
.nav-link.active {
background: var(--accent-glow);
border-color: var(--accent);
color: var(--text);
}
.header-status {
margin-left: auto;
display: flex; align-items: center; gap: 7px;
font-size: 12px; color: var(--text-2);
color: var(--text-2);
flex-shrink: 0;
}
.dot {
width: 7px; height: 7px; border-radius: 50%;
@@ -98,7 +109,6 @@
/* ── Body ── */
.body {
flex: 1;
display: grid;
grid-template-columns: 320px 1fr;
min-height: 0;
@@ -120,6 +130,55 @@
border-bottom: 1px solid var(--border);
flex-shrink: 0;
}
.studio-bulk-banner {
display: none;
margin-top: 10px;
align-items: center;
justify-content: space-between;
gap: 8px;
background: var(--surface2);
border: 1px solid var(--border);
border-radius: var(--r);
padding: 8px 10px;
}
.studio-bulk-banner.visible { display: flex; }
.studio-bulk-label {
font-size: 12px;
color: var(--text-2);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.studio-bulk-btn {
flex-shrink: 0;
padding: 5px 12px;
background: var(--accent);
color: #fff;
border: none;
border-radius: 6px;
font-size: 12px;
font-weight: 600;
font-family: inherit;
cursor: pointer;
transition: background 0.12s, opacity 0.12s;
}
.studio-bulk-btn:hover { background: var(--accent-h); }
.studio-bulk-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.studio-reset-btn {
flex-shrink: 0;
padding: 5px 10px;
background: transparent;
color: var(--red);
border: 1px solid var(--red);
border-radius: 6px;
font-size: 12px;
font-weight: 600;
font-family: inherit;
cursor: pointer;
transition: background 0.12s, opacity 0.12s;
}
.studio-reset-btn:hover { background: rgba(248,113,113,0.1); }
.studio-reset-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.search-inner { position: relative; }
.search-inner svg {
position: absolute; left: 11px; top: 50%;
@@ -809,12 +868,12 @@
.toast.err { background: rgba(248,113,113,.1); border: 1px solid var(--red); color: var(--red); }
@media (max-width: 1400px) {
.body { grid-template-columns: 280px minmax(0, 1fr); }
.body { grid-template-columns: 260px minmax(0, 1fr); }
.preview-shell { width: min(100%, 760px); }
}
@media (max-width: 1200px) {
.body { grid-template-columns: 248px minmax(0, 1fr); }
.body { grid-template-columns: 230px minmax(0, 1fr); }
.search-wrap,
.results-toolbar,
.results-footer,
@@ -876,19 +935,36 @@
</head>
<body>
<header class="header">
<div class="header-logo">TG</div>
<h1>Emby Thumbnail Generator</h1>
<nav class="header-nav">
<a class="nav-link active" href="/">Generator</a>
<a class="nav-link" href="/collections">Collections</a>
<a class="nav-link" href="/airing">Airing</a>
</nav>
<div class="header-status">
<nav class="app-nav">
<div class="app-nav-brand">
<div class="app-nav-logo">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.29 7 12 12 20.71 7"/><line x1="12" y1="22" x2="12" y2="12"/></svg>
</div>
<span class="app-nav-name">EmbyToolkit</span>
</div>
<ul class="app-nav-items">
<li><a class="app-nav-item active" href="/">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="m21 15-5-5L5 21"/></svg>
<span>Generator</span>
</a></li>
<li><a class="app-nav-item" href="/collections">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/></svg>
<span>Collections</span>
</a></li>
<li><a class="app-nav-item" href="/airing">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="7" width="20" height="15" rx="2"/><polyline points="17 2 12 7 7 2"/></svg>
<span>Airing</span>
</a></li>
<li><a class="app-nav-item" href="/bulk-assign">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"/></svg>
<span>Bulk Assign</span>
</a></li>
</ul>
<div class="app-nav-footer">
<span class="dot" id="statusDot"></span>
<span id="statusText">Checking…</span>
</div>
</header>
</nav>
<div class="body">
@@ -899,6 +975,13 @@
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
<input class="search-input" id="searchInput" type="text" placeholder="Search movies & shows…" autocomplete="off">
</div>
<div class="studio-bulk-banner" id="studioBulkBanner">
<span class="studio-bulk-label" id="studioBulkLabel">0 shows</span>
<div style="display:flex;gap:6px;flex-shrink:0">
<button class="studio-reset-btn" id="studioResetBtn">Reset All</button>
<button class="studio-bulk-btn" id="studioBulkBtn">Bulk Assign All</button>
</div>
</div>
</div>
<div class="results-toolbar" id="resultsToolbar" style="display:none">
<div class="results-count" id="resultsCount">0 results</div>
@@ -952,20 +1035,20 @@
<div class="primary-preview-shell" id="primaryPreviewShell">
<div class="primary-preview-head">
<span>Primary Preview</span>
<div class="primary-preview-tools">
<span>Primary Poster</span>
<div class="primary-preview-tools" id="primaryPreviewTools">
<button class="mini-link" id="btnPrimaryReset" type="button">Reset</button>
<span class="primary-preview-note" id="primaryPreviewMeta">100% · X 0 · Y -16</span>
</div>
</div>
<div class="primary-preview-frame" id="primaryPreviewFrame" title="Drag to position the poster crop. Use the mouse wheel to zoom.">
<div class="primary-preview-frame" id="primaryPreviewFrame" title="This applies the selected studio logo to the existing primary poster.">
<img id="primaryPreviewImg" src="" alt="">
<div class="primary-preview-zoom">
<div class="primary-preview-zoom" id="primaryPreviewZoom">
<button class="primary-preview-zoom-btn" id="btnPrimaryPreviewZoomOut" type="button" aria-label="Zoom out">-</button>
<button class="primary-preview-zoom-btn" id="btnPrimaryPreviewZoomIn" type="button" aria-label="Zoom in">+</button>
</div>
<div class="primary-preview-empty" id="primaryPreviewEmpty">Enable matching primary to edit the poster crop.</div>
<div class="primary-preview-hint">Drag to position • Wheel to zoom</div>
<div class="primary-preview-empty" id="primaryPreviewEmpty">Enable this to stamp the selected studio logo onto the existing primary poster.</div>
<div class="primary-preview-hint" id="primaryPreviewHint">No separate poster is generated.</div>
</div>
</div>
@@ -1074,9 +1157,9 @@
<div class="ctrl-group" id="studioPosGroup" style="display:none">
<label>Studio pos</label>
<div class="corner-grid" id="studioCornerGrid">
<button class="corner-btn" data-pos="top-left" title="Top left"></button>
<button class="corner-btn active" data-pos="top-left" title="Top left"></button>
<button class="corner-btn" data-pos="top-right" title="Top right"></button>
<button class="corner-btn active" data-pos="bottom-right" title="Bottom right"></button>
<button class="corner-btn" data-pos="bottom-right" title="Bottom right"></button>
<button class="corner-btn" data-pos="bottom-left" title="Bottom left"></button>
</div>
</div>
@@ -1096,10 +1179,10 @@
</div>
<div class="ctrl-group">
<label>Matching primary</label>
<label>Primary poster</label>
<label class="toggle-chip" for="matchPrimaryToggle">
<input type="checkbox" id="matchPrimaryToggle">
<span>Generate tall primary</span>
<span>Stamp studio logo onto existing poster</span>
</label>
</div>
@@ -1206,6 +1289,7 @@ const state = {
searchLimit: 12,
searchTotal: 0,
searchController: null,
studioKey: null,
categoriesLoaded: false,
};
@@ -1218,6 +1302,10 @@ const resultsList = $('#resultsList');
const resultsFooter = $('#resultsFooter');
const btnPrevPage = $('#btnPrevPage');
const btnNextPage = $('#btnNextPage');
const studioBulkBanner = $('#studioBulkBanner');
const studioBulkLabel = $('#studioBulkLabel');
const studioBulkBtn = $('#studioBulkBtn');
const studioResetBtn = $('#studioResetBtn');
const placeholder = $('#placeholder');
const previewFrame = $('#previewFrame');
const thumbImg = $('#thumbImg');
@@ -1226,6 +1314,9 @@ const primaryPreviewFrame = $('#primaryPreviewFrame');
const primaryPreviewImg = $('#primaryPreviewImg');
const primaryPreviewEmpty = $('#primaryPreviewEmpty');
const primaryPreviewMeta = $('#primaryPreviewMeta');
const primaryPreviewTools = $('#primaryPreviewTools');
const primaryPreviewZoom = $('#primaryPreviewZoom');
const primaryPreviewHint = $('#primaryPreviewHint');
const btnPrimaryReset = $('#btnPrimaryReset');
const btnPrimaryPreviewZoomOut = $('#btnPrimaryPreviewZoomOut');
const btnPrimaryPreviewZoomIn = $('#btnPrimaryPreviewZoomIn');
@@ -1440,9 +1531,12 @@ function updatePrimaryPreviewMeta() {
function setPrimaryPreviewVisible(visible) {
primaryPreviewShell.classList.toggle('visible', visible);
primaryZoomGroup.style.display = visible ? '' : 'none';
primaryPanXGroup.style.display = visible ? '' : 'none';
primaryPanYGroup.style.display = visible ? '' : 'none';
primaryZoomGroup.style.display = 'none';
primaryPanXGroup.style.display = 'none';
primaryPanYGroup.style.display = 'none';
primaryPreviewTools.style.display = 'none';
primaryPreviewZoom.style.display = 'none';
primaryPreviewHint.style.display = visible ? '' : 'none';
}
function syncPrimaryPreviewState() {
@@ -1450,18 +1544,15 @@ function syncPrimaryPreviewState() {
setPrimaryPreviewVisible(show);
if (!show) {
primaryPreviewImg.removeAttribute('src');
primaryPreviewEmpty.textContent = 'Enable matching primary to edit the poster crop.';
primaryPreviewEmpty.textContent = 'Enable this to stamp the selected studio logo onto the existing primary poster.';
primaryPreviewEmpty.style.display = '';
return;
}
if (state.cacheKey && state.primaryGenerated) {
primaryPreviewImg.src = `/api/cache/${state.cacheKey}/primary?t=${Date.now()}`;
primaryPreviewEmpty.style.display = 'none';
} else {
primaryPreviewImg.removeAttribute('src');
primaryPreviewEmpty.textContent = 'Generate to preview the tall poster crop.';
primaryPreviewEmpty.style.display = '';
}
primaryPreviewImg.removeAttribute('src');
primaryPreviewEmpty.textContent = selectedStudio === 'none'
? 'Select a studio to stamp its logo onto the existing primary poster. No separate poster is generated.'
: 'Applying will stamp the selected studio logo onto the existing primary poster. No separate poster is generated.';
primaryPreviewEmpty.style.display = '';
}
let primaryPreviewTimer;
@@ -1558,6 +1649,11 @@ async function doSearch(q, start = 0) {
resultsList.innerHTML = '<div class="empty"><div class="spinner" style="margin:0 auto 0"></div></div>';
resultsToolbar.style.display = 'flex';
resultsFooter.style.display = 'none';
studioBulkBanner.classList.remove('visible');
studioBulkBtn.disabled = false;
studioBulkBtn.textContent = 'Bulk Assign All';
studioResetBtn.disabled = false;
studioResetBtn.textContent = 'Reset All';
resultsCount.textContent = 'Searching...';
resultsPage.textContent = '';
try {
@@ -1570,6 +1666,13 @@ async function doSearch(q, start = 0) {
if (state.searchController !== controller) return;
state.searchTotal = data.total;
state.searchStart = data.start;
state.studioKey = data.studio_key || null;
if (state.studioKey && data.total > 0) {
studioBulkLabel.textContent = `${data.total} show${data.total !== 1 ? 's' : ''} — apply studio thumb to all`;
studioBulkBanner.classList.add('visible');
} else {
studioBulkBanner.classList.remove('visible');
}
if (!data.items.length) {
resultsList.innerHTML = '<div class="empty">No results</div>';
resultsCount.textContent = '0 results';
@@ -1598,6 +1701,7 @@ async function doSearch(q, start = 0) {
if (e.name === 'AbortError') return;
resultsToolbar.style.display = 'none';
resultsFooter.style.display = 'none';
studioBulkBanner.classList.remove('visible');
resultsList.innerHTML = `<div class="empty">Error: ${esc(e.message)}</div>`;
} finally {
if (state.searchController === controller) state.searchController = null;
@@ -1614,6 +1718,59 @@ btnNextPage.addEventListener('click', () => {
doSearch(state.searchQuery, state.searchStart + state.searchLimit);
});
studioResetBtn.addEventListener('click', async () => {
if (!state.studioKey) return;
if (!confirm(`Reset all ${state.searchQuery} thumbs and posters? This deletes custom images and reverts to Emby originals.`)) return;
studioResetBtn.disabled = true;
studioBulkBtn.disabled = true;
studioResetBtn.textContent = 'Resetting…';
try {
const r = await fetch('/api/bulk-reset/studio', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ studio_key: state.studioKey }),
});
const result = await r.json();
if (!r.ok) throw new Error(result?.detail || `${r.status}`);
studioBulkLabel.textContent = `✓ Reset ${result.reset} shows${result.skipped ? `, ${result.skipped} skipped` : ''}`;
studioResetBtn.textContent = 'Done';
} catch (e) {
studioBulkLabel.textContent = `Error: ${esc(e.message)}`;
studioResetBtn.textContent = 'Reset All';
studioResetBtn.disabled = false;
studioBulkBtn.disabled = false;
}
});
studioBulkBtn.addEventListener('click', async () => {
if (!state.studioKey) return;
studioBulkBtn.disabled = true;
studioBulkBtn.textContent = 'Fetching…';
try {
const r = await fetch(`/api/search?q=${encodeURIComponent(state.searchQuery)}&type=Series,Movie&start=0&limit=500`);
const data = await r.json();
if (!r.ok) throw new Error(data?.detail || `${r.status}`);
const ids = data.items.map(it => it.id);
if (!ids.length) throw new Error('No items found.');
studioBulkBtn.textContent = `Applying to ${ids.length}`;
const ar = await fetch('/api/bulk-assign/apply', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ item_ids: ids }),
});
const result = await ar.json();
if (!ar.ok) throw new Error(result?.detail || `${ar.status}`);
const n = result.applied_count ?? (result.applied || []).length;
const sk = result.skipped_missing_assets_count ?? (result.skipped_missing_assets || []).length;
studioBulkLabel.textContent = `✓ Applied to ${n}${sk ? `, skipped ${sk}` : ''}`;
studioBulkBtn.textContent = 'Done';
} catch (e) {
studioBulkLabel.textContent = `Error: ${esc(e.message)}`;
studioBulkBtn.textContent = 'Bulk Assign All';
studioBulkBtn.disabled = false;
}
});
// ── Select item ──
async function selectItem(item) {
// Don't re-select the same item
@@ -1650,6 +1807,7 @@ async function selectItem(item) {
newEpisodesToggle.checked = false;
seasonFinaleToggle.checked = false;
}
setStudioSelection(item.auto_studio || 'none', 'top-left');
// Clear stale image and start generating immediately
thumbImg.src = '';
@@ -1734,22 +1892,34 @@ darknessSlider.addEventListener('input', () => darknessVal.textContent = darknes
// Studio selector
let selectedStudio = 'none';
let studioPos = 'bottom-right';
let studioPos = 'top-left';
function setStudioSelection(studio, position = 'top-left') {
selectedStudio = studio;
studioPos = studio === 'appletv' ? 'top-right' : position;
studioGrid.querySelectorAll('.studio-btn').forEach(btn => {
btn.classList.toggle('active', btn.dataset.studio === selectedStudio);
});
studioPosGroup.style.display = selectedStudio === 'none' ? 'none' : '';
studioCornerGrid.querySelectorAll('.corner-btn').forEach(btn => {
btn.classList.toggle('active', btn.dataset.pos === studioPos);
});
syncPrimaryPreviewState();
}
studioGrid.querySelectorAll('.studio-btn').forEach(btn => {
btn.addEventListener('click', () => {
studioGrid.querySelectorAll('.studio-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
selectedStudio = btn.dataset.studio;
studioPosGroup.style.display = selectedStudio === 'none' ? 'none' : '';
setStudioSelection(btn.dataset.studio, studioPos);
});
});
studioCornerGrid.querySelectorAll('.corner-btn').forEach(btn => {
btn.addEventListener('click', () => {
if (selectedStudio === 'appletv' && btn.dataset.pos !== 'top-right') return;
studioCornerGrid.querySelectorAll('.corner-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
studioPos = btn.dataset.pos;
syncPrimaryPreviewState();
});
});
textColorPicker.addEventListener('input', () => textColorText.value = textColorPicker.value);
@@ -1758,7 +1928,6 @@ newEpisodesToggle.addEventListener('change', () => syncSeriesTagToggles('new'));
seasonFinaleToggle.addEventListener('change', () => syncSeriesTagToggles('finale'));
matchPrimaryToggle.addEventListener('change', () => {
syncPrimaryPreviewState();
if (state.item) generateThumb();
});
primaryZoomSlider.addEventListener('input', schedulePrimaryPreviewRegenerate);
primaryPanXSlider.addEventListener('input', schedulePrimaryPreviewRegenerate);
@@ -1960,13 +2129,7 @@ async function generateThumb({ silent = false } = {}) {
btnRegenerate.disabled = false;
updateBdUI();
if (!silent) {
if (matchPrimaryToggle.checked && primaryGenerated) {
showToast('Generated thumb + primary', 'ok');
} else if (matchPrimaryToggle.checked) {
showToast('Generated thumb', 'ok');
} else {
showToast('Generated', 'ok');
}
showToast('Generated thumb', 'ok');
}
} catch (e) {
if (e.name === 'AbortError') return;
@@ -2025,7 +2188,7 @@ btnApply.addEventListener('click', async () => {
if (!r.ok) throw new Error(await readErrorMessage(r));
const data = await r.json();
if (data.primary_attempted && data.primary_code) {
showToast('Applied thumb + primary poster', 'ok');
showToast('Applied thumb + studio logo to primary', 'ok');
} else if (data.primary_attempted && data.primary_error) {
showToast('Applied thumb only', 'ok');
} else {