Last active
April 7, 2019 19:10
-
-
Save xNWDD/03cb0809b0d09c02e454d74d4846c574 to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @updateURL https://gist.github.com/xNWDD/03cb0809b0d09c02e454d74d4846c574/raw/GDCBVD.user.js | |
// @downloadURL https://gist.github.com/xNWDD/03cb0809b0d09c02e454d74d4846c574/raw/GDCBVD.user.js | |
// @name GDC Browse Video Downloader | |
// @description Tested with Tampermonkey in Firefox, Should not work in Greasemonkey, May Freeze Violentmonkey | |
// @version 2019r1 | |
// @include /https?://www.gdcvault.com/*/ | |
// @connect cdnapisec.kaltura.com | |
// @connect *.akamaihd.net | |
// @grant GM_download | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
(function injector() { | |
'use strict'; | |
if (document.body.querySelectorAll('a.session_item').length == 0) | |
return setTimeout(injector,1000); | |
[].slice.call(document.body.querySelectorAll('a.session_item')) //grab all talks | |
.filter(v=>v.querySelector('.video')) //filter only videos | |
.map(d=>({d:d,u:d.getAttribute("onclick")||d.href})) //pick href if no onclick | |
.filter(o=>!o.u.startsWith("loginPopup(")) //don't show buttons for unaccessible vids. | |
.map(o=>({d:o.d,i:o.u.match(/(play\/|cid=|\('[0-9]+',')([0-9]+)/)[2]})) //fetch the ids | |
.map(o=>({d:o.d,u:location.protocol+"//"+location.host+"/play/"+o.i})) //generate urls from ids | |
.forEach(o=>{ | |
const img = document.createElement("img"); //create download image | |
img.src="/img/icon_play.png"; //use play icon as texture | |
img.style="transform:rotate(90deg)"; //rotate it 90 deg clockwise | |
img.addEventListener('click',(event)=>{ //start download process | |
const origin = "https://www.gdcvault.com/play/0/GDCBVD"; | |
GM_xmlhttpRequest({method:"GET",headers:{Origin:origin,Referer:origin},url:o.u,onload:(r)=>{ //download talk page (html only) | |
const filename = r.responseText.match(/:title" content="(([^/>])+)\/>/)[1].replace(/[<|>|:|"|/|\|*|_| ]+/g," ").trim().replace(/[ |?]+/g,"_"); //generate valid win32 names | |
const iframe_path = r.responseText.match(/<iframe src="([^"]+)/i)[1]; //extract iframe address (evt/sevt) | |
GM_xmlhttpRequest({method:"GET",headers:{Origin:origin,Referer:origin},url:iframe_path,onload:(r)=>{ //download video page (html only) | |
const w = eval("("+r.responseText.match(/window.kalturaIframePackageData = ([^;]+)/i)[1]+")"); | |
const video_redirect_url = "https://cdnapisec.kaltura.com/p/" + w.playerConfig.widgetId.substring(1) + "/sp/" + w.playerConfig.widgetId.substring(1) + "00/playManifest/entryId/" + w.playerConfig.entryId + "/flavorIds/" + w.entryResult.contextData.flavorAssets.filter(o=>o.fileExt == "mp4").sort((a,b)=>a.bitrate<b.bitrate)[0].id + "/format/url/protocol/http/a.mp4"; | |
GM_xmlhttpRequest({timeout:2500,method:"GET",headers:{Origin:origin,Referer:origin},url:video_redirect_url,onerror:(r)=>{ //download video page (html only) | |
GM_download({url:r.error.match(/http.*?.mp4/i)[0],name:filename+".mp4",saveAs:true}); //open download popup to chose location | |
}}); | |
}}); | |
}}); | |
event.preventDefault(); //prevent click from changing url | |
event.stopPropagation(); //prevent click from triggering in parents | |
}); | |
o.d.appendChild(img); //append download button | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment