Files
Proxer-Downloader/views/index.ejs
T
2026-10-23 18:19:44 +02:00

83 lines
10 KiB
Plaintext
Executable File

<%
const formValues = typeof values === 'object' && values ? values : {};
const selectedMode = formValues.mode === 'video' ? 'video' : 'series';
const isSeries = selectedMode === 'series';
const episodeLimit = typeof maxSeriesEpisodes === 'number' ? maxSeriesEpisodes : 500;
const destination = typeof outputDir === 'string' ? outputDir : 'Configured media folder';
const submissionError = typeof formError === 'string' ? formError : '';
const savedToken = typeof tokenStatus === 'object' && tokenStatus ? tokenStatus : { available: false, state: 'unknown' };
const languages = [['engsub', 'English subtitles'], ['engdub', 'English dub'], ['gersub', 'German subtitles'], ['gerdub', 'German dub']];
%>
<%- include('partials/header', { activePage: 'download' }) %>
<div class="page-heading">
<div><p class="eyebrow">YOUR DOWNLOAD LIBRARY</p><h1 class="page-title">New download</h1><p class="page-description">Queue a series or a single episode. Your workers take it from here.</p></div>
<a class="button button-secondary" href="/status">View queue <span aria-hidden="true">↗</span></a>
</div>
<div class="download-layout">
<section class="panel">
<div class="panel-header"><h2>Download details</h2><span class="muted small">Fields marked * are required</span></div>
<form method="POST" action="/queue" id="jobForm" class="panel-body download-form" data-max-episodes="<%= episodeLimit %>">
<% if (submissionError) { %>
<div id="form-error" class="inline-notice notice-warning" role="alert" tabindex="-1"><strong>Download not added</strong><p><%= submissionError %></p><p class="small">Your download details are kept below. Token values are never shown again; leave the field blank to try the saved token or paste a replacement.</p></div>
<% } %>
<fieldset class="mode-switch" id="download-mode" hidden>
<legend class="visually-hidden">Download mode</legend>
<label class="mode-choice"><input type="radio" name="mode" value="series" aria-controls="series-fields"<%- isSeries ? ' checked' : '' %>><span><strong>Series</strong><small>A range of episodes</small></span></label>
<label class="mode-choice"><input type="radio" name="mode" value="video" aria-controls="video-fields"<%- !isSeries ? ' checked' : '' %>><span><strong>Single episode</strong><small>One Proxer watch URL</small></span></label>
</fieldset>
<noscript><div class="inline-notice">Current mode: <strong><%= isSeries ? 'Series' : 'Single episode' %></strong>. Switch to <a href="/download?mode=series">Series</a> or <a href="/download?mode=video">Single episode</a> before filling out this form.</div></noscript>
<fieldset id="series-fields" class="form-section"<%- isSeries ? '' : ' hidden disabled' %>>
<legend class="section-label">01 <span>Choose your episodes</span></legend>
<div class="form-grid">
<div class="field"><label class="field-label" for="series-id">Series ID <span aria-hidden="true">*</span></label><input class="field-input" id="series-id" name="id" type="number" inputmode="numeric" min="1" max="9007199254740991" step="1" value="<%= formValues.id || '' %>" placeholder="e.g. 12345" required aria-describedby="series-id-hint"><p class="field-hint" id="series-id-hint">The numeric ID in the Proxer series or watch URL.</p></div>
<div class="field"><label class="field-label" for="language">Language <span aria-hidden="true">*</span></label><select class="field-input" id="language" name="language" required><% languages.forEach(([value, label]) => { %><option value="<%= value %>"<%- (formValues.language || 'engsub') === value ? ' selected' : '' %>><%= label %></option><% }) %></select></div>
<div class="field season-field"><label class="field-label" for="series-season">Season <span aria-hidden="true">*</span></label><input class="field-input" id="series-season" name="season" type="number" inputmode="numeric" min="0" max="9007199254740991" step="1" value="<%= formValues.season ?? '1' %>" required aria-describedby="season-hint"><p class="field-hint" id="season-hint">Used in the filename only. Use 0 for specials. Episode numbers still follow the Proxer source.</p></div>
<div class="field"><label class="field-label" for="episode-from">First episode <span aria-hidden="true">*</span></label><input class="field-input" id="episode-from" name="episode_from" type="number" inputmode="numeric" min="1" max="9007199254740991" step="1" value="<%= formValues.episode_from || '' %>" placeholder="1" required></div>
<div class="field"><label class="field-label" for="episode-to">Last episode <span aria-hidden="true">*</span></label><input class="field-input" id="episode-to" name="episode_to" type="number" inputmode="numeric" min="1" max="9007199254740991" step="1" value="<%= formValues.episode_to || '' %>" placeholder="12" required aria-describedby="episode-limit"><p class="field-hint" id="episode-limit">Both ends included. Up to <%= episodeLimit.toLocaleString('en') %> episodes per submission.</p></div>
</div>
</fieldset>
<fieldset id="video-fields" class="form-section"<%- isSeries ? ' hidden disabled' : '' %>>
<legend class="section-label">01 <span>Choose your episode</span></legend>
<div class="field"><label class="field-label" for="episode-url">Proxer episode URL <span aria-hidden="true">*</span></label><input class="field-input" id="episode-url" name="url" type="url" inputmode="url" value="<%= formValues.url || '' %>" maxlength="2048" placeholder="https://proxer.me/watch/12345/1/engsub" spellcheck="false" required aria-describedby="episode-url-hint"><p class="field-hint" id="episode-url-hint">Use the HTTPS watch URL. The episode and language are taken from this link.</p></div>
</fieldset>
<section class="form-section" aria-labelledby="filename-heading">
<h3 class="section-label" id="filename-heading">02 <span>Name your files</span></h3>
<div class="field"><label class="field-label" for="download-name"><span id="name-label"><%= isSeries ? 'Series title' : 'Filename' %></span> <span class="optional">Optional</span></label><input class="field-input" id="download-name" name="name" value="<%= formValues.name || '' %>" maxlength="255" placeholder="<%= isSeries ? 'e.g. My Series' : 'e.g. My SeriesS001E001_engsub' %>" aria-describedby="name-hint"><p class="field-hint" id="name-hint"><%= isSeries ? 'Enter the title without season or episode numbers. Season, episode and language are added automatically. Leave blank to use the series ID.' : 'Enter a filename without .mp4. Leave blank to use the series ID, episode and language.' %></p></div>
</section>
<section class="form-section" aria-labelledby="access-heading">
<h3 class="section-label" id="access-heading">03 <span>Provide access</span></h3>
<div class="token-cache-status" id="token-cache-status" data-state="<%= savedToken.state %>">
<span class="badge <%= savedToken.available ? 'badge-success' : savedToken.state === 'invalid' ? 'badge-warning' : 'badge-neutral' %>"><%= savedToken.available ? 'Token saved' : savedToken.state === 'invalid' ? 'Replacement needed' : savedToken.state === 'missing' ? 'No token saved' : 'Saved token checked on submission' %></span>
<p class="field-hint"><%= savedToken.available ? 'Leave the field blank to reuse it. Download access is checked again every time you add to the queue.' : savedToken.state === 'invalid' ? 'The saved token was rejected. Paste a fresh token to continue.' : savedToken.state === 'missing' ? 'Paste a token once. After a successful access check, it is saved for future submissions.' : savedToken.state === 'unavailable' ? 'Saved-token status is unavailable. Submission will retry the check before adding any jobs.' : 'Leave blank to try the saved token, or paste a replacement.' %></p>
<% if (savedToken.lastValidatedAt && Number.isFinite(new Date(savedToken.lastValidatedAt).getTime())) { %><p class="field-hint">Last access check: <time datetime="<%= savedToken.lastValidatedAt %>" id="token-checked-at"><%= new Date(savedToken.lastValidatedAt).toLocaleString('en-GB', { dateStyle: 'medium', timeStyle: 'short' }) %></time></p><% } %>
</div>
<div class="field"><label class="field-label" for="download-token">Session token <span class="optional">Leave blank to reuse saved token</span></label><div class="input-with-action"><input class="field-input" id="download-token" name="token" type="password" autocomplete="off" autocapitalize="none" spellcheck="false" maxlength="8192" placeholder="Paste a new token value" aria-describedby="token-hint"><button type="button" class="input-action" id="toggle-token" aria-pressed="false" aria-controls="download-token" hidden>Show</button></div><p class="field-hint" id="token-hint">Paste the cookie value only. A working token is stored in MongoDB and is never sent back to the browser. The first episode's source is checked before any jobs are added.</p></div>
</section>
<div class="form-actions"><button class="button button-primary" type="submit" id="queue-download">Add to queue <span aria-hidden="true">→</span></button><span class="muted small">Downloads start when a worker is available.</span></div>
</form>
</section>
<aside class="download-sidebar" aria-label="Download preview">
<section class="panel preview-panel">
<div class="panel-header"><h2>At a glance</h2><span class="badge badge-neutral" id="preview-mode"><%= isSeries ? 'Series' : 'Single episode' %></span></div>
<div class="panel-body">
<p class="preview-count"><strong id="preview-count">—</strong><span id="preview-count-label">episodes to queue</span></p>
<div class="preview-section"><h3>Filename preview</h3><p class="preview-filename" id="filename-preview">Fill in the episode details to see your filenames.</p><p class="field-hint" id="preview-last" hidden></p></div>
<div class="preview-section"><h3>Save location</h3><p class="destination-path"><%= destination %></p><p class="field-hint">Files are saved as MP4.</p></div>
<p class="preview-validation" id="preview-validation" aria-live="polite"></p>
</div>
</section>
<section class="help-card"><span class="help-icon" aria-hidden="true">i</span><div><h2>If verification is needed</h2><p>Downloads pause and keep the affected episode in the queue. Complete verification on Proxer, then use <strong>Resume after verification</strong> to retry.</p></div></section>
</aside>
</div>
<script src="/download.js" defer></script>
<%- include('partials/footer') %>