// ==SiteScript==
// @siteName Videojug
// @siteUrl http://www.videojug.com/
// @author mayan
// @authorUrl
// @scriptUrl
// @description
// @date 2012/03/18
// @version 0.1.1
// ==/SiteScript==
function CravingSiteScript() {
this._initialize();
}
CravingSiteScript.prototype = {
_xhr: null,
_initialize: function() {},
_getXmlHttpRequest: function() {
if ( this._xhr != null ) {
return this._xhr;
}
var xhr = null;
var these = [
function() { return new XMLHttpRequest(); }
, function() { return new ActiveXObject( "Msxml2.XMLHTTP" ); }
, function() { return new ActiveXObject( "Microsoft.XMLHTTP" ); }
, function() { return new ActiveXObject( "Msxml2.XMLHTTP.4.0" ); }
];
for ( var i = 0, length = these.length; i < length; i++ ) {
var func = these[ i ];
try {
xhr = func();
break;
}
catch( e ) {}
}
this._xhr = xhr;
return this._xhr;
},
_load: function( url, data, method ) {
var req = this._getXmlHttpRequest();
var mtd = ( method == null ) ? "GET" : "POST";
req.open( mtd, url, false );
if ( mtd == "POST" ) {
req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
}
req.send( data );
return req.responseText;
},
getResponseText: function( url, data, method ) {
return this._load( url, data, method );
},
getResponseJSON: function( url, data, method ) {
var text = this._load( url, data, method );
return eval( "("+text+")" );
},
/// Math
random: function( limit ) {
return Math.floor( Math.random() * limit );
},
/// String
decodeHtml: function( str ) {
return str.replace( /&(quot|#34);/ig, "\"" )
.replace( /&(amp|#38);/ig, "&" )
.replace( /&(apos|#39);/ig, "'" )
.replace( /&(lt|#60);/ig, "<" )
.replace( /&(gt|#62);/ig, ">" )
.replace( /&(nbsp|#160);/ig, " " )
.replace( /&(frasl|#8260);/ig, "/" );
}
}
function isSiteUrl( url ) {
if ( url.match( /http:\/\/(www\.)?videojug\.com\/film\/[^\/]+/ ) ) return true;
return false;
}
function getVideoDetail( url ) {
url = url.replace( /http:\/\/videojug\.com\//, "http://www.videojug.com/" );
if ( !url.match( /http:\/\/www\.videojug\.com\/film\/([^\/]+)/ ) ) return true;
var title_reserved = RegExp.$1.replace( /-/g, " " );
var craving = new CravingSiteScript();
try {
var text = craving.getResponseText( url );
} catch( e ) {
text = "";
}
if ( !text ) return null;
var host = "http://www.videojug.com";
var ar = "16_9";
var vid = "";
if ( text.match( /new\s+Player\(\s*'[^']*'\s*,\s*'[^']*'\s*,\s*'([^']+)'\s*,\s*'([^']+)'/ ) ) {
var type = RegExp.$1;
var vid = RegExp.$2;
}
if ( !type ) type = "film";
if ( !vid && text.match( /]*?rel\s*=\s*("|')video_src\2[^>]*)>/ )
&& RegExp.$1.match( /\s+href\s*=\s*("|')(.*?)\1/ )
&& RegExp.$2.match( /[?&]id=([^]+)/ ) ) {
vid = RegExp.$1;
}
if ( !vid && text.match( /]*?property\s*=\s*("|')og:video(:url)?\2[^>]*)>/ )
&& RegExp.$1.match( /\s+content\s*=\s*("|')(.*?)\1/ )
&& RegExp.$2.match( /[?&]id=([^]+)/ ) ) {
vid = RegExp.$1;
}
if ( !vid ) return null;
var xmlurl = host + "/feed/playlist?id=" + vid + "&items=&userName=&ar=" + ar;
//var xmlurl = host + "/views/" + type + "/playlist.aspx?id=" + vid + "&items=&userName=&ar=" + ar;
try {
text = craving.getResponseText( xmlurl );
} catch( e ) {
text = "";
}
if ( !text ) return null;
if ( text.match( /Title\s*?=\s*?("|')(.+?)\1/i ) ) var title = RegExp.$2;
else title = title_reserved;
title = title.replace(/[\\\/:*?"<>|]/g, "_");
if ( !text.match( / Prefix\*?=\*?("|')(.*?)\1/ ) ) return null;
var prefix = RegExp.$2;
var objReg = /]+)\/>/ig ;
var arrLct = new Array();
while( objReg.exec( text ) != null ){
var strAttr = RegExp.$1;
if ( !strAttr.match( / Name\s*?=\s*?("|')(.*?)\1/i ) ) continue;
var name = RegExp.$2;
if ( !strAttr.match( / Url\s?=\s*?("|')(.*?)\1/i ) ) continue;
var urlLoc = RegExp.$2;
arrLct[ name ] = urlLoc;
}
objReg = /]+)\/>/ig ;
var objShape = new strctShapeData();
var arrRet = new Array();
while ( objReg.exec( text ) != null ){
var objTmp = {};
strAttr = RegExp.$1;
if ( !strAttr.match( / Code\s*?=\s*?("|')(.*?)\1/i ) ) continue;
var code = RegExp.$2;
if ( !objShape[ code ] ) continue;
if ( !strAttr.match( / Locations\s*?=\s*?("|')(.*?)\1/i ) ) continue;
var locations = RegExp.$2.split( "," )[0];
if ( !arrLct[ locations ] ) continue;
objTmp.url = arrLct[ locations ] + prefix + "__" + code + "ENG." + objShape[ code ].extention;
objTmp.priority = objShape[ code ].priority;
arrRet.push( objTmp );
}
arrRet.sort( function (a,b){ return a.priority - b.priority; } );
return { videoTitle0: title, videoUrl0: arrRet[ 0 ].url };
}
function strctShapeData(){
//new strctData( "ShapeCode", priority, "extention", "description" );
this.VJ720P = new strctData( "VJ720P", 10, "mp4", "1280x720 AVC/H.264" );
this.VJ480P = new strctData( "VJ480P", 20, "mp4", "848x480 AVC/H.264" );
this.VJ360P = new strctData( "VJ360P", 40, "mp4", "640x360 AVC/H.264" );
this.ITV = new strctData( "ITV", 30, "mp4", "1280x720 AVC/H.264" );
this.FW8 = new strctData( "FW8", 50, "flv", "640x360 On2 VP6" );
this.FL8 = new strctData( "FL8", 60, "flv", "400x300 On2 VP6" );
this.FL7 = new strctData( "FL7", 70, "flv", "400x300 Sorenson H.263" );
this.FS8 = new strctData( "FS8", 80, "flv", "320x240 On2 VP6" );
this.FS7 = new strctData( "FS7", 90, "flv", "320x240 Sorenson H.263" );
}
function strctData( strShapeCode, intPriority, strExtention, strDescription ){
this.name = strShapeCode;
this.priority = intPriority;
this.extention = strExtention;
this.description = strDescription;
this.url = "";
}