Skip to content

Instantly share code, notes, and snippets.

@kumarasinghe
Last active June 25, 2020 02:30
Show Gist options
  • Save kumarasinghe/3387adf50b6772d16383f21f68b07179 to your computer and use it in GitHub Desktop.
Save kumarasinghe/3387adf50b6772d16383f21f68b07179 to your computer and use it in GitHub Desktop.
LinkedIn Course Downloader Script
// go to the course page, press F12 and run this code in Java Script console.
// once done you get a list of video download links. Right click and save them or,
// download all at once with a tool of your choice (e.g. Chrome Simple Mass Downloader)
(async () => {
let SELECTOR_CHAPTER_EXPANDERS = '.classroom-toc-chapter__toggle'
let SELECTOR_LESSONS = '[data-control-name="toc_item"]'
let VIDEO_LOAD_WAIT = 3000
// expand chapters on sidebar except the first
let chapterNodes = document.querySelectorAll(SELECTOR_CHAPTER_EXPANDERS)
for (let i = 1; i < chapterNodes.length; ++i) { chapterNodes[i].click() }
// get lesson nodes
let lessonNodes = document.querySelectorAll(SELECTOR_LESSONS)
// click each lesson node and grab the video source
let anchorArray = []
for (let i = 0; i < lessonNodes.length; ++i) {
console.log('Parsing video ' + (i + 1) + ' of ' + lessonNodes.length + '...')
let lessonNode = lessonNodes[i]
if (lessonNode.innerText.toLowerCase().includes('quiz')) { continue } // skip quizes
lessonNode.click() // play lesson
// wait and get video URL
let videoURL = await new Promise(resolve => {
let interval = setInterval(() => {
let player = document.querySelector('video')
if (player && player.src && !player.src.includes('0123456789')) {
clearInterval(interval)
resolve(player.src)
player.src = '0123456789' // mark dirty
}
}, VIDEO_LOAD_WAIT)
})
let a = document.createElement('a')
a.href = videoURL
a.innerHTML = videoURL
anchorArray.push(a)
}
document.body.innerHTML = ''
anchorArray.forEach(el => {
document.body.appendChild(el)
document.body.appendChild(document.createElement('br'))
})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment