feat(lucida): Download single url
This commit is contained in:
parent
36cd2213f7
commit
7a115ad2b2
2 changed files with 20 additions and 6 deletions
|
@ -5,7 +5,7 @@
|
||||||
"main": "src/download.ts",
|
"main": "src/download.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"start": "node dist/download.js",
|
"start": "node dist/lucida.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -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();
|
const page: Page = await context.newPage();
|
||||||
|
|
||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
|
@ -18,19 +18,33 @@ async function lucida(album: URL, context: BrowserContext): Promise<void> {
|
||||||
// Check 'Hide my download from recently downloaded' checkbox
|
// Check 'Hide my download from recently downloaded' checkbox
|
||||||
await page.check('input[id="hide-from-ticker"]');
|
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();
|
await page.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
// Launch a new Firefox browser instance
|
// 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({
|
const context = await browser.newContext({
|
||||||
acceptDownloads: true, // Enable download handling
|
acceptDownloads: true, // Enable download handling
|
||||||
baseURL: 'https://lucida.to'
|
baseURL: 'https://lucida.to'
|
||||||
});
|
});
|
||||||
|
|
||||||
const album = new URL('https://www.qobuz.com/us-en/album/liquid-spirit-gregory-porter/0060253743200');
|
const album: URL = new URL('https://www.qobuz.com/us-en/album/you-me-disclosure-eliza-doolittle/q5q4tg0cupgwa');
|
||||||
await lucida(album, context);
|
// 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
|
// Close the browser
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|
Reference in a new issue