aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjanus_wel2008-11-22 14:44:10 +0000
committerjanus_wel2008-11-22 14:44:10 +0000
commitac3737726e46cfd137f94673be3c3c345b972b44 (patch)
tree87b889b5ef4271b22741a9f9db6b7f99c66928f9
parent7d8fc0f98cca484935081e470131050ca663127c (diff)
downloadvimperator-plugins-ac3737726e46cfd137f94673be3c3c345b972b44.tar.bz2
change regular expression (for SunRed)
cosmetic change git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@24657 d0d07461-0603-4401-acd4-de1884942a52
-rw-r--r--ldrize_cooperation_fetch_flv.js148
1 files changed, 85 insertions, 63 deletions
diff --git a/ldrize_cooperation_fetch_flv.js b/ldrize_cooperation_fetch_flv.js
index 743ba8c..28d31ce 100644
--- a/ldrize_cooperation_fetch_flv.js
+++ b/ldrize_cooperation_fetch_flv.js
@@ -1,78 +1,100 @@
// Vimperator plugin: 'Cooperation LDRize Mappings - Niconico Flv Fetchearg || liberator.buffer.URLr'
// Version: 0.4
-// Last Change: 21-Oct-2008. Jan 2008
+// Last Change: 22-Nov-2008. Jan 2008
// License: Creative Commons
// Maintainer: Trapezoid <trapezoid.g@gmail.com> - http://unsigned.g.hatena.ne.jp/Trapezoid
//
// Cooperation LDRize Mappings - Niconico Flv Fetcher for vimperator0.6.*
// Require LDRize Cooperation ver 0.14
-(function(){
- function NiconicoFlvHandler(url,title){
- const nicoApiEndPoint = "http://www.nicovideo.jp/api/getflv?v=";
- const nicoWatchEndPoint = "http://www.nicovideo.jp/watch/";
- var videoId = url.match(/\wm\d+/)[0];
- var fileName = title.replace(/[?\\\*\/:<>\|\"]/g,'_') + ".flv";
- httpGET(nicoApiEndPoint + videoId,function(apiResult){
- var flvUrl = decodeURIComponent(apiResult.match(/url=(.*?)&/)[1]);
- httpGET(nicoWatchEndPoint + videoId,function(watchPage){
- try{
- var DownloadManager = Cc["@mozilla.org/download-manager;1"]
- .getService(Ci.nsIDownloadManager);
- var WebBrowserPersist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
- .createInstance(Ci.nsIWebBrowserPersist);
+( function () {
- var sourceUri = makeURI(flvUrl,null,null);
- var file = DownloadManager.userDownloadsDirectory;
- file.appendRelativePath(fileName);
- var fileUri = makeFileURI(file);
+function NiconicoFlvHandler(url, title) {
+ const nicoApiEndPoint = 'http://www.nicovideo.jp/api/getflv?v=';
+ const nicoWatchEndPoint = 'http://www.nicovideo.jp/watch/';
+ let videoId = url.match(/\w{2}\d+/)[0];
+ let fileName = title.replace(/[?\\\*\/:<>\|\"]/g, '_') + '.flv';
- var download = DownloadManager.addDownload(0, sourceUri, fileUri, fileName,
- null, null, null, null, WebBrowserPersist);
- WebBrowserPersist.progressListener = download;
- WebBrowserPersist.saveURI(sourceUri, null, null, null, null, file);
- }catch(e){log(e);liberator.echoerr(e)}
- });
- });
- }
+ httpGET(
+ nicoApiEndPoint + videoId,
+ function (apiResult) {
+ let flvUrl = decodeURIComponent(apiResult.match(/url=(.*?)&/)[1]);
- function setupLDRizeCooperationNiconicoFlvFetcher(){
- var NiconicoFlvFetcher = {
- pattern: 'http://www.nicovideo.jp/watch/*',
- handler: NiconicoFlvHandler,
- wait: 5000
- }
- this.convertHandlerInfo([NiconicoFlvFetcher]);
- this.handlerInfo.unshift(NiconicoFlvFetcher);
- }
+ httpGET(
+ nicoWatchEndPoint + videoId,
+ function (watchPage) {
+ try {
+ let DownloadManager = Cc['@mozilla.org/download-manager;1']
+ .getService(Ci.nsIDownloadManager);
+ let WebBrowserPersist = Cc['@mozilla.org/embedding/browser/nsWebBrowserPersist;1']
+ .createInstance(Ci.nsIWebBrowserPersist);
- if(liberator.plugins.LDRizeCooperation == undefined){
- liberator.plugins.LDRizeCooperationPlugins = liberator.plugins.LDRizeCooperationPlugins || [];
- liberator.plugins.LDRizeCooperationPlugins.push(setupLDRizeCooperationNiconicoFlvFetcher);
- }else{
- setupLDRizeCooperationNiconicoFlvFetcher.apply(liberator.plugins.LDRizeCooperation);
- }
+ let sourceUri = makeURI(flvUrl, null, null);
+ let file = DownloadManager.userDownloadsDirectory;
+ file.appendRelativePath(fileName);
+ let fileUri = makeFileURI(file);
- function httpGET(uri,callback){
- var xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function(){
- if(xhr.readyState == 4){
- if(xhr.status == 200)
- callback.call(this,xhr.responseText);
- else
- throw new Error(xhr.statusText)
- }
- };
- xhr.open("GET",uri,true);
- xhr.send(null);
- }
- liberator.modules.commands.addUserCommand(['fetchflv'],'Download flv file from Nicovideo',
- function(arg){
- httpGET(arg.string || liberator.modules.buffer.URL,function(responseText){
- var [,title] = responseText.match(/<title>(.*?)<\/title>/i);
+ let download = DownloadManager.addDownload(
+ 0, sourceUri, fileUri, fileName,
+ null, null, null, null, WebBrowserPersist
+ );
+ WebBrowserPersist.progressListener = download;
+ WebBrowserPersist.saveURI(sourceUri, null, null, null, null, file);
+ }
+ catch (e) {
+ log(e);
+ liberator.echoerr(e);
+ }
+ } // function (watchPage)
+ ); // httpGET
+ } // function (apiResult)
+ ); // httpGET
+}
+
+function setupLDRizeCooperationNiconicoFlvFetcher() {
+ let NiconicoFlvFetcher = {
+ pattern: 'http://www.nicovideo.jp/watch/*',
+ handler: NiconicoFlvHandler,
+ wait: 5000,
+ };
+ this.convertHandlerInfo([NiconicoFlvFetcher]);
+ this.handlerInfo.unshift(NiconicoFlvFetcher);
+}
+
+if (liberator.plugins.LDRizeCooperation === undefined) {
+ liberator.plugins.LDRizeCooperationPlugins = liberator.plugins.LDRizeCooperationPlugins || [];
+ liberator.plugins.LDRizeCooperationPlugins.push(setupLDRizeCooperationNiconicoFlvFetcher);
+}
+else {
+ setupLDRizeCooperationNiconicoFlvFetcher.apply(liberator.plugins.LDRizeCooperation);
+}
+
+function httpGET(uri, callback) {
+ let xhr = new XMLHttpRequest();
+ xhr.onreadystatechange = function () {
+ if (xhr.readyState === 4) {
+ if (xhr.status === 200) callback.call(this,xhr.responseText);
+ else throw new Error(xhr.statusText)
+ }
+ };
+ xhr.open('GET', uri, true);
+ xhr.send(null);
+}
+
+liberator.modules.commands.addUserCommand(
+ ['fetchflv'],
+ 'Download flv file from Nicovideo',
+ function (arg) {
+ httpGET(
+ arg.string || liberator.modules.buffer.URL,
+ function (responseText) {
+ let [, title] = responseText.match(/<title>(.*?)<\/title>/i);
liberator.log(title);
- NiconicoFlvHandler(arg.string || liberator.modules.buffer.URL,title);
- });
- },{}
- );
+ NiconicoFlvHandler(arg.string || liberator.modules.buffer.URL, title);
+ }
+ );
+ },
+ {}
+);
+
})();