mirror of
https://github.com/lyz05/danmaku.git
synced 2026-02-02 17:59:53 +08:00
fix: 根据重定向后的 URL 确定解析器选择逻辑
This commit is contained in:
10
bin/www
10
bin/www
@@ -6,6 +6,7 @@
|
||||
const app = require('../app');
|
||||
const debug = require('debug')('danmaku:server');
|
||||
const http = require('http');
|
||||
const os = require('os');
|
||||
|
||||
/**
|
||||
* Get port from environment and store in Express.
|
||||
@@ -24,7 +25,14 @@ const server = http.createServer(app);
|
||||
|
||||
server.listen(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('listening', onListening);
|
||||
|
||||
@@ -13,28 +13,28 @@ const {
|
||||
const list = [bilibili, mgtv, tencentvideo, youku, iqiyi, gamer];
|
||||
const memory = require("../utils/memory");
|
||||
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: []}
|
||||
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是否能下载
|
||||
try {
|
||||
await axios.get(url, {
|
||||
headers: { "Accept-Encoding": "gzip,deflate,compress" }
|
||||
const response = await axios.get(url, {
|
||||
headers: {
|
||||
"Accept-Encoding": "gzip,deflate,compress",
|
||||
"User-Agent": UA
|
||||
},
|
||||
maxRedirects: 10
|
||||
});
|
||||
url = response.request.res.responseUrl || url;
|
||||
console.log("Real url:", url);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
// 如果是 403 错误,不报错,继续执行
|
||||
if (e.response && e.response.status === 403) {
|
||||
console.log("访问视频页面 403 错误,有可能被防火墙拦了");
|
||||
} else {
|
||||
return { msg: "传入的链接非法!请检查链接是否能在浏览器正常打开" };
|
||||
return { msg: "传入的链接非法!请检查链接能否能在浏览器正常打开" };
|
||||
}
|
||||
}
|
||||
// 循环找到对应的解析器
|
||||
|
||||
Reference in New Issue
Block a user