Greasy Fork is available in English.

Download Sibnet Video as MP4

Выдает ссылку на видео в правом нижнем углу плеера

Устаревшая версия на 18.07.2017. Перейти к последней версии.

// ==UserScript==
// @name        Download Sibnet Video as MP4
// @namespace   http://video.sibnet.ru
// @description Выдает ссылку на видео в правом нижнем углу плеера
// @include     http://video.sibnet.ru/*
// @include     http://video.sibnet.ru/video*
// @include     http://video.sibnet.ru/*/video*
// @include     https://video.sibnet.ru/*
// @include     https://video.sibnet.ru/video*
// @include     https://video.sibnet.ru/*/video*
// @version     1.2.7
// @copyright   2017, Iron mark 42.1
// @author      Iron_man
// @grant       none
// ==/UserScript==

window.onload = function(){
var POSTMessage = true;
start();
function start()
{
	try{
		var video_path = findVideoPath();// get video path name '/v/{numbers}/{videoid}.mpd' from current html source page
		var xhr = createXMLHttpObject();
		xhr.onreadystatechange = function()
		{
			if( xhr.readyState == 4 && xhr.status == 200 )
			{
				var video_link = findVideoLink( xhr.responseText );// get downloadable video link
				if( !video_link )
				{
					console.error("[start] can't find video source link");
					return;
				}
				//console.log('video link: ', video_link);
				var stat = insertLink( video_link );// try to insert the link into 'video_size' element of html source page
				if( stat != 0 )// if failed to insert the link then 
				{
					if( window.parent !== window.self && POSTMessage )
						window.parent.postMessage( video_link, '*');
					window.location = video_link;// open it in current page
				}
			}
		};
		if( video_path )
		{
			//console.log('video path: ', video_path);
			xhr.open('GET', video_path, true);//  send 'GET' request to 'http://video.sibnet.ru/v/{numbers}/{videoid}.mpd'
			xhr.send(null);
		}
		else
			console.error("[start] can't find video path");
	}catch(e){
		console.error("[start] " + e);
	}
}
	
function findVideoPath()
{
	var video, source_str, pos, end;
	try{
		video = document.getElementById('video');
		if( video )
			source_str = video.innerHTML;
		else
			source_str = document.body.innerHTML;
		pos = source_str.indexOf( "player.src([{src: \"" );
		if( pos == -1 )
		{
			console.error( "Error: matching 'player.src([{src: \"' string not found");
			return null;
		}
		pos = source_str.indexOf("/v/", pos);
		end = source_str.indexOf(".mpd", pos);
		if( end == -1 )
		{
			console.error("Error: matching '.mpd' string not found");
			return null;
		}
		return source_str.substring(pos, end) + ".mpd";
	}catch(e){
		console.error("[findVideoPath] " + e);
		return null;
	}
}

function createXMLHttpObject() //  create xhr object
{
	if( window.XMLHttpRequest )
	{
		return new XMLHttpRequest();
	}
	else if( window.ActiveXObject )
	{
		try{
			return new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){}
		try{
			return new ActiveXObject("MSxml2.XMLHTTP");
		}catch(e){}
		console.error("[createXMLHttpObject] can't create ActiveXObject");
	}else{
		console.error("[createXMLHttpObject] can't create xhr object" );
	}
	return null;
}

function findVideoLink( source_str )
{
	try{
		var pos = source_str.indexOf("initialization=\"");
		if( pos == -1 )
		{
			console.error( "Error: matching string 'initialization=\"' not found");
			return null;
		}
		pos = source_str.indexOf("http", pos);
		var end = source_str.indexOf("noip=1", pos);
		if( end == -1 )
		{
			console.error( "Error: matching string 'noip=1' not found");
			return null;
		}
		source_str = source_str.substring(pos, end) + "noip=1";
		var result_str = source_str.replace("amp;", "");
		for( var count = 0; source_str.length != result_str.length && count < 10; ++count )
		{
			source_str = result_str;
			result_str = source_str.replace("amp;", "");
		}
		result_str = result_str.replace("/init-$RepresentationID$", "");
		return result_str;
	}catch(e){
		console.log("[findVideoLink] " + e);
		return null;
	}
}

function insertLink( source_link ) // insert hyper reference in video_size element  
{
	try{
		//console.log('inserting link into video_size ...');
		var video_size = document.getElementsByClassName('video_size')[0];
		video_size.innerHTML = '<a href="' + source_link + '" title="Скачать">' + video_size.innerHTML + '</a>';
		return 0;
	}catch(e){
		console.error("[insertLink] " + e);
		return 1;
	}
}
};