mirror of
https://github.com/lyz05/danmaku.git
synced 2026-02-03 02:04:38 +08:00
fix: 尝试修复芒果TV Z_BUF_ERROR
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { filesize } from "filesize";
|
||||
import pLimit from 'p-limit';
|
||||
|
||||
export default class BaseSource {
|
||||
// 构造函数,初始化通用配置
|
||||
@@ -53,14 +54,14 @@ export default class BaseSource {
|
||||
async work(url) {
|
||||
const promises = await this.resolve(url);
|
||||
if (!this.error_msg) {
|
||||
console.log(this.name, "API lens:", promises.length);
|
||||
this.memory(); //显示内存使用量
|
||||
// 并发请求弹幕数据,等待所有请求完成。
|
||||
let datas = (await Promise.allSettled(promises))
|
||||
.filter(x => x.status === "fulfilled")
|
||||
.map(x => x.value.data);
|
||||
.map(x => x.value.data || x.value.body); //同时兼容 axios 和 got 的返回值结构
|
||||
this.memory(); //显示内存使用量
|
||||
this.content = await this.parse(datas);
|
||||
console.log(this.name, "API lens:", promises.length,"API fulfilled:", datas.length, "比例:", ((datas.length / promises.length) * 100).toFixed(2) + "%");
|
||||
this.content = await this.parse(datas);
|
||||
}
|
||||
return {
|
||||
title: this.title,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import urlmodule from "url";
|
||||
import axios from "axios";
|
||||
import got from "got";
|
||||
import BaseSource from "./base.mjs";
|
||||
|
||||
|
||||
@@ -21,19 +21,28 @@ export default class MgtvSource extends BaseSource {
|
||||
const path = q.pathname.split("/");
|
||||
const cid = path.slice(-2)[0];
|
||||
const vid = path.slice(-1)[0].split(".")[0];
|
||||
const res = await axios.get(api_video_info, {params: {cid, vid}});
|
||||
if (res.data.code !== 200) {
|
||||
this.error_msg = this.name + " API: " + api_video_info + "请求失败,错误信息: " + res.data.msg;
|
||||
const res = await got(api_video_info,{
|
||||
searchParams: {cid, vid},
|
||||
responseType: 'json'
|
||||
})
|
||||
if (res.body.code !== 200) {
|
||||
this.error_msg = this.name + " API: " + api_video_info + "请求失败,错误信息: " + res.body.msg;
|
||||
return null;
|
||||
}
|
||||
this.title = res.data.data.info.videoName;
|
||||
const time = res.data.data.info.time;
|
||||
this.title = res.body.data.info.videoName;
|
||||
const time = res.body.data.info.time;
|
||||
|
||||
const step = 60 * 1000;
|
||||
const end_time = this.time_to_second(time) * 1000;
|
||||
let promises = [];
|
||||
for (let i = 0; i < end_time; i += step) {
|
||||
promises.push(axios({method: "get", url: api_danmaku, params: {vid, cid, time: i}}));
|
||||
promises.push(
|
||||
got(api_danmaku, {
|
||||
searchParams: { vid, cid, time: i },
|
||||
timeout: 10000,
|
||||
responseType: 'json'
|
||||
})
|
||||
);
|
||||
}
|
||||
return promises;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ async function resolve(req, res) {
|
||||
res.redirect(ret.url);
|
||||
} else {
|
||||
console.log("标题:", ret.title, "弹幕数量:", ret.content.length);
|
||||
res.set('Cache-Control', 'public, max-age=86400'); // 缓存一天
|
||||
// res.set('Cache-Control', 'public, max-age=86400'); // 缓存一天
|
||||
res.render("danmaku-xml", { contents: ret.content });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user