add(ui/ux): keep episode numbers out of the audible query

This commit is contained in:
Steppenstreuner
2026-08-28 20:17:20 +02:00
parent f4177339f2
commit 951f68ca7d
3 changed files with 31 additions and 3 deletions
+29 -2
View File
@@ -785,6 +785,28 @@ $("#import-deselect-all").addEventListener("click", () => {
// ---- quick request from a scanned file ----
let quickItemIndex = null;
let quickEpisode = null;
// "017 - Titel", "Folge 17: Titel", "[003] Titel" -> episode number + rest.
// A bare number without a separator ("100 Stunden") or without a leading zero is
// left alone: there it is part of the title, not a numbering.
const EPISODE_PATTERNS = [
/^\s*(?:folge|teil|band|nr\.?)\s*(\d{1,4})\s*(?:[-–—._:]+\s*|\s+)/i, // "Folge 124: Titel"
/^\s*[\[(](\d{1,4})[\])]\s*(?:[-–—._:]+\s*|\s+)/, // "[003] Titel"
/^\s*(0\d{1,3})\s*(?:[-–—._:]+\s*|\s+)/, // "001 Titel"
/^\s*(\d{1,3})\s*[-–—._:]+\s*/, // "17 - Titel"
];
function splitEpisodeNumber(name) {
for (const re of EPISODE_PATTERNS) {
const m = name.match(re);
if (!m) continue;
const rest = name.slice(m[0].length).trim();
if (!rest) break; // the number *is* the name
return { number: parseInt(m[1], 10), rest };
}
return { number: null, rest: name };
}
function cleanFileName(name) {
return name
@@ -797,8 +819,13 @@ function cleanFileName(name) {
function openQuickDialog(i) {
quickItemIndex = i;
const item = scanItems[i];
// the episode number wrecks the Audible keyword search, so it is kept out of
// the query and used as the volume instead
const { number, rest } = splitEpisodeNumber(item.name);
quickEpisode = number;
$("#quick-file").textContent = (item.rel_dir ? item.rel_dir + "/" : "") + item.name;
$("#quick-q").value = cleanFileName(item.name);
$("#quick-episode").textContent = number != null ? `Folge ${number} — nicht mitgesucht` : "";
$("#quick-q").value = cleanFileName(rest);
$("#quick-library").innerHTML =
libOptions(item.media_type) || "<option value=''>— keine Library —</option>";
$("#quick-results").innerHTML = "";
@@ -893,7 +920,7 @@ async function pickQuickResult(r) {
const req = await createRequest({
library_id: parseInt(libId),
title: r.title, authors: r.authors, narrator: r.narrator || "",
external_id: r.external_id, volume: r.volume ?? null,
external_id: r.external_id, volume: r.volume ?? quickEpisode,
year: r.year, series: r.series, cover_url: r.cover_url,
});
setLastLib(scanItems[i].media_type, libId);
+1
View File
@@ -191,6 +191,7 @@
<dialog id="quick-dialog">
<h3>Suchen &amp; Anfragen</h3>
<p class="muted mono" id="quick-file"></p>
<p class="muted" id="quick-episode"></p>
<form id="quick-search-form" class="bar">
<input id="quick-q" placeholder="Titel/Serie suchen…" required />
<button type="submit">Suchen</button>