fix(lucida): Use locators #9

This commit is contained in:
Tibo De Peuter 2025-01-01 17:42:25 +01:00
parent 48fe8886f7
commit fe523c91fe
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2

View file

@ -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<boolean | string> {
export async function openAlbum(album: URL, context: BrowserContext): Promise<Page> {
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<boolean | string> {
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();