diff --git a/docs-users/admin/audible.md b/docs-users/admin/audible.md index 03007879..5a16c4a8 100644 --- a/docs-users/admin/audible.md +++ b/docs-users/admin/audible.md @@ -69,9 +69,11 @@ Bridge's [Accounts tab](../getting-started/bridge-accounts.md#the-accounts-state ## The titles page -![Audible titles with their backup states and a warning for the saved destination of A Small Hour in Varrow](/img/screenshots/admin/audible-titles.png) +![Audible titles showing an invalid destination for A Small Hour in Varrow, an unmatched backup for Echo of the Drowned Choir and a successful backup for Orchard Cycle 4: The Silver Wood](/img/screenshots/admin/audible-titles.png) Choose **Destination...** on *A Small Hour in Varrow* to set a new place for its backup. +For *Echo of the Drowned Choir*, the server couldn't confirm that the book at the destination belongs to this title +(see [When the server can't match a finished backup](#when-the-server-cant-match-a-finished-backup)). **Server > Settings > Audible** lists every title your accounts own or have preordered. Each row says whether the title is **On this server** (with a link to diff --git a/screenshots/capture-bridge.mjs b/screenshots/capture-bridge.mjs index d09e3fc4..92bfe08a 100644 --- a/screenshots/capture-bridge.mjs +++ b/screenshots/capture-bridge.mjs @@ -104,6 +104,10 @@ const audible = {library: null, account: null, moduleOn: false}; const AUDIBLE_BACKUP = 'B0FAKE0004'; const AUDIBLE_REJECT = 'B0FAKE0025'; const AUDIBLE_DEST_TITLE = "The Cartographer's Return"; +// The titles shot's refused backup: Echo's destination is saved inside a folder of two +// discs that is then joined into one book, so its backup lands in a book of no title. +const AUDIBLE_REFUSED = 'B0FAKE0009'; +const AUDIBLE_TAPES = 'Household Recordings/Family Tapes'; // The Audible card on the Bridge's Accounts tab. const audibleCard = () => page.getByRole('region', {name: 'Audible', exact: true}); const clipShoot = async (p, locator, file) => { @@ -125,6 +129,20 @@ const untilKind = async (method, path, ms = 60000) => { } } }; +const titlePath = (asin) => `/admin/audible/titles/${audible.account}/${asin}`; +// Polls the title's row until `ended` answers true for it, throwing at once when its +// backup failed, was cancelled or waits for attention. +const untilBackup = async (asin, ended) => { + for (const until = Date.now() + 240000; Date.now() < until; await sleep(2000)) { + const {titles = []} = (await server(admin, 'GET', `/admin/audible/titles?account=${audible.account}&q=${asin}`)) ?? {}; + if (titles[0] && ended(titles[0])) return; + const imp = titles[0]?.import; + if (imp && ['failed', 'cancelled', 'needs_attention'].includes(imp.state)) { + throw new Error(`the backup of ${asin} ended ${imp.state} ${imp.code}`); + } + } + throw new Error(`the backup of ${asin} never finished`); +}; async function audibleShots() { await step('audible: library', async () => { @@ -228,19 +246,9 @@ async function audibleShots() { // so the two confirmations use the same seed as the titles page. await step('audible: a backup', async () => { if (!wanted(AUDIBLE_SHOTS.card, AUDIBLE_SHOTS.titles, AUDIBLE_SHOTS.backupAll, AUDIBLE_SHOTS.backupSkipped)) return; - const titlePath = (asin) => `/admin/audible/titles/${audible.account}/${asin}`; await server(admin, 'PATCH', titlePath(AUDIBLE_REJECT), {rejected: true}); await untilKind('POST', `${titlePath(AUDIBLE_BACKUP)}/backup`); - for (const until = Date.now() + 240000; Date.now() < until; await sleep(2000)) { - const {titles = []} = - (await server(admin, 'GET', `/admin/audible/titles?account=${audible.account}&q=${AUDIBLE_BACKUP}`)) ?? {}; - const imp = titles[0]?.import; - if (imp?.state === 'done' && titles[0].match) return; - if (imp && ['failed', 'cancelled', 'needs_attention'].includes(imp.state)) { - throw new Error(`the backup ended ${imp.state} ${imp.code}`); - } - } - throw new Error('the backup never finished'); + await untilBackup(AUDIBLE_BACKUP, (t) => t.import?.state === 'done' && t.match); }); const consolePage = await ctx.newPage(); @@ -276,12 +284,44 @@ async function audibleShots() { }); } await step('audible: console titles', async () => { - await consolePage.goto(`${ORIGIN}/admin/server?topic=audible`, {waitUntil: 'networkidle', timeout: 45000}); - await consolePage.getByRole('list', {name: 'Audible titles'}).waitFor({timeout: 15000}); - if (wanted(AUDIBLE_SHOTS.titles)) { - await consolePage.getByText(/Your destination is no longer valid/).first().waitFor(); + const want = wanted(AUDIBLE_SHOTS.titles); + try { + if (want) { + // The destination is saved before the discs are joined, as the refusal needs. + await server(admin, 'PATCH', titlePath(AUDIBLE_REFUSED), {dest_path: `${AUDIBLE_TAPES}/CD3`}); + for (const disc of ['CD1', 'CD2']) { + const dir = path.join(AUDIBLE_DIR, AUDIBLE_TAPES, disc); + await mkdir(dir, {recursive: true}); + if (!silence(path.join(dir, 'Track.mp3'), 5)) throw new Error('could not seed Family Tapes'); + } + await server(admin, 'PUT', `/admin/libraries/${audible.library.id}/folder-override${pathQuery(AUDIBLE_TAPES)}`, {mode: 'book'}); + await waitForScans(server, admin); + await untilKind('POST', `${titlePath(AUDIBLE_REFUSED)}/backup`); + await untilBackup(AUDIBLE_REFUSED, (t) => { + if (t.match) throw new Error('the backup meant to be refused matched its title'); + return t.fold_refusal_reason === 'not_own_book'; + }); + } + await consolePage.goto(`${ORIGIN}/admin/server?topic=audible`, {waitUntil: 'networkidle', timeout: 45000}); + await consolePage.getByRole('list', {name: 'Audible titles'}).waitFor({timeout: 15000}); + if (want) { + await consolePage.getByText(/Your destination is no longer valid/).first().waitFor(); + const echo = consolePage.getByRole('listitem').filter({hasText: 'Echo of the Drowned Choir'}); + const reason = "The server couldn't confirm that the book at the backup destination belongs to this title."; + await echo.getByText(reason, {exact: true}).waitFor({timeout: 15000}); + if (await echo.getByText('Backed up', {exact: true}).isVisible()) throw new Error('the refused backup shows as backed up'); + } + await tallShoot(consolePage, AUDIBLE_SHOTS.titles, {settle: 1000, max: 2600, fitSettle: 800}); + } finally { + if (want) { + // Back up everything skips a done backup whose book is still indexed, so Echo + // would drop out of the batch shot later in this run (16 queued, as the + // confirmation before it shows). Its book leaves the library again here. + await rm(path.join(AUDIBLE_DIR, AUDIBLE_TAPES), {recursive: true, force: true}); + await server(admin, 'POST', `/admin/libraries/${audible.library.id}/scan`); + await waitForScans(server, admin); + } } - await tallShoot(consolePage, AUDIBLE_SHOTS.titles, {settle: 1000, max: 2600, fitSettle: 800}); }); await step('audible: destination', async () => { if (!wanted(AUDIBLE_SHOTS.destination)) return; diff --git a/screenshots/manifest.mjs b/screenshots/manifest.mjs index 510722fd..d55e540a 100644 --- a/screenshots/manifest.mjs +++ b/screenshots/manifest.mjs @@ -230,7 +230,7 @@ export const SHOTS = [ {file: 'admin/audible-backup-settings.png', capture: 'bridge', audible: true, title: 'Admin - Audible account settings', hint: "the accounts card's Account settings... dialog (clipped; the file keeps its 4b name): Back up by itself (Only books you choose) with its new-purchases-only hint, the empty Placement template with its hint, Sync listening places with Audible (off) with its hint, the legal line, Save"}, {file: 'admin/audible-backup-all.png', capture: 'bridge', audible: true, title: 'Admin - Back up everything', hint: 'The confirmation with the eligible book count, size estimate and Back up button'}, {file: 'admin/audible-backup-all-skipped.png', capture: 'bridge', audible: true, title: 'Admin - Audible backups queued', hint: 'The confirmation after a real batch with the queued count and one skipped title whose stored destination no longer validates'}, - {file: 'admin/audible-titles.png', capture: 'bridge', audible: true, title: 'Admin - Audible titles', hint: 'Settings > Audible with the invalid destination warning on A Small Hour in Varrow and the other row states, including matched and backed-up books'}, + {file: 'admin/audible-titles.png', capture: 'bridge', audible: true, title: 'Admin - Audible titles', hint: 'Settings > Audible with an invalid destination for A Small Hour in Varrow, a backup the server could not match to Echo of the Drowned Choir, and matched and backed-up books'}, {file: 'admin/audible-destination.png', capture: 'bridge', audible: true, title: 'Admin - Audible destination', hint: "a title's Destination... dialog (clipped) on The Cartographer's Return, a folder typed (Wen Liang/Mapmakers/MM03 - The Cartographer's Return; not saved), the hint, Save"}, // ── AudioSilo Meta site (meta.audiosilo.app; desktop 1440x900, dark) ──── diff --git a/static/img/screenshots/admin/audible-titles.png b/static/img/screenshots/admin/audible-titles.png index 46747da7..26749512 100644 Binary files a/static/img/screenshots/admin/audible-titles.png and b/static/img/screenshots/admin/audible-titles.png differ