feat(lucida): Download single url

This commit is contained in:
Tibo De Peuter 2024-12-29 17:29:36 +01:00
parent 36cd2213f7
commit 7a115ad2b2
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
2 changed files with 20 additions and 6 deletions

View file

@ -5,7 +5,7 @@
"main": "src/download.ts",
"scripts": {
"build": "tsc",
"start": "node dist/download.js",
"start": "node dist/lucida.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {

View file

@ -1,6 +1,6 @@
import { firefox, Page, BrowserContext } from 'playwright';
import {firefox, Page, BrowserContext, Download} from 'playwright';
async function lucida(album: URL, context: BrowserContext): Promise<void> {
async function lucida(album: URL, timeout: number, context: BrowserContext): Promise<void> {
const page: Page = await context.newPage();
await page.goto('/');
@ -18,19 +18,33 @@ async function lucida(album: URL, context: BrowserContext): Promise<void> {
// Check 'Hide my download from recently downloaded' checkbox
await page.check('input[id="hide-from-ticker"]');
// Start download
await page.getByText('download full album').click();
page.on('download', download => download.path().then(console.log));
const downloadPromise: Promise<Download> = page.waitForEvent('download', { timeout: timeout });
const download: Download = await downloadPromise;
// Save the download to the Downloads folder
// TODO Set path (configurable)
await download.saveAs('/home/tdpeuter/Downloads/' + download.suggestedFilename());
await page.close();
}
(async () => {
// Launch a new Firefox browser instance
const browser = await firefox.launch({ headless: false }); // Set headless: true to run without UI
// TODO Allow to pass headless option as argument
const browser = await firefox.launch({ headless: true }); // Set headless: true to run without UI
const context = await browser.newContext({
acceptDownloads: true, // Enable download handling
baseURL: 'https://lucida.to'
});
const album = new URL('https://www.qobuz.com/us-en/album/liquid-spirit-gregory-porter/0060253743200');
await lucida(album, context);
const album: URL = new URL('https://www.qobuz.com/us-en/album/you-me-disclosure-eliza-doolittle/q5q4tg0cupgwa');
// const album: URL = new URL('https://www.qobuz.com/us-en/album/led-zeppelin-iv-hd-remastered-edition-led-zeppelin/0603497898503');
const timeout: number = 240000;
await lucida(album, timeout, context);
// Close the browser
await browser.close();