Created
August 15, 2016 20:46
-
-
Save KingCprey/2808ef6a63dcd96834777649423eef52 to your computer and use it in GitHub Desktop.
Vodlocker Download Functional
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
//Download URL only accessible from input element named "videourl" | |
//Exists after flash player has loaded (inb4 haxed through flash) | |
function getDownloadURL(elem_name){ | |
var videlems=document.getElementsByName(elem_name); | |
if(videlems.length>0){return videlems[0].getAttribute("value"); | |
}else{return null;} | |
} | |
//The file title is accessible either from the element id "file_title" or the document title | |
function getVideoNameFromID(elem_id){ | |
var titelem=document.getElementById(elem_id); | |
return titelem==null?null:titelem.innerText.replace("Background Audio?","").replace("Close X","").trim(); | |
} | |
function getVideoNameFromTitle(title_string){ | |
var tit=title_string==null?document.title:title_string; | |
//The vodlocker title usually has "Watch x" at the start of the title | |
return tit.indexOf("Watch ")==0?tit.substring(6):tit; | |
} | |
function getVideoName(){ | |
var name=getVideoNameFromID("file_title"); | |
console.log(name); | |
if(name==null){name=getVideoNameFromTitle(document.title);} | |
console.log(name); | |
if(name==null){name="v.mp4";} | |
console.log(name); | |
return name; | |
} | |
//The name of the download depends upon the last part of the url (default is v.mp4) | |
//Checks if .mp4 exists within the string (doesn't check if at end however) | |
function setDownloadName(download_url,orig_name,name,extension){return download_url.replace(orig_name,(name.indexOf(extension)>0?name:name+extension));} | |
function createDownloadLink(link_url){ | |
var download_a=document.createElement("a"); | |
download_a.setAttribute("href",link_url); | |
download_a.setAttribute("target","_blank"); | |
return download_a; | |
} | |
function downloadCurrentFile(download_name){ | |
var durl=getDownloadURL("videourl"); | |
if(durl==null){ | |
alert("Video download URL does not exist on page"); | |
}else{ | |
var dname=(download_name==null)?getVideoName():download_name; | |
console.log(dname); | |
var dlink=setDownloadName(durl,"v.mp4",dname,".mp4"); | |
var da=createDownloadLink(dlink); | |
da.click(); | |
} | |
} | |
downloadCurrentFile(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment