Last active
April 17, 2020 12:23
-
-
Save dennisja/24ed5cf6648e1d8e78dce2a0e85ff9b7 to your computer and use it in GitHub Desktop.
A simple script to download pluralsight courses in the browser console.
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
// open all sections | |
$$('section.module:not(.open) header').forEach((h) => h.click()); | |
// get all list course videos in each section | |
let listItems = $$('section.module li'); | |
// download them | |
for (let i = 0; i < listItems.length; i++) { | |
let listItem = listItems[i]; | |
let title = listItem.querySelector('h3').textContent; | |
let number = `000${i}`.slice(-3); | |
let videoName = `${number}-${title}.mp4`; | |
listItem.click(); | |
await new Promise((resolve) => setTimeout(resolve, 3000)); | |
let video = document.querySelector('video'); | |
let url = video.src; | |
const response = await fetch(url); | |
const blob = await response.blob(); | |
let a = document.createElement('a'); | |
a.href = window.URL.createObjectURL(blob); | |
a.download = videoName; | |
document.body.appendChild(a); | |
a.click(); | |
a.remove(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be great if u could give more explanation. I tried to use this code inside browser console and it's not working