From fe523c91fe1843efb8fcc53a2fd29e5aa5f0da69 Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Wed, 1 Jan 2025 17:42:25 +0100 Subject: [PATCH] fix(lucida): Use locators #9 --- src/lucida.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lucida.ts b/src/lucida.ts index 97ae8fe..82c9a8c 100644 --- a/src/lucida.ts +++ b/src/lucida.ts @@ -1,22 +1,27 @@ -import {firefox, Page, BrowserContext, Download, Browser, Locator} from 'playwright'; +import {BrowserContext, Download, Locator, Page} from 'playwright'; -export async function lucida(album: URL, baseTimeout: number, context: BrowserContext): Promise { +export async function openAlbum(album: URL, context: BrowserContext): Promise { const page: Page = await context.newPage(); - await page.goto('/'); // Fill in the album URL - await page.fill('input[id="download"]', album.href); + await page.locator('input[id="download"]').first().fill(album.href); // Wait for the XHR request to complete await Promise.all([ page.waitForResponse(res => res.url().includes('/api/load') && res.status() == 200), - page.click('input[id="go"]'), + page.locator('input[id="go"]').first().click(), page.waitForLoadState('domcontentloaded') ]); + return page; +} + +export async function lucida(album: URL, baseTimeout: number, context: BrowserContext): Promise { + const page: Page = await openAlbum(album, context); + // Check 'Hide my download from recently downloaded' checkbox - await page.check('input[id="hide-from-ticker"]'); + await page.locator('input[id="hide-from-recent"]').first().setChecked(true); // Parse info const albumName: string = (await page.locator('h1[class="svelte-6pt9ji"]').last().innerText()).trim();