diff --git a/src/lucida.ts b/src/lucida.ts index 3b8a07b..d79ce9b 100644 --- a/src/lucida.ts +++ b/src/lucida.ts @@ -1,4 +1,4 @@ -import {firefox, Page, BrowserContext, Download, Browser} from 'playwright'; +import {firefox, Page, BrowserContext, Download, Browser, Locator} from 'playwright'; async function lucida(album: URL, baseTimeout: number, context: BrowserContext): Promise { const page: Page = await context.newPage(); @@ -33,6 +33,28 @@ async function lucida(album: URL, baseTimeout: number, context: BrowserContext): // TODO Set path (configurable) await download.saveAs('/home/tdpeuter/Downloads/lucida/' + download.suggestedFilename()); + // TODO Check if booklet is available. + + await page.close(); +} + +async function booklet(album: URL, context: BrowserContext): Promise { + const page: Page = await context.newPage(); + + const bookletURL: URL = new URL('http://audiofil.hostronavt.ru/booklet.php?name=' + encodeURIComponent(album.href)); + await page.goto(bookletURL.href); + + // Find link with goodies + const link: Locator = page.locator('a').filter({hasText: '/goodies/'}); + const linkCount: number = await link.count(); + if (linkCount > 0) { + console.log(await link.innerHTML()); + } else { + console.log('No goodies link found'); + } + + // TODO Download the booklet. + await page.close(); } @@ -43,7 +65,7 @@ async function lucida(album: URL, baseTimeout: number, context: BrowserContext): 'https://www.qobuz.com/us-en/album/shes-gone-dance-on-disclosure/xrylx7j5794ab', 'https://www.qobuz.com/us-en/album/tondo-disclosure-eko-roosevelt/tlb5v175fbyxb' ]; - const testAlbums: string[] = [ + const withBooklet: string[] = [ 'https://www.qobuz.com/us-en/album/moon-safari-air/0724384497859' ]; @@ -55,9 +77,11 @@ async function lucida(album: URL, baseTimeout: number, context: BrowserContext): baseURL: 'https://lucida.to' }); - for (const album of testAlbums) { - await lucida(new URL(album), timeout, context); - } + // for (const album of testAlbums) { + // await lucida(new URL(album), timeout, context); + // } + + await booklet(new URL(withBooklet[0]), context); // Close the browser await browser.close();