Last active
September 5, 2024 02:21
-
-
Save mahadirz/944a07fe1a45a0c0c5f0 to your computer and use it in GitHub Desktop.
Grab laracast all video download links for series and to be used by IDM. Useful in case you want to watch the videos later from you own saved copy
This file contains 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
/** | |
*@author Mahadir Ahmad | |
*Revision | |
* 22/11/2015 - Able to grab lesson or series | |
* | |
* Laracast Video download link grabber | |
* This script is used with IDM | |
* 0. Visit any laracast series (eg: https://laracasts.com/series/whats-new-in-laravel-5-1/episodes/1) | |
* 1. Open Chrome console | |
* 2. paste this script and hit enter | |
* 3. Save the links.html | |
* 4. Run the html file from any server (eg: localhost) | |
* 5. Right click and choose "Download all links with IDM" | |
*/ | |
var i =1; | |
var total = 0; | |
var downloadURL = []; | |
getAllLinks(document.documentElement.outerHTML); | |
function getAllLinks(data){ | |
var count =0; | |
var myRegexp = /<span class="Lesson-List__title(?: utility-flex)?">[\s\S]+?<a href="(.+?)">([\s\S]+?)<\/a>/gi; | |
while ( ( match = myRegexp.exec(data) ) != null ) | |
{ | |
url = "https://laracasts.com"+match[1]; | |
title = match[2]; | |
$.get(url,{}, function(data) { | |
process(data); | |
} | |
); | |
count++; | |
} | |
total = count; | |
console.log(count); | |
} | |
function process(data){ | |
//var myRegexp = /<a href='\/downloads\/(\d{1,10})\?type=episode'/g; | |
//the episode is optional | |
var myRegexp = /<a href='\/downloads\/(\d{1,10})(\?type=episode)?'/g; | |
var match = myRegexp.exec(data); | |
var id = match[1]; | |
var episode = match[2] !=undefined? match[2]:" "; | |
var url = '<a href="https://laracasts.com/downloads/'+id+episode+'">'+i+'</a>'; | |
//console.log('<a href="https://laracasts.com/downloads/'+id+'?type=episode">'+title+'</a>'); | |
downloadURL.push(url); | |
i++; | |
if(i>total){ | |
finished(); | |
} | |
} | |
function finished() | |
{ | |
console.log('finished'); | |
//generate | |
var html = "<html>"; | |
for(i=0;i<downloadURL.length;i++){ | |
//console.log(downloadURL[i]); | |
html += downloadURL[i] + "\n"; | |
} | |
html += "</html>"; | |
download(html, 'links.html', 'text/html'); | |
} | |
function download(strData, strFileName, strMimeType) { | |
var D = document, | |
A = arguments, | |
a = D.createElement("a"), | |
d = A[0], | |
n = A[1], | |
t = A[2] || "text/plain"; | |
//build download link: | |
a.href = "data:" + strMimeType + "charset=utf-8," + escape(strData); | |
if (window.MSBlobBuilder) { // IE10 | |
var bb = new MSBlobBuilder(); | |
bb.append(strData); | |
return navigator.msSaveBlob(bb, strFileName); | |
} /* end if(window.MSBlobBuilder) */ | |
if ('download' in a) { //FF20, CH19 | |
a.setAttribute("download", n); | |
a.innerHTML = "downloading..."; | |
D.body.appendChild(a); | |
setTimeout(function() { | |
var e = D.createEvent("MouseEvents"); | |
e.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
a.dispatchEvent(e); | |
D.body.removeChild(a); | |
}, 66); | |
return true; | |
}; /* end if('download' in a) */ | |
//do iframe dataURL download: (older W3) | |
var f = D.createElement("iframe"); | |
D.body.appendChild(f); | |
f.src = "data:" + (A[2] ? A[2] : "application/octet-stream") + (window.btoa ? ";base64" : "") + "," + (window.btoa ? window.btoa : escape)(strData); | |
setTimeout(function() { | |
D.body.removeChild(f); | |
}, 333); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment