// ==SiteScript==
// @siteName NHKニュース:動画
// @siteUrl http://www3.nhk.or.jp/news/newsvideo_top.html
// @author mayan
// @authorUrl
// @scriptUrl
// @description adjust to rtmpdump
// @date 2012/03/25
// @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:\/\/www3\.nhk\.or\.jp\/news\/html\/\d+\/\w+\d+\.html/ ) ) return true;
return false;
}
function getVideoDetail( url ) {
if ( !url.match( /(http:\/\/www3\.nhk\.or\.jp)\/news\/html\/(\d+)\/(\w+\d+)\.html/ ) ) return null;
var bk_title = RegExp.$2 + "_" + RegExp.$3;
var dom = RegExp.$1;
var craving = new CravingSiteScript();
var text = craving.getResponseText( url );
if ( !text ) return null;
if ( !text.match( /
(.+?)<\/div>/ ) ) return null;
var vid = RegExp.$1;
if ( text.match( /]*?name\s*=\s*("|')title\2[^>]*)>/ )
&& RegExp.$1.match( /\s+content\s*=\s*("|')(.*?)\1/ ) ) {
var title = RegExp.$2;
}
if ( !title && text.match( /
(.+?)<\/title>/ ) ) {
title = RegExp.$1;
}
if ( title ){
var date = ( text.match( /(.+?)<\/span>/ ) )? " " + RegExp.$1 : "";
var time = ( text.match( /(.+?)<\/span>/ ) )? " " + RegExp.$1 : "";
title = title + date + time;
} else {
title = bk_title;
}
title = title.replace(/[\\\/:*?"<>|]/g, "_");
var jsurl = "http://www3.nhk.or.jp/news/js/common.js";
try {
text = craving.getResponseText( jsurl );
} catch( e ) {
text = ""
}
var dir = ( text && text.match( /BASEDIR\s*=\s*"([^"]+)"/ ) )? RegExp.$1 : "/news/";
var fms = ( text && text.match( /"fms"\s*:\s*"([^"]+)"/ ) )? RegExp.$1 : "rtmp://flv.nhk.or.jp/ondemand/flv/news/";
var fpurl = ( text && text.match( /"fpurl"\s*:\s*BASEDIR\s*\+\s*"([^"]+)"/ ) )? RegExp.$1 : "news_player4.swf";
var swfurl = dom + dir + fpurl;
var realUrl = fms + vid;
var rtmpdump = "rtmpdump"
+ " -r \"" + realUrl + "\""
+ " -W \"" + swfurl + "\""
+ " -p \"" + url + "\""
+ " -o \"" + vid + ".flv\"";
return { videoTitle0: title, videoUrl0: rtmpdump };
}
/* Craving Explorer の SiteScript ここで終わり */
/* WSH 動作用コード、ここから */
function clsInputBox(){
//VBScript InputBox
this.isOK = false;
this._objSC = null;
this._initialize = function (){
try {
this._objSC = new ActiveXObject( "ScriptControl" );
this.isOK = true;
} catch(e) {
this.isOK = false;
return;
}
this._objSC.Language = "VBScript";
this._objSC.AddCode( "Function VB_IB(p, t, d) : VB_IB = InputBox(p, t, d) : End Function" );
}
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();
}
var strUrl = objIBox.InputBox( "URL を入力してください。",
"from SiteScript", "http://" );
if ( !strUrl ) WScript.Quit();
if ( !isSiteUrl( strUrl ) ){
WScript.Echo( strUrl + "\nは、このスクリプトでは正しく扱えないかもしれません。" );
//WScript.Quit();
}
var objRet = getVideoDetail( strUrl );
if ( !objRet ){
WScript.Echo( "取得失敗" );
WScript.Quit();
}
WScript.Echo( "videoTitle0:\n" + objRet.videoTitle0
+ "\nvideoUrl0:\n" + objRet.videoUrl0 );
/* WSH 動作用コード、ここまで */