Created
July 31, 2019 07:38
-
-
Save t3k4y/a88afc5907bca0ffaec316de9bdb8184 to your computer and use it in GitHub Desktop.
basic tampermonkey js to get video url
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== | |
// @name teka artedownloader | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://www.arte.tv/de/videos/* | |
// @grant GM_download | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
console.log("----------- DWNL started ------------"); | |
let api_base = " https://api.arte.tv/api/player/v1/config/de/"; | |
var loc = window.location.pathname.split('/'); | |
var id = loc[3]; | |
var name = loc[4]; | |
var download_url = api_base + id; | |
console.log("----------- download-url", download_url); | |
window.onload = function () { | |
var para = document.createElement("a"); | |
para.setAttribute('id', 'dwnl'); | |
para.setAttribute('style', 'color: #333'); | |
var node = document.createTextNode("Download"); | |
para.appendChild(node); | |
document.getElementsByClassName('metas-infos')[0].insertBefore(para, null); | |
document.getElementById('dwnl').addEventListener("click", function(){ | |
// var r = confirm("download " + name + "?"); | |
// if (r == true) { | |
var getJSON = function(url, callback) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', url, true); | |
xhr.responseType = 'json'; | |
xhr.onload = function() { | |
var status = xhr.status; | |
if (status == 200) { | |
callback(null, xhr.response); | |
} else { | |
callback(status); | |
} | |
}; | |
xhr.send(); | |
}; | |
getJSON(download_url, function(err, data) { | |
if (err != null) { | |
console.error(err); | |
} else { | |
var down_url = data.videoJsonPlayer.VSR.HTTPS_SQ_1.url; | |
console.log("will download: ", down_url); | |
document.getElementById('dwnl').textContent = down_url; | |
document.getElementById('dwnl').setAttribute('href', down_url); | |
GM_download(down_url, "xx"); // not working on my chromium 65.0.3325.181 | |
} | |
}); | |
// } | |
}); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment