TVI Play Download

Inclui comando do rtmpdump nas páginas da TVI para fazer download do vídeo.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        TVI Play Download
// @description Inclui comando do rtmpdump nas páginas da TVI para fazer download do vídeo.
// @namespace   daniel-sousa-me
// @include     http://www.tvi.iol.pt/programa/*
// @grant       none
// @version     1.0.1
// ==/UserScript==
// Based on RTP Play Download, since I didn't know how to create GreaseMonkey scripts

var metaTags=document.getElementsByTagName("meta");

var full_video_url = "";
for (var i = 0; i < metaTags.length; i++) {
    if (metaTags[i].getAttribute("property") == "og:video") {
        full_video_url = metaTags[i].getAttribute("content");
        break;
    }
}

var rtmp_dump_cmd = "rtmpdump -e -R -r "+getUrlVars(full_video_url)["streamer"]+"/"+getUrlVars(full_video_url)["file"];

var parentGuest = document.getElementsByClassName("seccao")[0];
// http://stackoverflow.com/questions/7258185/javascript-append-child-after-element/7258301#7258301
parentGuest.parentNode.insertBefore(document.createTextNode(rtmp_dump_cmd), parentGuest.nextSibling);

var a = document.createElement("a");
if (link.length != 0) {
	a.setAttribute("href",link);
	a.appendChild(document.createTextNode("Link Directo"));
}
else {
	a.appendChild(document.createTextNode(flashvars));
}
div_add.appendChild(a);

// http://papermashup.com/read-url-get-variables-withjavascript/
function getUrlVars(url) {
	var vars = {};
	var parts = url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
	    vars[key] = decodeURIComponent(value);
	});
	return vars;
}