mirror of
https://github.com/lyz05/danmaku.git
synced 2026-02-03 02:04:38 +08:00
fix: 根据重定向后的 URL 确定解析器选择逻辑
This commit is contained in:
10
bin/www
10
bin/www
@@ -6,6 +6,7 @@
|
|||||||
const app = require('../app');
|
const app = require('../app');
|
||||||
const debug = require('debug')('danmaku:server');
|
const debug = require('debug')('danmaku:server');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
const os = require('os');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get port from environment and store in Express.
|
* Get port from environment and store in Express.
|
||||||
@@ -24,7 +25,14 @@ const server = http.createServer(app);
|
|||||||
|
|
||||||
server.listen(port, () => {
|
server.listen(port, () => {
|
||||||
console.log(`Listening on port ${port}`);
|
console.log(`Listening on port ${port}`);
|
||||||
console.log(`visit: http://localhost:${port}`);
|
console.log(`Visit the server at the following addresses:`);
|
||||||
|
|
||||||
|
const interfaces = os.networkInterfaces();
|
||||||
|
for (const name in interfaces) {
|
||||||
|
for (const iface of interfaces[name]) {
|
||||||
|
console.log(`- http://${iface.address}:${port} (${name})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
server.on('error', onError);
|
server.on('error', onError);
|
||||||
server.on('listening', onListening);
|
server.on('listening', onListening);
|
||||||
|
|||||||
@@ -13,28 +13,28 @@ const {
|
|||||||
const list = [bilibili, mgtv, tencentvideo, youku, iqiyi, gamer];
|
const list = [bilibili, mgtv, tencentvideo, youku, iqiyi, gamer];
|
||||||
const memory = require("../utils/memory");
|
const memory = require("../utils/memory");
|
||||||
const db = require("../utils/db");
|
const db = require("../utils/db");
|
||||||
|
const UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
||||||
|
|
||||||
// 返回对象{msg: "ok", title: "标题", content: []}
|
// 返回对象{msg: "ok", title: "标题", content: []}
|
||||||
async function build_response(url, req) {
|
async function build_response(url, req) {
|
||||||
// 循环找最终url
|
|
||||||
for (let q = new URLSearchParams(URL.parse(url).query); q.has("url");) {
|
|
||||||
console.log("Redirecting to", url);
|
|
||||||
url = q.get("url");
|
|
||||||
q = new URLSearchParams(URL.parse(url).query);
|
|
||||||
}
|
|
||||||
console.log("Real url:", url);
|
|
||||||
// 测试url是否能下载
|
// 测试url是否能下载
|
||||||
try {
|
try {
|
||||||
await axios.get(url, {
|
const response = await axios.get(url, {
|
||||||
headers: { "Accept-Encoding": "gzip,deflate,compress" }
|
headers: {
|
||||||
|
"Accept-Encoding": "gzip,deflate,compress",
|
||||||
|
"User-Agent": UA
|
||||||
|
},
|
||||||
|
maxRedirects: 10
|
||||||
});
|
});
|
||||||
|
url = response.request.res.responseUrl || url;
|
||||||
|
console.log("Real url:", url);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
// 如果是 403 错误,不报错,继续执行
|
// 如果是 403 错误,不报错,继续执行
|
||||||
if (e.response && e.response.status === 403) {
|
if (e.response && e.response.status === 403) {
|
||||||
console.log("访问视频页面 403 错误,有可能被防火墙拦了");
|
console.log("访问视频页面 403 错误,有可能被防火墙拦了");
|
||||||
} else {
|
} else {
|
||||||
return { msg: "传入的链接非法!请检查链接是否能在浏览器正常打开" };
|
return { msg: "传入的链接非法!请检查链接能否能在浏览器正常打开" };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 循环找到对应的解析器
|
// 循环找到对应的解析器
|
||||||
|
|||||||
Reference in New Issue
Block a user