// ==SiteScript==
// @siteName crunchyroll
// @siteUrl http://www.crunchyroll.com/
// @author mayan
// @authorUrl
// @scriptUrl
// @description RTMPDump CmdLine
// @date 2011/07/16
// @version 0.1
// ==/SiteScript==
/* CravingSiteScriptクラス */
//削除
/* CravingSiteScriptクラス、ここまで */
var _Crunchyroll = {};
_Crunchyroll.setProxy = false;
_Crunchyroll.Proxy = "xxx.xxx.xxx.xxx:portnum";
_Crunchyroll.Err = new Array();
function isSiteUrl( url ) {
if ( url.match( /http:\/\/(www\.)?crunchyroll\.com\/([^\/]+\/)+[^\/]*-\d+/ ) ) return true;
return false;
}
function getVideoDetail( url ) {
url = url.replace( /http:\/\/crunchyrol\.com\//, "http://www.crunchyroll.com/" );
if ( url.match( /http:\/\/www\.crunchyroll\.com\/([^\/]+\/)*([^\/]+)\/([^\/]*)-(\d+)/ ) ){
var vid = RegExp.$4;
var bk_title = RegExp.$2 + "_" + RegExp.$3;
} else {
_Crunchyroll.Err.push( "URL不適合" );
//return null;
}
try {
var objHttp = new ActiveXObject( "WinHttp.WinHttpRequest.5.1" );
} catch( e ) {
_Crunchyroll.Err.push( e.description );
return null;
}
if ( _Crunchyroll.setProxy && _Crunchyroll.Proxy ){
try {
objHttp.SetProxy( 2, _Crunchyroll.Proxy );
_Crunchyroll.Err.push( "Proxy_use:" + _Crunchyroll.Proxy );
} catch( e ) {
objHttp.SetProxy( 1 );
_Crunchyroll.Err.push( "Proxyの設定に失敗\nproxy=" + _Crunchyroll.Proxy + "\n" + e.description );
}
}
try {
objHttp.Open( "HEAD", "http://www.crunchyroll.com/", false );
objHttp.Send();
} catch( e ) { }
objHttp.SetProxy( 1 );
try {
objHttp.Open( "GET", url, false );
objHttp.SetRequestHeader( "Accept-Language", "ja-JP,en-US;q=0.5" );
objHttp.Send();
var redirecturl = objHttp.Option( 1 );
} catch( e ) {
_Crunchyroll.Err.push( "url=" + url + "\n" + e.description );
return null;
}
if ( url != redirecturl ) {
_Crunchyroll.Err.push( "redirectされました。\nur10=" + url + "\nurl1=" + redirecturl );
}
var objCnv = new clsCharConvert();
if ( objCnv.isOK && objCnv.convertChar( objHttp.responseBody, "utf-8" ) )
var text = objCnv.result;
else text = objHttp.responseText;
if ( !text ) {
_Crunchyroll.Err.push( "ページの取得に失敗" );
return null;
}
if ( text.match( /
]*>(.+?)<\/h1>/ ) ) var title = RegExp.$1;
if ( !title && text.match( /(.+?)<\/title>/ ) ) title = RegExp.$1.replace( /^\s*watch\s*/, "" );
if ( !title ) title = bk_title.replace( /-/g, " " );
title = title.replace(/[\\\/:*?"<>|]/g, "_");
if ( text.match( /embedSWF\(\s*('|")(.*?)\1\s*,(.+?)\)\s*;/ ) ) {
var arg = RegExp.$3;
var swfurl_std = RegExp.$2.replace( /\\\//g, "/" );
if ( arg.match( /("|')config_url\1\s*:\s*("|')(.*?)\2/ ) ) {
var configurl = decodeURIComponent( RegExp.$3 );
}
}
if ( !swfurl_std ) {
_Crunchyroll.Err.push( "swfurl_stdの取得に失敗" );
return null;
}
if ( !configurl ) {
_Crunchyroll.Err.push( "configurlの取得に失敗" );
configurl = "http://www.crunchyroll.com/xml/?req=RpcApiVideoPlayer_GetStandardConfig&media_id=" + vid;
}
try {
objHttp.Open( "GET", configurl, false );
objHttp.Send();
var text = objHttp.responseText;
} catch( e ) {
_Crunchyroll.Err.push( "configurl=" + configurl + "\n" + e.description );
text = "";
}
if ( !text ){
_Crunchyroll.Err.push( "configurlコンテンツの取得に失敗" );
return null;
}
if ( text.match( /(.+?)<\/host>/ ) ){
var host = RegExp.$1;
} else {
_Crunchyroll.Err.push( " の取得に失敗" );
return null;
}
if ( text.match( /(.+?)<\/file>/ ) ){
var file = RegExp.$1.replace( /&/g, "&" );
} else {
_Crunchyroll.Err.push( " の取得に失敗" );
return null;
}
if ( text.match( /(.+?)<\/default:chromelessPlayerUrl>/ ) ) {
var swfurl_def = RegExp.$1.replace( /&/g, "&" );
} else {
_Crunchyroll.Err.push( "swfurl_defの取得に失敗" );
return null;
}
var swfurl_base = swfurl_std.substr( 0, swfurl_std.lastIndexOf( "/" ) );
var swfurl = swfurl_base + "/" + swfurl_def.split( "?" )[ 0 ];
if ( host.match( /^(rtmp[ets]*?):\/\/([^\/]+)(\/(.*))?/ ) ) {
var protocol = RegExp.$1;
var domain = RegExp.$2;
var app = RegExp.$4;
}
var flashver = getFlashVer();
var outfile = ( bk_title + "_" + vid ).replace(/[\\\/:*?"<>|]/g, "_");
var rtmpdump = "rtmpdump"
+ " -r \"" + host + "\""
+ ( app? ( " -a \"" + app + "\"" ) : "" )
+ ( flashver? ( " -f \"" + flashver + "\"" ) : "" )
+ " -W \"" + swfurl + "\""
+ " -p \"" + url + "\""
+ " -y \"" + file + "\""
+ " -o \"" + outfile + ".flv\"";
return { videoTitle0: title, videoUrl0: rtmpdump };
}
function getFlashVer(){
try {
var obj = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash" );
var ver = obj.GetVariable( "$version" );
} catch( e ) {
return "";
}
if ( !ver ) return "";
return ver;
}
function clsCharConvert(){
this.isOK = false;
this.result = "";
this._stream = null;
this._initialize = function (){
try {
this._stream = new ActiveXObject( "ADODB.Stream" );
this.isOK = true;
} catch( e ) {
this.isOK = false;
}
}
this._initialize();
this.convertChar = function ( bin, charset ){
var flag = false;
if ( !this.isOK ) return flag;
this._stream.Open();
try {
this._stream.Type = 1;
this._stream.Write( bin );
this._stream.Position = 0;
this._stream.Type = 2;
this._stream.Charset = charset;
this.result = this._stream.ReadText();
flag = true;
} catch( e ) {
this.result = "";
flag = false;
}
this._stream.Close();
return flag;
}
}
/* Craving Explorer の SiteScript ここで終わり */
/* WSH 動作用コード、ここから */
function clsInputBox(){
//VBScript InputBox
this.isOK = false;
this._objSC = null;
this._initialize = function (){
try {
this._objSC = new ActiveXObject( "ScriptControl" );
this._objSC.Language = "VBScript";
this._objSC.AddCode( "Function VB_IB(p, t, d) : VB_IB = InputBox(p, t, d) : End Function" );
this.isOK = true;
} catch(e) {
this.isOK = false;
return;
}
}
this._initialize();
this.InputBox = function (msg, title, def){
if ( this.isOK ){
return this._objSC.Run( "VB_IB", msg, title, def);
}
}
}
var objIBox = new clsInputBox();
if ( !objIBox ){
WScript.Echo( "InputBox 作成に失敗。終了します。" );
WScript.Quit();
}
if ( _Crunchyroll.setProxy && _Crunchyroll.Proxy )
var strProxy = "Proxy を使用します。\n" + "proxy=" + _Crunchyroll.Proxy + "\n\n";
else strProxy = "Proxy を使いません。\n\n";
var strUrl = objIBox.InputBox( ( strProxy? strProxy: "" ) + "URL を入力してください。",
"from SiteScript", "http://" );
if ( !strUrl ) WScript.Quit();
if ( !isSiteUrl( strUrl ) ){
WScript.Echo( strUrl + "\nは、このスクリプトでは正しく扱えないかもしれません。" );
//WScript.Quit();
}
var objRet = getVideoDetail( strUrl );
if ( _Crunchyroll.Err.length > 0 ) var strErr = _Crunchyroll.Err.join( "\n" );
else strErr = "";
if ( objRet == null ) {
WScript.Echo( "取得失敗"
+ "\n\nInfoMsg:\n" + strErr );
} else {
WScript.Echo( "title:\n" + objRet.videoTitle0
+ ( strErr? ( "\n\nInfo:\n" + strErr ): "" )
+ "\n\nRTMPDump CmdLine:\n" + objRet.videoUrl0 );
}
/* WSH 動作用コード、ここまで */