From b5b8334f4359cfad199076d49306ff38a8455656 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sat, 10 Dec 2016 00:58:04 +0800 Subject: [PATCH] add http-proxy --- nodejs/package.json | 1 + nodejs/routes/video-bilibili.js | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nodejs/package.json b/nodejs/package.json index 9ab3b24..1cd933b 100644 --- a/nodejs/package.json +++ b/nodejs/package.json @@ -9,6 +9,7 @@ "dependencies": { "blueimp-md5": "^2.4.0", "express": "^4.13.4", + "http-proxy-agent": "^1.0.0", "log4js": "^0.6.36", "mongoose": "^4.1.9", "node-fetch": "^1.6.3", diff --git a/nodejs/routes/video-bilibili.js b/nodejs/routes/video-bilibili.js index 69ef59c..48ec051 100644 --- a/nodejs/routes/video-bilibili.js +++ b/nodejs/routes/video-bilibili.js @@ -4,18 +4,19 @@ var redis = require('../tools/redis'); var fetch = require('node-fetch'); var md5 = require('blueimp-md5'); var xml2js = require('xml2js'); +var HttpProxyAgent = require('http-proxy-agent'); var parseString = xml2js.parseString; var appkey = 'f3bb208b3d081dc8'; var secret = '1c15888dc316e05a15fdd0a02ed6584f'; function getData(cid, res, type) { var sign = md5(`cid=${cid}&from=miniplay&player=1${secret}`); - var api = `https://interface.bilibili.com/playurl?&cid=${cid}&from=miniplay&player=1&sign=${sign}`; + var api = `http://interface.bilibili.com/playurl?&cid=${cid}&from=miniplay&player=1&sign=${sign}`; if (type === '1') { res.send(api); } else { - fetch(api).then( + fetch(api, { agent:new HttpProxyAgent('http://183.61.236.54:3128/')}).then( response => response.text() ).then((data) => { parseString(data, {explicitArray: false}, function (err, result) {