// ==SiteScript==
// @siteName Phim47.Com
// @siteUrl http://phim47.com/
// @author mayan
// @authorUrl
// @scriptUrl
// @description
// @date 2013/06/14
// @version 0.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|#0*34);/ig, "\"" )
.replace( /&(amp|#0*38);/ig, "&" )
.replace( /&(apos|#0*39);/ig, "'" )
.replace( /&(lt|#0*60);/ig, "<" )
.replace( /&(gt|#0*62);/ig, ">" )
.replace( /&(nbsp|#0*160);/ig, " " )
.replace( /&(frasl|#8260);/ig, "/" );
}
}
var _PHIM47 = {};
_PHIM47.showMsg = true;
function isSiteUrl( url ) {
if ( url.match( /^http:\/\/(www\.)?phim47\.com\/xem-online?\/(?:[^\/?]*\/)*\d+\.html/ ) ) return true;
return false;
}
function getVideoDetail( url ) {
url = url.replace( /^http:\/\/www\.phim47\.com\//, "http://phim47.com/" );
if ( url.match( /http:\/\/phim47\.com\/xem-online?\/(?:[^\/?]*\/)*(\d+)\.html/ ) ) {
var vid = RegExp.$1;
} else {
return null;
}
var craving = new CravingSiteScript();
try {
var text = craving.getResponseText( url );
} catch( e ) {
text = "";
}
if ( !text ) return null;
if ( text.match( /
\s*(.*?)\s*<\/h2>/ ) ) {
var title = craving.decodeHtml( RegExp.$1 );
}
if ( !title ) title = "phim47_" + vid;
title = title.replace(/[\\\/:*?"<>|]/g, "_");
if ( text.match( /so\.addParam\(\s*('|")flashvars\1\s*,(.*?)\)\s*;/ )
&& RegExp.$2.match( /[?&]proxy\.link=([^&]+)/ ) ) {
var pxylnk = RegExp.$1;
if ( pxylnk.match( /^phim47\*([0-9A-Fa-f]+)/ ) ) {
pxylnk = decodePhim47( RegExp.$1 );
}
}
if ( !pxylnk || !pxylnk.match( /^https?:\/\/([^\/?]+)/i ) ) return null;
var domain = RegExp.$1;
//type
if ( domain.match( /(.+\.)?picasaweb\.google\.com(?::\d+)?$/ ) ) {
var type = "picasaweb";
} else {
type = "unknown";
}
switch ( type ) {
case "picasaweb":
var objRtn = getVideoDetail_picasa( pxylnk, craving );
if ( !objRtn ) return null;
objRtn.videoTitle0 = title;
return objRtn;
break;
case "unknown":
if ( _PHIM47.showMsg === true ) {
var objBx = new clsMsgBox();
if ( objBx.isOK ) {
objBx.MsgBox( "未対応です。\n\n" + pxylnk,
"from Site-Script", 0 );
}
}
return null;
break;
default:
}
return null;
}
function decodePhim47( strEnc ) {
//if ( !strEnc.match( /^phim47\*([0-9A-Fa-f]+)$/ ) ) return "";
//strEnc = RegExp.$1;
var arrSb = [1,0,7,1,0,4,5,0,9,8,8,1,1,1,2,1,
0,4,1,0,5,1,0,9,5,2,5,5,1,0,2,1,0,3,1,1,9];
var sblen = arrSb.length;
var key = parseInt( strEnc.slice( -4 ), 10 );
if ( isNaN( key ) ) return "";
strEnc = strEnc.slice( 0, -4 );
var blk = Math.ceil( strEnc.length / 4 );
var arr = [];
for ( var i=0, j=2, p=0; i < blk; i=i+1, j=j+2, p=p+4 ) {
var tmp = parseInt( strEnc.substr(p, 4), 16 );
var sb = arrSb[ (i % sblen) ];
tmp = ( (( (tmp - key) - sb ) - (j * j)) -16 ) / 3;
arr.push( String.fromCharCode( tmp ) );
}
return arr.join( "" );
}
function getVideoDetail_picasa( url, craving ) {
if ( url.match( /https?:\/\/picasaweb\.google\.com\/(\d+)\/([^\/?]+)/ ) ) {
var usrid = RegExp.$1;
var vid = RegExp.$2;
} else {
//return null;
}
var data = "iagent=Mozilla%2F5%2E0%20%28Windows%20NT%206%2E1%3B%20WOW64%3B%20rv%3A13%2E0%29%20Gecko%2F20100101%20Firefox%2F13%2E0"
+ "&url=" + encodeURIComponent( url )
+ "&ihttpheader=true&isslverify=true";
var phpurl = "http://player.phim47.com/load/plugins/picasaweb/plugins_player.php";
try {
var text = craving.getResponseText( phpurl, data, "POST" );
} catch( e ) {
text = "";
}
if ( !text ) return null;
if ( text.match( /[{,]\s*("|')?content\1\s*:\s*(\[[^>]*?\])\s*[},]/ ) ) {
var cont = RegExp.$2;
}
if ( !cont ) return null;
try {
var arrCnt = eval( "(" + cont + ")" );
} catch( e ) {
arrCnt = undefined;
}
if ( !arrCnt || !( arrCnt instanceof Array ) ) return null;
var arrDat = [];
for ( var i = 0; i < arrCnt.length; i++ ) {
if ( !arrCnt[i] || typeof arrCnt[i] != "object" ) continue;
if ( arrCnt[i].type == "image/jpeg" ) continue;
if ( !arrCnt[i].url ) continue;
if ( typeof arrCnt[i].width != "number" ) arrCnt[i].width = 0;
arrDat.push( arrCnt[i] );
}
if( arrDat.length <= 0 ) return null;
arrDat.reverse();
arrDat.sort( function(a,b){return b.width - a.width;} );//may not necessary
var realUrl = arrDat[0].url;
if ( text.match( /]*?name\s*=\s*("|')?title\2[^>]*)>/i )
&& RegExp.$1.match( /\s+content\s*=\s*("|')(.*?)\1/i ) ) {
var title = RegExp.$2;
}
if ( !title ) title = "picase_" + ( vid || (new Date()).getTime() );
title = title.replace(/[\\\/:*?"<>|]/g, "_");
return { videoTitle0: title, videoUrl0: realUrl };
}
function clsMsgBox(){
//WScript.Shell Popup
this.isOK = false;
this._objShell = null;
this._initialize = function (){
try{
this._objShell = new ActiveXObject( "WScript.Shell" );
this.isOK = true;
} catch( e ) {
this.isOK = false;
}
}
this._initialize();
this.MsgBox = function ( msg, title, btn ){
if ( btn == undefined ) btn = 1;
//btn=1の時ret: OK:1, キャンセル:2
if ( this.isOK )
return this._objShell.Popup( msg, 0, title, btn+64 );
}
}