feat: 增加 dy 压缩格式的自由选择

1. 增加 dy 压缩格式选择
2. 优化使用 http 不使用安全格式 https(出问题再修正)
This commit is contained in:
zhiyu1998 2024-06-29 14:59:19 +08:00
parent 2b30dea287
commit 2dbfe925e6
4 changed files with 178 additions and 7 deletions

View File

@ -195,6 +195,8 @@ export class tools extends plugin {
this.biliDuration = this.toolsConfig.biliDuration;
// 加载抖音Cookie
this.douyinCookie = this.toolsConfig.douyinCookie;
// 加载抖音是否压缩
this.douyinCompression = this.toolsConfig.douyinCompression;
// 翻译引擎
this.translateEngine = new Translate({
translateAppId: this.toolsConfig.translateAppId,
@ -277,16 +279,20 @@ export class tools extends plugin {
if (urlType === "video") {
// logger.info(item.video);
// 多位面选择play_addr、play_addr_265、play_addr_h264
// H.265压缩率更高、流量省一半. 相对于H.264
let resUrl;
// 判断是否使用压缩格式
const { play_addr_265, play_addr_h264, play_addr } = item.video;
if (this.douyinCompression === 1) {
// H.265压缩率更高、流量省一半. 相对于H.264
// 265 和 264 随机均衡负载
if (Math.random() > 0.5) {
const videoAddrList = item.video.play_addr_265.url_list;
resUrl = videoAddrList[videoAddrList.length - 1 || 0];
const videoAddrList = Math.random() > 0.5 ? play_addr_265.url_list : play_addr_h264.url_list;
resUrl = videoAddrList[0] || videoAddrList[videoAddrList.length - 1];
} else {
const videoAddrList = item.video.play_addr_h264.url_list;
resUrl = videoAddrList[videoAddrList.length - 1 || 0];
// 原始格式ps. videoAddrList 这里[0]、[1]是 http[最后一个]是 https
const videoAddrList = play_addr.url_list;
resUrl = videoAddrList[0] || videoAddrList[videoAddrList.length - 1];
}
// logger.info(resUrl);
const path = `${ this.getCurDownloadPath(e) }/temp.mp4`;
await this.downloadVideo(resUrl).then(() => {

View File

@ -10,6 +10,7 @@ biliIntroLenLimit: 50 # 哔哩哔哩简介长度限制,填 0 或者 -1 可以
biliDuration: 480 # 哔哩哔哩限制的最大视频时长默认8分钟单位
douyinCookie: '' # douyin's cookie, 格式odin_tt=xxx;passport_fe_beating_status=xxx;sid_guard=xxx;uid_tt=xxx;uid_tt_ss=xxx;sid_tt=xxx;sessionid=xxx;sessionid_ss=xxx;sid_ucp_v1=xxx;ssid_ucp_v1=xxx;passport_assist_user=xxx;ttwid=xxx;
douyinCompression: 1 # 1-压缩0-不压缩;是否使用压缩视频格式的抖音(默认使用),使用后加速视频发送
queueConcurrency: 1 # 【目前只涉及哔哩哔哩的下载】根据服务器性能设置可以并发下载的个数如果你的服务器比较强劲就选择4~12较弱就一个一个下载选择1

View File

@ -119,6 +119,17 @@ export function supportGuoba() {
placeholder: "请输入抖音的Cookie",
},
},
{
field: "tools.douyinCompression",
label: "抖音是否使用压缩格式1-压缩0-不压缩)",
bottomHelpMessage:
"1-压缩0-不压缩;是否使用压缩视频格式的抖音(默认使用),使用后加速视频发送",
component: "Input",
required: false,
componentProps: {
placeholder: "请输入1或者0默认1",
},
},
{
field: "tools.queueConcurrency",
label: "允许多用户下载个数",

153
utils/kugou.js Normal file
View File

@ -0,0 +1,153 @@
// 获取MV信息的函数
export async function getKugouMv(msg, page_limit, count_limit, n) {
const url = `https://mobiles.kugou.com/api/v3/search/mv?format=json&keyword=${encodeURIComponent(
msg
)}&page=${page_limit}&pagesize=${count_limit}&showtype=1`;
try {
const response = await fetch(url);
const json = await response.json();
const info_list = json.data.info;
let data_list = [];
if (n !== "") {
const info = info_list[n];
const json_data2 = await getMvData(info.hash);
const mvdata_list = json_data2.mvdata;
let mvdata = null;
if ("sq" in mvdata_list) {
mvdata = mvdata_list["sq"];
} else if ("le" in mvdata_list) {
mvdata = mvdata_list["le"];
} else if ("rq" in mvdata_list) {
mvdata = mvdata_list["rq"];
}
data_list = [
{
name: info["filename"],
singername: info["singername"],
duration: new Date(info["duration"] * 1000)
.toISOString()
.substr(14, 5),
file_size: `${(mvdata["filesize"] / (1024 * 1024)).toFixed(2)} MB`,
mv_url: mvdata["downurl"],
cover_url: info["imgurl"].replace("/{size}", ""),
// 下面这些字段可能需要你从其他地方获取因为它们不是直接从这个API返回的
// "play_count": json.play_count,
// "like_count": json.like_count,
// "comment_count": json.comment_count,
// "collect_count": json.collect_count,
// "publish_date": json.publish_date
},
];
} else {
data_list = info_list.map((info) => ({
name: info["filename"],
singername: info["singername"],
duration: new Date(info["duration"] * 1000).toISOString().substr(14, 5),
cover_url: info["imgurl"].replace("/{size}", ""),
}));
}
return data_list;
} catch (error) {
console.error("Error fetching MV data:", error);
return [];
}
}
// 获取歌曲信息的函数
export async function getKugouSong(msg, page_limit, count_limit, n) {
const url = `https://mobiles.kugou.com/api/v3/search/song?format=json&keyword=${encodeURIComponent(
msg
)}&page=${page_limit}&pagesize=${count_limit}&showtype=1`;
try {
const response = await fetch(url);
const json = await response.json();
const info_list = json.data.info;
// console.log(info_list)
let data_list = [];
if (n !== "") {
const info = info_list[n];
const song_hash = info.hash;
let song_url = "付费歌曲暂时无法获取歌曲下载链接";
let json_data2 = {};
if (song_hash !== "") {
json_data2 = await getMp3Data(song_hash);
song_url = json_data2.error ? song_url : json_data2.url;
}
data_list = [
{
name: info.filename,
singername: info.singername,
duration: new Date(info.duration * 1000).toISOString().substr(14, 5),
file_size: `${(json_data2.fileSize / (1024 * 1024)).toFixed(2)} MB`,
song_url: song_url,
album_img: json_data2.album_img?.replace("/{size}", ""),
// "mv_url": await get_kugou_mv(msg, page_limit, count_limit, n) 这可能会导致递归调用,视具体情况而定
},
];
} else {
data_list = info_list.map((info) => ({
name: info.filename,
singername: info.singername,
duration: new Date(info.duration * 1000).toISOString().substr(14, 5),
hash: info.hash,
mvhash: info.mvhash ? info.mvhash : null,
}));
}
// 发送响应
return {
code: 200,
text: "解析成功",
type: "歌曲解析",
now: new Date().toISOString(),
data: data_list,
};
} catch (error) {
console.error("Error fetching song data:", error);
return { code: 500, text: "服务器内部错误" };
}
}
// 获取MP3数据的函数
async function getMp3Data(song_hash) {
const url = `https://m.kugou.com/app/i/getSongInfo.php?hash=${song_hash}&cmd=playInfo`;
try {
const response = await fetch(url, {
headers: {
"User-Agent": "Mozilla/6.0 (Linux; Android 11; SAMSUNG SM-G973U) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/14.2 Chrome/87.0.4280.141 Mobile Safari/537.36"
},
redirect: 'follow',
method: 'GET',
});
const json = await response.json();
return json;
} catch (error) {
console.error("Error fetching MP3 data:", error);
return {};
}
}
// 获取MV数据的函数
async function getMvData(mv_hash) {
const url = `http://m.kugou.com/app/i/mv.php?cmd=100&hash=${mv_hash}&ismp3=1&ext=mp4`;
try {
const response = await fetch(url, {
headers: {
"User-Agent": "Mozilla/6.0 (Linux; Android 11; SAMSUNG SM-G973U) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/14.2 Chrome/87.0.4280.141 Mobile Safari/537.36"
},
redirect: 'follow',
method: 'GET',
});
const json = await response.json();
return json;
} catch (error) {
console.error("Error fetching MV data:", error);
return {};
}
}