Skip to content

Instantly share code, notes, and snippets.

@t3k4y
Created July 31, 2019 07:38
Show Gist options
  • Save t3k4y/a88afc5907bca0ffaec316de9bdb8184 to your computer and use it in GitHub Desktop.
Save t3k4y/a88afc5907bca0ffaec316de9bdb8184 to your computer and use it in GitHub Desktop.
basic tampermonkey js to get video url
// ==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