// ==SiteScript==
// @siteName NWAnime.com
// @siteUrl http://www.nwanime.com/
// @author mayan
// @authorUrl
// @scriptUrl
// @description
// @date 2013/12/04
// @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, "/" )
.replace( /(\d+);/g, function(a,b){return String.fromCharCode(parseInt(b,10));} )
.replace( /([0-9a-f]+);/ig, function(a,b){return String.fromCharCode(parseInt(b,16));} );
}
}
var _NWAnime = {};
_NWAnime.showMsg = true;
function isSiteUrl( url ) {
if ( url.match( /http:\/\/(?:www\.)?nwanime\.com\/(?:[^\/?]+\/)+video\/[^\/?]+\/mirror[0-9a-f]{20}\// ) ) return true;
if ( url.match( /http:\/\/(?:www\.)?nwanime\.com\/(?:[^\/?]+\/)+video\/[0-9a-f]{20}\/?/ ) ) return true;
return false;
}
function getVideoDetail( url ) {
if ( url.match( /http:\/\/(?:www\.)?nwanime\.com\/(?:[^\/?]+\/)+video\/[^\/?]+\/mirror([0-9a-f]{20})\// ) ) {
var vid = RegExp.$1;
} else
if ( url.match( /http:\/\/(?:www\.)?nwanime\.com\/(?:[^\/?]+\/)+video\/([0-9a-f]{20})\/?/ ) ) {
vid = RegExp.$1
} else {
return null;
}
var craving = new CravingSiteScript();
var objRef = { "text":"", "id":"" };
try {
objRef.text = craving.getResponseText( url );
} catch( e ) {
objRef.text = "";
}
if ( !objRef.text ) return null;
if ( objRef.text.match( /
]*)?>\s*(.*?)\s*<\/title\s*>/i ) ) {
var title = craving.decodeHtml( RegExp.$1 ).replace( /\s*-\s*Watch\s+.*/,"" ).replace( /^\s+/,"" );
}
title = (title? title: "nwanime") + "_" + vid;
title = title.replace(/[\\\/:*?"<>|]/g, "_");
objRef.id = "embed_holder";
var objRet = {};
if ( !getDiv( objRef, objRet ) ) return null;
if ( objRet.inner.match( /<(iframe|embed)\s+[^>]*?src\s*=\s*("|')(.*?)\2[^>]*>/im ) ) {
var src = craving.decodeHtml( RegExp.$3 ).replace( /\\\//g, "/" );
}
if ( !src &&
objRet.inner.match( /\s+href\s*=\s*("|')http:\/\/(?:www\.)?nwanime\.com\/portal\.php\?url=(.+?)\1/im ) ) {
src = decodeURIComponent( RegExp.$2 );
}
if ( src ) {
var arr = [ {"src":src} ];
setType( arr );
if ( arr[0].func ) {
var rtn = arr[0].func( arr[0].src, craving );
if ( rtn ) return { videoTitle0: title, videoUrl0: rtn };
arr[0].msg = "functionが空文字を返した";
}
if ( arr[0].script ) {
var objInc = new clsIncludeSiteScript();
var objScript = objInc.includeSiteScript( arr[0].script );
if ( objScript ) {
var srctmp = arr[0].dummy || arr[0].src;
if ( objScript.isSiteUrl( srctmp ) ) {
rtn = objScript.getVideoDetail( srctmp );
if ( rtn ) {
return objInc.replaceTitle( rtn, title );
} else {
arr[0].msg = "getVideoDetailがnullを返した";
}
} else {
arr[0].msg = "isSiteUrlがfalseを返した";
}
} else {
arr[0].msg = "スクリプトの読み込みに失敗";
}
}
}
if ( _NWAnime.showMsg ) {
var objBx = new clsMsgBox();
if ( src ) {
if ( objBx.isOK ) {
rtn = objBx.MsgBox( "取得失敗。"
+ (arr[0].msg? ("\n"+arr[0].msg):"")
+ "\ntitle=" + title
+ "\nsrc=" + arr[0].src
+ "\ntype=" + arr[0].type
+ ( arr[0].script? ("\nscript=" + arr[0].script): "" )
+ "\n\nsrcをCraving Explorerへ送ってみますか?"
//+ "\n(タイトルは動画配信元から取得したものになります)"
, "from nwamine.site.js", 3 );
if ( rtn == 6 ) sendCE( src );
}
} else {
if ( objBx.isOK ) {
objBx.MsgBox( "取得失敗。"
+ "\ntitle=" + title
+ "\ncode=\n" + objRet.inner
, "from nwanime.site.js", 0 );
}
}
}
return null;
}
function getDiv( objRef, objRet ) {
//objRef.text, objRef.id
//objRet.inner, objRet.outer
//return boolean
if ( typeof( objRef ) != "object" ) return false;
if ( !objRef.text || typeof( objRef.text ) != "string" ) return false;
if ( !objRef.id || typeof( objRef.id ) != "string" ) return false;
if ( typeof ( objRet ) != "object" ) return false;
objRet.inner = "";
objRet.outer = "";
var objReg = new RegExp( "]*?id\\s*=\\s*(\"|')?" + objRef.id + "\\1[^>]*>", "im" );
if ( !objReg.test( objRef.text ) ) return false;
var div = RegExp.lastMatch;
var next = RegExp.rightContext;
var objReg1 = /
]*)?>/ig;
var objReg2 = /<\/div\s*>/ig;
var close = 0;
var success = false;
while( objReg2.test( next ) ) {
var left = RegExp.leftContext;
var open = 0;
while ( objReg1.test( left ) ) {
if ( RegExp.$1.match( /\/$/ ) ) continue;
open++;
}
if ( open === close ) {
objRet.inner = left;
objRet.outer = div + left + "
";
success = true;
break;
}
close++;
}
return success;
}
function setType( arrDat ) {
//arrはobjを要素に持つ
for ( var i = 0; i < arrDat.length; i++ ) {
if ( arrDat[i].type ) continue;
if ( !arrDat[i].src ) {
arrDat[i].type = "unknown";
continue;
}
if ( !arrDat[i].domain ) {
arrDat[i].domain = arrDat[i].src.match( /:\/\/([^\/?]+)(?::\d+)?\// )? RegExp.$1: "";
}
if ( !arrDat[i].domain ) {
arrDat[i].type = "unknown";
continue;
}
//mp4upload type
if ( arrDat[i].domain.match( /(.+\.)?ani-stream\.com$/ ) ) {
arrDat[i].type = "anistreamcom";
arrDat[i].script = "anistreamcom.site.js";
arrDat[i].func = getVideoUrl_JWPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?mp4upload\.com$/ ) ) {
arrDat[i].type = "mp4uploadcom";
arrDat[i].script = "mp4uploadcom.site.js";
arrDat[i].func = getVideoUrl_JWPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?videonest\.net$/ ) ) {
arrDat[i].type = "videonestnet";
arrDat[i].script = "videonestnet.site.js";
arrDat[i].func = getVideoUrl_JWPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?slickvid\.com$/ ) ) {
arrDat[i].type = "slickvidcom";
arrDat[i].script = "slickvidcom.site.js";
arrDat[i].func = getVideoUrl_JWPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?uploadc\.com$/ ) ) {
arrDat[i].type = "uploadccom";
arrDat[i].script = "uploadc.site.js";
//arrDat[i].func = getVideoUrl_JWPlayer;
}
//vidbz type
else if ( arrDat[i].domain.match( /(.+\.)?vid\.bz$/ ) ) {
arrDat[i].type = "vidbz";
arrDat[i].script = "vidbz.site.js";
}
else if ( arrDat[i].domain.match( /(.+\.)?vidwoot\.com$/ ) ) {
arrDat[i].type = "vidwootcom";
arrDat[i].script = "vidwootcom.site.js";
}
else if ( arrDat[i].domain.match( /(.+\.)?yourupload\.com$/ ) ) {
arrDat[i].type = "youruploadcom";
arrDat[i].script = "youruploadcom.site.js";
}
//novamov type
else if ( arrDat[i].domain.match( /(.+\.)?novamov\.com$/ ) ) {
arrDat[i].type = "novamovcom";
arrDat[i].script = "novamov.site.js";
}
else if ( arrDat[i].domain.match( /(.+\.)?videoweed\.es$/ ) ) {
arrDat[i].type = "videoweedes";
arrDat[i].script = "videoweed.site.js";
}
else if ( arrDat[i].domain.match( /(.+\.)?divxstage\.(eu|net)$/ ) ) {
arrDat[i].type = "divxstage";
arrDat[i].script = "divxstage.site.js";
}
else if ( arrDat[i].domain.match( /(.+\.)?movshare\.net$/ ) ) {
arrDat[i].type = "movsharenet";
arrDat[i].script = "movshare.site.js";
}
else if ( arrDat[i].domain.match( /(.+\.)?nowvideo\.(ch|sx|eu)$/ ) ) {
arrDat[i].type = "nowvideo";
arrDat[i].script = "nowvideoch.site.js";
}
//auengine type
else if ( arrDat[i].domain.match( /(.+\.)?auengine\.com$/ ) ) {
arrDat[i].type = "auenginecom";
arrDat[i].func = getVideoUrl_FlowPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?videofun\.me$/ ) ) {
arrDat[i].type = "videofunme";
arrDat[i].func = getVideoUrl_FlowPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?trollvid\.net$/ ) ) {
arrDat[i].type = "trollvidnet";
arrDat[i].func = getVideoUrl_FlowPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?vidzur\.com$/ ) ) {
arrDat[i].type = "vidzurcom";
arrDat[i].func = getVideoUrl_FlowPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?videobug\.net$/ ) ) {
arrDat[i].type = "videobugnet";
arrDat[i].func = getVideoUrl_FlowPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?play44\.net$/ ) ) {
arrDat[i].type = "play44net";
arrDat[i].func = getVideoUrl_FlowPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?chia-anime\.com$/ ) ) {
arrDat[i].type = "chiaanimecom";
arrDat[i].func = getVideoUrl_FlowPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?animepremium\.tv$/ ) ) {
arrDat[i].type = "animepremiumtv";
arrDat[i].func = getVideoUrl_FlowPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?gogoanime\.com$/ ) ) {
arrDat[i].type = "gogoanimecom";
arrDat[i].func = getVideoUrl_FlowPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?tinyvid\.net$/ ) ) {
arrDat[i].type = "tinyvidnet";
arrDat[i].func = getVideoUrl_FlowPlayer;
}
//etc script
else if ( arrDat[i].domain.match( /(.+\.)?zunux\.com$/ ) ) {
arrDat[i].type = "zunuxcom";
arrDat[i].script = "zunuxcom.site.js";
}
else if ( arrDat[i].domain.match( /(.+\.)?upload2\.com$/ ) ) {
arrDat[i].type = "upload2com";
arrDat[i].script = "upload2com.site.js";
}
else if ( arrDat[i].domain.match( /(.+\.)?videobam\.com$/ ) ) {
arrDat[i].type = "videobamcom";
arrDat[i].script = "videobam.site.js";
}
else if ( arrDat[i].domain.match( /(.+\.)?putlocker\.com$/ ) ) {
arrDat[i].type = "putlockercom";
arrDat[i].script = "putlocker.site.js";
}
//etc func
else if ( arrDat[i].domain.match( /(.+\.)?4shared\.com$/ ) ) {
arrDat[i].type = "4sharedcom";
arrDat[i].func = getVideoUrl_4sharedcom;
}
else if ( arrDat[i].domain.match( /(.+\.)?video44\.net$/ ) ) {
arrDat[i].type = "video44net";
arrDat[i].func = getVideoUrl_video44net;
}
else if ( arrDat[i].domain.match( /(.+\.)?animeget\.net$/ ) ) {
arrDat[i].type = "animegetnet";
arrDat[i].func = getVideoUrl_JWPlayer;
}
else if ( arrDat[i].domain.match( /(.+\.)?animedreaming\.tv$/ ) ) {
arrDat[i].type = "animedreaming(Veoh)";
arrDat[i].func = getVideoUrl_animedreamingtv;
}
//etc.
else if ( arrDat[i].domain.match( /(.+\.)?crunchyroll\.com$/ ) ) {
arrDat[i].type = "crunchyrollcom";
arrDat[i].msg = "未対応(RTMP)";
}
else if ( arrDat[i].domain.match( /(.+\.)?hulu\.com$/ ) ) {
arrDat[i].type = "hulucom";
arrDat[i].msg = "未対応(RTMP)";
}
else if ( arrDat[i].domain.match( /(.+\.)?veevr\.com$/ ) ) {
arrDat[i].type = "veevrcom";
arrDat[i].msg = "未対応(HDS)"
}
else if ( arrDat[i].domain.match( /(.+\.)?dailymotion\.com$/ ) ) {
arrDat[i].type = "dailymotioncom";
arrDat[i].script = "Dailymotion.site.js";
if ( arrDat[i].src.match( /:\/\/[^\/]+\/swf\/([0-9a-zA-z]+)/i ) ) {
arrDat[i].dummy = "http://www.dailymotion.com/video/" + RegExp.$1;
}
}
else if ( arrDat[i].domain.match( /(.+\.)?clip\.vn$/ ) ) {
arrDat[i].type = "clipvn";
arrDat[i].script = "clipvn.site.js";
}
else {
arrDat[i].type = "unknown";
}
}
}
function getVideoUrl_JWPlayer( url, craving ) {
//jwplayer type
try {
var text = craving.getResponseText( url );
} catch( e ) {
text = getResponse( url );
}
if ( !text ) return "";
if ( text.match( /jwplayer\s*\([^)]*\)\.setup\(([\s\S]*?)\)\s*;/im ) ) {
var stup = RegExp.$1.replace( /("|')?logo\1\s*:\s*\{[^}]*}/, "" );
if ( stup.match( /[,{]\s*("|')?file\1\s*:\s*("|')(.*?)\2\s*[,}]/m ) ) {
var realUrl = RegExp.$3;
}
if ( !realUrl &&
stup.match( /\{\s*("|')?type\1\s*:\s*("|')html5\2\s*,\s*("|')?config\3\s*:\s*\{\s*("|')?file\4\s*:\s*('|")(.*?)\5/ ) ) {
realUrl = RegExp.$6;
}
}
if ( !realUrl ) return "";
return realUrl;
}
function getVideoUrl_FlowPlayer( url, craving ) {
//flowplayer type
try {
var text = craving.getResponseText( url );
} catch( e ) {
text = getResponse( url );
}
if ( !text ) return "";
if ( text.match( /[{,]\s*("|'|"|')?playlist\1\s*:\s*\[([\s\S]*?)\]\s*[},]/m ) ) {
var playlist = RegExp.$2;
}
if ( playlist ) {
var objReg = /[{,]\s*("|'|"|')?url\1\s*:\s*("|'|"|')(.*?)\2\s*[},]/gm;
var arrDat = [];
while ( objReg.test( playlist ) ) {
var url0 = decodeURIComponent( RegExp.$3 );
if ( !url0 ) continue;
var obj = {};
obj.url = url0;
var url1 = url0.split( /[?]/ )[0];
obj.ext = url1.match( /\.([^/]+)$/ )? RegExp.$1: "";
obj.extP = obj.ext.match( /flv|mp4|m4v/i )? 1: 0;
arrDat.push( obj );
}
if ( arrDat.length > 0 ) {
arrDat.reverse();
arrDat.sort( function(a,b){return b.extP-a.extP;} );
var realUrl = arrDat[0].url;
}
}
if ( realUrl ) return realUrl;
if ( text.match( /[{,]\s*("|'|"|')?clip\1\s*:\s*\{([\s\S]*?)\}/m )
&& RegExp.$2.match( /("|'|"|')?url\1\s*:\s*("|'|"|')(.*?)\2/ ) ) {
realUrl = decodeURIComponent( RegExp.$3 );
}
if ( realUrl ) return realUrl;
return "";
}
function getVideoUrl_4sharedcom( url, craving ) {
if ( url.match( /http:\/\/(www\.)?4shared\.com\/embed\/\d+\/[0-9a-f]+/ ) ){
try {
var objHttp = new ActiveXObject( "WinHttp.WinHttpRequest.5.1" );
objHttp.Open( "HEAD", url, false );
objHttp.Send();
var rdturl = objHttp.option(1);
} catch( e ){
rdturl = ""
}
}
if ( !rdturl ) return "";
if ( rdturl.match( /[?&]file=([^&]+)/ ) ||
rdturl.match( /[?&]streamer=([^&]+)/ ) ) {
var realUrl = decodeURIComponent( RegExp.$1 );
}
if ( !realUrl ) return "";
return realUrl;
}
function getVideoUrl_video44net( url, craving ) {
try {
var text = craving.getResponseText( url );
} catch( e ) {
text = "";
}
if ( !text ) return "";
if ( text.match( /
]*?name\s*=\s*("|')?flashvars\2[^>]*)>/im )
&& RegExp.$1.match( /\s+value\s*=\s*("|')(.*?)\1/im ) ) {
var value = "&" + craving.decodeHtml( RegExp.$2 );
if ( value.match( /&file=([^&]+)/ ) ) {
var realUrl = decodeURIComponent( RegExp.$1 );
}
}
if ( !realUrl &&
text.match( /[{,]\s*("|')?file\1\s*:\s*("|')(.*?)\2\s*[},]/ ) ) {
realUrl = RegExp.$3;
}
if ( !realUrl ) return "";
return realUrl;
}
function getVideoUrl_animedreamingtv( url, craving ) {
//url = url.replace( /^http:\/\/animedreaming\.tv\//, "http://www.animedreaming.tv/" );
if ( url.match( /^http:\/\/(?:www\.)?animedreaming\.tv\/v\/(\d+)/ ) ) {
var v = RegExp.$1;
} else {
return "";
}
var configurl = "http://www.animedreaming.tv/c/" + v + "/";
try {
var text = craving.getResponseText( configurl );
} catch( e ) {
text = "";
}
if ( !text ) return "";
if ( text.match( /
\s*(.*?)\s*<\/file>/ ) ) {
var realUrl = RegExp.$1;
}
if ( !realUrl ) return "";
return realUrl;
}
/* common */
function getResponse( url ) {
try {
var objHttp = new ActiveXObject( "WinHttp.WinHttpRequest.5.1" );
objHttp.open( "GET", url, false );
objHttp.send();
var text = objHttp.responseText;
} catch( e ) {
text = "";
}
return text;
}
/* common end */
/* getVideoUrl end */
function clsIncludeSiteScript() {
var code1 = "(function(){\n\n";
var code2 = "\n\nreturn {'isSiteUrl':isSiteUrl,'getVideoDetail':getVideoDetail};})()";
var cePath = "\\CravingExplorer\\site-script\\";
this.isOK = false;
//initialize
try {
var appPath = ( new ActiveXObject( "WScript.Shell" ) ).SpecialFolders( "AppData" );
this.isOK = true;
} catch( e ) {
appPath = "";
this.isOK = false;
}
function evalScript( strFullPath, strCharset ) {
try {
var objStream = new ActiveXObject( "ADODB.Stream" );
objStream.Charset = strCharset;
objStream.Open();
objStream.LoadFromFile( strFullPath );
var obj = eval( "(" + code1 + objStream.ReadText() + code2 + ")" );
objStream.Close();
} catch( e ) {
obj = null;
}
if ( !obj || typeof obj != "object" ) return null;
if ( typeof obj.isSiteUrl != "function" ) return null;
if ( typeof obj.getVideoDetail != "function" ) return null;
return obj;
}
this.includeSiteScript = function ( strFileName ) {
if ( !this.isOK ) return null;
var strFullPath = appPath + cePath + strFileName;
var objS = evalScript( strFullPath, "unicode" );
if ( !objS ) objS = evalScript( strFullPath, "utf-8" );
return objS;
};
this.replaceTitle = function ( objRtn, title ) {
var count = 0;
var safe = 300;
while ( count < safe ) {
if ( objRtn[ "videoTitle" + count ] == undefined ) break;
count++;
}
if ( count <= 1 ) {
objRtn.videoTitle0 = title;
} else {
for ( var i = 0; i < count; i++ ) {
objRtn[ "videoTitle" + i ] = title + "_" + ( (i<9)?("0"+(i+1)):(""+(i+1)) );
}
}
return objRtn;
};
}
/* msgbox */
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 );
}
}
/* msgbox */
/* send to CravingExplorer */
function sendCE( strUrl ) {
try {
var objCE = new ActiveXObject( "CravingExplorer.Api" );
var ret = objCE.addDownloadItem( strUrl, 'flv', true );
} catch( e ) {
}
return ret;
}
/* send to CravingExplorer end */