| 25 | | var sourceUri = makeURI(flvUrl,null,null); |
| 26 | | var file = DownloadManager.userDownloadsDirectory; |
| 27 | | file.appendRelativePath(fileName); |
| 28 | | var fileUri = makeFileURI(file); |
| | 12 | function NiconicoFlvHandler(url, title) { |
| | 13 | const nicoApiEndPoint = 'http://www.nicovideo.jp/api/getflv?v='; |
| | 14 | const nicoWatchEndPoint = 'http://www.nicovideo.jp/watch/'; |
| | 15 | let videoId = url.match(/\w{2}\d+/)[0]; |
| | 16 | let fileName = title.replace(/[?\\\*\/:<>\|\"]/g, '_') + '.flv'; |
| 30 | | var download = DownloadManager.addDownload(0, sourceUri, fileUri, fileName, |
| 31 | | null, null, null, null, WebBrowserPersist); |
| 32 | | WebBrowserPersist.progressListener = download; |
| 33 | | WebBrowserPersist.saveURI(sourceUri, null, null, null, null, file); |
| 34 | | }catch(e){log(e);liberator.echoerr(e)} |
| 35 | | }); |
| 36 | | }); |
| 37 | | } |
| | 18 | httpGET( |
| | 19 | nicoApiEndPoint + videoId, |
| | 20 | function (apiResult) { |
| | 21 | let flvUrl = decodeURIComponent(apiResult.match(/url=(.*?)&/)[1]); |
| 39 | | function setupLDRizeCooperationNiconicoFlvFetcher(){ |
| 40 | | var NiconicoFlvFetcher = { |
| 41 | | pattern: 'http://www.nicovideo.jp/watch/*', |
| 42 | | handler: NiconicoFlvHandler, |
| 43 | | wait: 5000 |
| | 23 | httpGET( |
| | 24 | nicoWatchEndPoint + videoId, |
| | 25 | function (watchPage) { |
| | 26 | try { |
| | 27 | let DownloadManager = Cc['@mozilla.org/download-manager;1'] |
| | 28 | .getService(Ci.nsIDownloadManager); |
| | 29 | let WebBrowserPersist = Cc['@mozilla.org/embedding/browser/nsWebBrowserPersist;1'] |
| | 30 | .createInstance(Ci.nsIWebBrowserPersist); |
| | 31 | |
| | 32 | let sourceUri = makeURI(flvUrl, null, null); |
| | 33 | let file = DownloadManager.userDownloadsDirectory; |
| | 34 | file.appendRelativePath(fileName); |
| | 35 | let fileUri = makeFileURI(file); |
| | 36 | |
| | 37 | let download = DownloadManager.addDownload( |
| | 38 | 0, sourceUri, fileUri, fileName, |
| | 39 | null, null, null, null, WebBrowserPersist |
| | 40 | ); |
| | 41 | WebBrowserPersist.progressListener = download; |
| | 42 | WebBrowserPersist.saveURI(sourceUri, null, null, null, null, file); |
| | 43 | } |
| | 44 | catch (e) { |
| | 45 | log(e); |
| | 46 | liberator.echoerr(e); |
| | 47 | } |
| | 48 | } // function (watchPage) |
| | 49 | ); // httpGET |
| | 50 | } // function (apiResult) |
| | 51 | ); // httpGET |
| | 52 | } |
| | 53 | |
| | 54 | function setupLDRizeCooperationNiconicoFlvFetcher() { |
| | 55 | let NiconicoFlvFetcher = { |
| | 56 | pattern: 'http://www.nicovideo.jp/watch/*', |
| | 57 | handler: NiconicoFlvHandler, |
| | 58 | wait: 5000, |
| | 59 | }; |
| | 60 | this.convertHandlerInfo([NiconicoFlvFetcher]); |
| | 61 | this.handlerInfo.unshift(NiconicoFlvFetcher); |
| | 62 | } |
| | 63 | |
| | 64 | if (liberator.plugins.LDRizeCooperation === undefined) { |
| | 65 | liberator.plugins.LDRizeCooperationPlugins = liberator.plugins.LDRizeCooperationPlugins || []; |
| | 66 | liberator.plugins.LDRizeCooperationPlugins.push(setupLDRizeCooperationNiconicoFlvFetcher); |
| | 67 | } |
| | 68 | else { |
| | 69 | setupLDRizeCooperationNiconicoFlvFetcher.apply(liberator.plugins.LDRizeCooperation); |
| | 70 | } |
| | 71 | |
| | 72 | function httpGET(uri, callback) { |
| | 73 | let xhr = new XMLHttpRequest(); |
| | 74 | xhr.onreadystatechange = function () { |
| | 75 | if (xhr.readyState === 4) { |
| | 76 | if (xhr.status === 200) callback.call(this,xhr.responseText); |
| | 77 | else throw new Error(xhr.statusText) |
| 49 | | if(liberator.plugins.LDRizeCooperation == undefined){ |
| 50 | | liberator.plugins.LDRizeCooperationPlugins = liberator.plugins.LDRizeCooperationPlugins || []; |
| 51 | | liberator.plugins.LDRizeCooperationPlugins.push(setupLDRizeCooperationNiconicoFlvFetcher); |
| 52 | | }else{ |
| 53 | | setupLDRizeCooperationNiconicoFlvFetcher.apply(liberator.plugins.LDRizeCooperation); |
| 54 | | } |
| | 84 | liberator.modules.commands.addUserCommand( |
| | 85 | ['fetchflv'], |
| | 86 | 'Download flv file from Nicovideo', |
| | 87 | function (arg) { |
| | 88 | httpGET( |
| | 89 | arg.string || liberator.modules.buffer.URL, |
| | 90 | function (responseText) { |
| | 91 | let [, title] = responseText.match(/<title>(.*?)<\/title>/i); |
| | 92 | liberator.log(title); |
| | 93 | NiconicoFlvHandler(arg.string || liberator.modules.buffer.URL, title); |
| | 94 | } |
| | 95 | ); |
| | 96 | }, |
| | 97 | {} |
| | 98 | ); |
| 56 | | function httpGET(uri,callback){ |
| 57 | | var xhr = new XMLHttpRequest(); |
| 58 | | xhr.onreadystatechange = function(){ |
| 59 | | if(xhr.readyState == 4){ |
| 60 | | if(xhr.status == 200) |
| 61 | | callback.call(this,xhr.responseText); |
| 62 | | else |
| 63 | | throw new Error(xhr.statusText) |
| 64 | | } |
| 65 | | }; |
| 66 | | xhr.open("GET",uri,true); |
| 67 | | xhr.send(null); |
| 68 | | } |
| 69 | | liberator.modules.commands.addUserCommand(['fetchflv'],'Download flv file from Nicovideo', |
| 70 | | function(arg){ |
| 71 | | httpGET(arg.string || liberator.modules.buffer.URL,function(responseText){ |
| 72 | | var [,title] = responseText.match(/<title>(.*?)<\/title>/i); |
| 73 | | liberator.log(title); |
| 74 | | NiconicoFlvHandler(arg.string || liberator.modules.buffer.URL,title); |
| 75 | | }); |
| 76 | | },{} |
| 77 | | ); |