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();