Created
February 21, 2022 05:16
-
-
Save manan-gup/9c165b362705a7900cdab8d97ac88bf0 to your computer and use it in GitHub Desktop.
Script to download an Egghead.io course
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import puppeteer from "puppeteer"; | |
import fs from "fs"; | |
import { execSync } from "child_process"; | |
const folder = process.argv[2]; // This array contains command line args passed to node | |
// First entry is node path, second is script path, thrid onwards are the args passed. | |
const URL = `https://egghead.io/courses/${folder}`; | |
async function main() { | |
const browser = await puppeteer.launch({ | |
headless: true, | |
}); | |
const webpage = await browser.newPage(); | |
await webpage.goto(URL, { | |
waitUntil: "networkidle0", | |
}); | |
// Select anchor tags with classes text-lg and font-semibold. | |
// Then get the property href for each, convert it to json and await all returned promises. | |
const list = await webpage.$$("a.text-lg.font-semibold"); | |
const hrefs = await Promise.all( | |
list.map((handle) => | |
handle.getProperty("href").then((href) => href.jsonValue()) | |
) | |
); | |
await browser.close(); | |
console.log(hrefs); | |
// Write hrefs to file | |
fs.writeFileSync( | |
"url-list.txt", | |
hrefs.reduce((prev, current) => { | |
return prev + current + "\n"; | |
}, "") | |
); | |
// Run yt-dlp on batch file | |
execSync( | |
`yt-dlp --batch-file 'url-list.txt' --concurrent-fragments 6 --paths 'C:\\Users\\Manan\\Videos\\${folder}' --output '[%(autonumber)d] %(title)s.%(ext)s'`, | |
{ shell: "powershell.exe" }, | |
(error, stdout, stderr) => { | |
console.log(error); | |
console.log(stdout); | |
console.log(stderr); | |
} | |
); | |
} | |
await main(); | |
process.exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment