Greasy Fork is available in English.

Video.mediaset.it native video player and direct links

This script allows you to watch and download videos on Video Mediaset.

Fra og med 07.11.2015. Se Den nyeste version.

// ==UserScript==
// @name        Video.mediaset.it native video player and direct links
// @namespace   http://andrealazzarotto.com
// @description This script allows you to watch and download videos on Video Mediaset.
// @include     http://www.video.mediaset.it/video/*
// @include     http://www.video.mediaset.it/player/playerIFrame*
// @include     http://www.mediaset.it/*
// @include     http://www.tgcom24.mediaset.it/video/
// @version     6.1
// @require     http://code.jquery.com/jquery-latest.min.js
// @grant       GM_xmlhttpRequest
// @license     GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// ==/UserScript==

var silverlight = function() {
	return unsafeWindow.Silverlight.isInstalled();
};

var boxStyle = function(selector, color, textcolor) {
	$(selector).css({
		'padding': '.5em',
		'margin': '1em 4em',
		'text-align': 'center',
		'background-color': color,
		'color': textcolor
	});
	$(selector + ' a').css('color', textcolor);
};

var writeLive = function(stream, highquality) {
	$('<div id="stream-url">').insertAfter('#video-player');
	$('#stream-url').append('<p>Flusso della diretta <strong>da aprire con VLC o <code>avplay</code>:</strong></p>')
		.append('<pre><code>' + stream + '</code></pre>')
		.append('<p>Flusso a <strong>qualità più alta:</strong></p>')
		.append('<pre><code>' + highquality + '</code></pre>');
	boxStyle('#stream-url', 'rgba(255,255,255,0.5)', 'black');
	$('#stream-url p').css('font-size', '15px');
	
	// kill login timeout
	unsafeWindow.userNotLogged = function() { return; };
	$('.countdown').remove();
	
	// Firefox does not display the error correctly
	var obj = $('#video-player > object');
	if(!silverlight() && !!obj.length) {
		$('<div class="vjs-error-display"><div></div></div>').css({
			'display': 'block',
			'left': 0,
			'right': 0,
			'top': 0,
			'bottom': 0,
			'position': 'absolute'
		}).appendTo('#video-player');
		$('#video-player').css({
			'background-color': 'black',
			'height': obj.attr('height'),
			'width': obj.attr('width')
		});
		obj.remove();
	}
	
	// replace error message
	$('.vjs-error-display div').replaceWith('<div id="custom-error"></div>');
	$('#custom-error').append('<p><img src="http://i.imgur.com/10hLEEY.png" /></p>')
		.append('<p>Il tuo browser non supporta la riproduzione. Trovi sotto i link ai flussi in diretta.</p>')
		.append('<p>&mdash; Andrea Lazzarotto</p>')
		.css({
			'background-color': 'black',
			'margin': '3em',
			'text-align': 'center',
			'font-size': '15px'
		});
	$('#custom-error img').css({
		'margin-bottom': '4em',
		'display': 'inline-block'
	});
};

var handleLive = function(playlistUri) {
	GM_xmlhttpRequest({
		method: 'GET',
		url: playlistUri,
		headers: {
			'Accept': 'application/atom+xml,application/xml,text/xml'
		},
		onload: function(responseDetails) {
			var r = responseDetails.responseText;
			var doc = $.parseXML(r);
			var $xml = $( doc );
			var videoID = $xml.find('videoUrl').text();
			GM_xmlhttpRequest({
				method: 'GET',
				url: 'http://cdnselector.xuniplay.fdnames.com/GetCDN.aspx?type=livehls&streamid=' + videoID,
				headers: {
					'Accept': 'application/atom+xml,application/xml,text/xml'
				},
				onload: function(responseDetails) {
					var r = responseDetails.responseText;
					var doc = $.parseXML(r);
					var $xml = $( doc );
					var src = $xml.find('video').attr('src');
					var highquality = src.replace('index.m3u8', 'Stream(04)/index.m3u8');
					writeLive(src, highquality);
				}
			});
		}
	});
};

// wrapper for non-Mozilla browsers
if(!exportFunction) var exportFunction = function(a,b) {return a;};

$(document).ready(function(){
	// handle live stream
	var playlistUri = (unsafeWindow.playlistUri || null);
	if (playlistUri !== null)
		return handleLive('http://www.mediaset.it' + playlistUri);

	// check if it contains a video
	if (unsafeWindow.CDN_SELECTOR_URL === null)
		return;

	if(!silverlight()) {
		unsafeWindow.CDN_SELECTOR_URL = "http://video.lazza.dk/vd.php?id=";
		unsafeWindow.CDN_SELECTOR_SECURE_URL = "https://video.lazza.dk/vd.php?id=";
	}

	// kill ads
	unsafeWindow.adsEnabled = false;
	
	var isIframe = (window.location.href.indexOf("playerIFrame") > 0);
	var id = (unsafeWindow.videoMetadataId) || 0;
	if (!id) {
		if(isIframe)
			id = window.location.href.split("id=")[1].split("&")[0];
		else {
			var chunks = window.location.pathname.replace(/[\._]/g, "/").split("/");
			for (var i in chunks) {
				id = chunks[i];
				if(!!parseInt(id) && id.length > 4)
					break;
			}
		}
	}
	
	// kill registration request
	if (!!unsafeWindow.trafficlight)
		unsafeWindow.Initialize(id);
	
	GM_xmlhttpRequest({
		method: 'GET',
		url: 'http://video.lazza.dk/vd.php?id='+id,
		headers: {
			'Accept': 'application/atom+xml,application/xml,text/xml'
		},
		onload: function(responseDetails) {
			var r = responseDetails.responseText;
			var doc = $.parseXML(r);
			var $xml = $( doc );
			var videos = $xml.find("video");
			var vlinks = [];
			
			// parse video URLs
			videos.each(function (i) {
				var url = $( videos.get(i) ).attr("src");
				var type = url.slice(-3);
				var name = "";
				switch(type) {
					case "est": name = "Smooth streaming"; break;
					case "pl)": name = "Apple streaming"; break;
					case "flv": name = "Video FLV"; break;
					case "f4v": name = "Video F4V"; break;
					case "mp4": name = "Video MP4"; break;
					case "wmv": name = "Video WMV"; break;
				}
				vlinks.push( { na: name, url: url } );
			});
			
			// display video URLs
			var num = vlinks.length;
			
			if(isIframe)
				$('<div id="video-links">').appendTo('body');
			else
				$('<div id="video-links">').appendTo('#box-apertura');
			for(var i=0; i<num; i++) {
				var o = vlinks[i];
				var s = '<a href="'+o.url+'">'+o.na+'</a>';
				$(s).appendTo('#video-links');
				if(i!=num-1)
					$('<span>&nbsp;|&nbsp;</span>').appendTo('#video-links');
			}
			boxStyle('#video-links', 'rgba(0,0,0,0.5)', 'white');
			
			if(isIframe) {
				$('#video-links').css({
					'position': 'absolute',
					'bottom': '1.5em',
					'left': '10%',
					'right': '10%',
					'font-size': '.9em',
					'z-index': '9999'
				})
				.append("<span id='close'>&times;</span>");
				$("#close").css({
					'font-weight': 'bold',
					'position': 'absolute',
					'right': '1em',
					'cursor': 'pointer'
				}).click(function() {
					$("#video-links").fadeOut();
				});
				boxStyle('#video-links', 'rgba(255,255,255,0.5)', 'black');
			}
			
			$("#spinner").remove();
		}
	});
});