mirror of
https://github.com/lyz05/danmaku.git
synced 2026-02-03 02:04:38 +08:00
feat: 增加对巴哈姆特動畫瘋的支持
This commit is contained in:
@@ -4,12 +4,13 @@ const Mgtv = require("./mgtv");
|
||||
const Tencentvideo = require("./tencentvideo");
|
||||
const Youku = require("./youku");
|
||||
const Iqiyi = require("./iqiyi");
|
||||
const Gamer = require("./gamer");
|
||||
// 实例化API组件
|
||||
const bilibili = new Bilibili();
|
||||
const mgtv = new Mgtv();
|
||||
const tencentvideo = new Tencentvideo();
|
||||
const youku = new Youku();
|
||||
const iqiyi = new Iqiyi();
|
||||
|
||||
const gamer = new Gamer();
|
||||
//TODO 优化代码
|
||||
module.exports = { bilibili, mgtv, tencentvideo, youku, iqiyi };
|
||||
module.exports = { bilibili, mgtv, tencentvideo, youku, iqiyi, gamer };
|
||||
|
||||
85
routes/api/gamer.js
Normal file
85
routes/api/gamer.js
Normal file
@@ -0,0 +1,85 @@
|
||||
const urlmodule = require("url");
|
||||
const axios = require("axios");
|
||||
const {time_to_second, content_template} = require("./utils");
|
||||
|
||||
function Gamer() {
|
||||
this.name = "巴哈姆特動畫瘋";
|
||||
this.domain = "gamer.com.tw";
|
||||
this.example_urls = [
|
||||
"https://ani.gamer.com.tw/animeVideo.php?sn=41645",
|
||||
"https://ani.gamer.com.tw/animeVideo.php?sn=41889"
|
||||
];
|
||||
|
||||
this.resolve = async (url) => {
|
||||
// 相关API
|
||||
const api_video_info = "https://api.gamer.com.tw/anime/v1/video.php";
|
||||
const api_danmu = "https://api.gamer.com.tw/anime/v1/danmu.php";
|
||||
const q = urlmodule.parse(url, true);
|
||||
// 获取视频sn信息
|
||||
const sn = q.query.sn;
|
||||
if (sn) {
|
||||
var url = api_video_info+'?videoSn='+sn;
|
||||
const res = await axios({
|
||||
url: url,
|
||||
method: "get"
|
||||
});
|
||||
const data = res.data;
|
||||
this.title = data.data.video.title;
|
||||
let promises = [];
|
||||
promises.push(axios({
|
||||
method: "get",
|
||||
url: api_danmu,
|
||||
params: {
|
||||
'videoSn': sn,
|
||||
'geo': 'TW,HK',
|
||||
},
|
||||
}));
|
||||
return promises;
|
||||
} else {
|
||||
this.error_msg = "不支持的巴哈姆特動畫瘋视频网址";
|
||||
return [];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.parse = async (promises) => {
|
||||
//筛选出成功的请求
|
||||
let datas = (await Promise.allSettled(promises))
|
||||
.filter(x => x.status === "fulfilled")
|
||||
.map(x => x.value.data);
|
||||
let contents = [];
|
||||
for (let i = 0; i < datas.length; i++) {
|
||||
const data = datas[i].data;
|
||||
for (const item of data.danmu) {
|
||||
const content = JSON.parse(JSON.stringify(content_template));
|
||||
content.timepoint = item.time / 10;
|
||||
content.content = item.text;
|
||||
content.uid = item.userid;
|
||||
content.color = parseInt(item.color.replace('#', ''), 16)
|
||||
contents.push(content);
|
||||
}
|
||||
}
|
||||
// contents = make_response(contents);
|
||||
return contents;
|
||||
}
|
||||
|
||||
this.work = async (url) => {
|
||||
const promises = await this.resolve(url);
|
||||
console.log(this.name, "api lens:", promises.length);
|
||||
this.content = await this.parse(promises);
|
||||
return {
|
||||
title: this.title,
|
||||
content: this.content,
|
||||
msg: this.error_msg? this.error_msg: "ok"
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = Gamer;
|
||||
|
||||
if(!module.parent) {
|
||||
const g = new Gamer();
|
||||
g.work(g.example_urls[0]).then(res=>{
|
||||
console.log(res)
|
||||
});
|
||||
}
|
||||
@@ -26,6 +26,7 @@ function Iqiyi() {
|
||||
});
|
||||
const data = res.data;
|
||||
const result = data.match(/<script id="__NEXT_DATA__" type="application\/json">(.*?)<\/script>/);
|
||||
console.log(url)
|
||||
let page_info = JSON.parse(result[1]);
|
||||
// console.log('page_info:', page_info)
|
||||
page_info = page_info.props.pageProps.videoInfo
|
||||
|
||||
@@ -7,9 +7,10 @@ const {
|
||||
mgtv,
|
||||
tencentvideo,
|
||||
youku,
|
||||
iqiyi
|
||||
iqiyi,
|
||||
gamer,
|
||||
} = require("./api/base");
|
||||
const list = [bilibili, mgtv, tencentvideo, youku, iqiyi];
|
||||
const list = [bilibili, mgtv, tencentvideo, youku, iqiyi, gamer];
|
||||
const memory = require("../utils/memory");
|
||||
const db = require("../utils/db");
|
||||
|
||||
@@ -29,7 +30,12 @@ async function build_response(url, req) {
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { msg: "传入的链接非法!请检查链接是否能在浏览器正常打开" };
|
||||
// 如果是 403 错误,不报错,继续执行
|
||||
if (e.response && e.response.status === 403) {
|
||||
console.log("访问视频页面 403 错误,有可能被防火墙拦了");
|
||||
} else {
|
||||
return { msg: "传入的链接非法!请检查链接是否能在浏览器正常打开" };
|
||||
}
|
||||
}
|
||||
// 循环找到对应的解析器
|
||||
let fc = undefined;
|
||||
@@ -84,13 +90,15 @@ async function resolve(req, res) {
|
||||
}
|
||||
|
||||
async function index(req, res) {
|
||||
const urls = [mgtv.example_urls[0], bilibili.example_urls[0], tencentvideo.example_urls[0], youku.example_urls[0], iqiyi.example_urls[0]];
|
||||
const urls = list.map(item => item.example_urls[0]);
|
||||
const names = list.map(item => item.name);
|
||||
const path = req.protocol + "://" + req.headers.host + req.originalUrl;
|
||||
const resolve_info = await db.accessCountQuery()
|
||||
const hotlist = await db.hotlistQuery()
|
||||
res.render("danmaku", {
|
||||
path,
|
||||
urls,
|
||||
names,
|
||||
resolve_info,
|
||||
hotlist
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
let chai = require("chai");
|
||||
let chaiHttp = require("chai-http");
|
||||
let app = require("../app");
|
||||
const { bilibili, mgtv, tencentvideo, youku, iqiyi } = require("../routes/api/base");
|
||||
const list = [bilibili, mgtv, tencentvideo, youku, iqiyi];
|
||||
const { bilibili, mgtv, tencentvideo, youku, iqiyi, gamer } = require("../routes/api/base");
|
||||
const list = [bilibili, mgtv, tencentvideo, youku, iqiyi, gamer];
|
||||
chai.should();
|
||||
chai.use(chaiHttp);
|
||||
|
||||
|
||||
@@ -20,7 +20,11 @@
|
||||
</p>
|
||||
<p>
|
||||
使用方法:在当前页面添加一个查询字符串url<br/>
|
||||
目前支持芒果TV,腾讯视频,优酷视频,爱奇艺视频,哔哩哔哩。<br/>
|
||||
目前支持
|
||||
<% names.forEach(function(name, idx) { %>
|
||||
<%= name %><% if(idx !== names.length - 1) { %>,<% } %>
|
||||
<% }); %>。
|
||||
<br/>
|
||||
注意:目前只支持单个视频的解析,不支持专辑的解析。<br/>
|
||||
赞助一下服务器费用吧!<a href="https://blog.lyz05.cn/about/#%E6%89%93%E8%B5%8F">打赏链接</a><br/>
|
||||
遇到什么问题,或有任何意见可以在<a href="https://github.com/lyz05/danmaku/issues">Issue</a>中提出<br/>
|
||||
|
||||
Reference in New Issue
Block a user