Skip to content

Commit 36aadbb

Browse files
author
Taois
committed
feat: 优化请求库支持忽略https证书错误
1 parent 39c431e commit 36aadbb

File tree

3 files changed

+1000
-591
lines changed

3 files changed

+1000
-591
lines changed

libs_drpy/fetchAxios.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import FormData from 'form-data';
66
import https from "https";
77
import diagnosticsChannel from 'diagnostics_channel';
88
import {resolveDoh, getSystemProxy} from '../utils/dns_doh.js';
9-
import {ProxyAgent} from 'undici';
9+
import {ProxyAgent, Agent} from 'undici';
1010

1111
let undiciStripUASubscribed = false;
1212

@@ -130,12 +130,15 @@ class FetchAxios {
130130
}
131131

132132
// Proxy and DOH Handling
133-
let fetchDispatcher = undefined;
133+
let fetchDispatcher = new Agent({connect: {rejectUnauthorized: false}});
134134
try {
135135
const proxy = await getSystemProxy();
136136
if (proxy) {
137137
// If proxy detected, use it via Undici ProxyAgent
138-
fetchDispatcher = new ProxyAgent(proxy);
138+
fetchDispatcher = new ProxyAgent({
139+
uri: proxy,
140+
connect: {rejectUnauthorized: false}
141+
});
139142
// When using proxy, we generally rely on the proxy for DNS, so we can skip DOH
140143
// unless we want to force DOH even with Proxy (which is complex).
141144
// "Python requests" logic usually means: if proxy env var, use proxy.

spider/js/狗狗音乐[听].js

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
@header({
3+
searchable: 1,
4+
filterable: 0,
5+
quickSearch: 1,
6+
title: '狗狗音乐[听]',
7+
'类型': '影视',
8+
lang: 'ds'
9+
})
10+
*/
11+
12+
var rule = {
13+
title: '狗狗音乐[听]',
14+
host: 'https://m.kugou.com',
15+
url: '',
16+
searchable: 1,
17+
quickSearch: 1,
18+
filterable: 0,
19+
headers: {
20+
'User-Agent': 'Mozilla/5.0 (Linux; Android 11)',
21+
'Referer': 'https://m.kugou.com/'
22+
},
23+
class_name: '热门榜&特色榜&全球榜',
24+
class_url: 'hot&feature&global',
25+
26+
play_parse: true,
27+
28+
lazy: async function () {
29+
let playUrl = this.input;
30+
let realUrl = '', lyric = '';
31+
32+
const getLrc = async (hash) => {
33+
try {
34+
let lData = JSON.parse(await request(`https://lyrics.kugou.com/search?ver=1&man=yes&client=pc&hash=${hash}`));
35+
let cand = lData?.candidates?.[0];
36+
if (cand) {
37+
let dData = JSON.parse(await request(`https://lyrics.kugou.com/download?ver=1&client=pc&id=${cand.id}&accesskey=${cand.accesskey}`));
38+
return base64Decode(dData.content || '');
39+
}
40+
} catch (e) {
41+
log('getLrc error:', e);
42+
}
43+
return '';
44+
};
45+
46+
const lrcToAss = (lrc) => {
47+
let ass = "[Script Info]\nScriptType: v4.00+\nPlayResX: 1280\nPlayResY: 720\n\n[V4+ Styles]\nStyle: Default,Arial,36,&H00FFFFFF,&H00000000,&H64000000,&H64000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1\n\n[Events]\nFormat: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n";
48+
let times = [];
49+
lrc.split('\n').forEach(line => {
50+
let m = line.match(/\[(\d+):(\d+\.\d+)\](.*)/);
51+
if (m) times.push({start: `0:${m[1]}:${m[2]}`.replace('.', ','), text: m[3].trim()});
52+
});
53+
times.forEach((cur, i) => {
54+
let end = times[i + 1] ? times[i + 1].start : '0:99:00,00';
55+
ass += `Dialogue: 0,${cur.start},${end},Default,,0,0,0,,${cur.text}\n`;
56+
});
57+
return ass;
58+
};
59+
60+
try {
61+
if (playUrl.includes('/mvweb/html/mv_')) {
62+
let mvid = playUrl.match(/mv_(\w+)/)?.[1];
63+
if (mvid) {
64+
let mv = JSON.parse(await request(`https://m.kugou.com/app/i/mv.php?cmd=100&hash=${mvid}&ismp3=1&ext=mp4`))?.mvdata || {};
65+
realUrl = mv.rq?.downurl || mv.sq?.downurl || mv.le?.downurl || '';
66+
if (realUrl) {
67+
let rawLrc = await getLrc(mvid);
68+
if (rawLrc) lyric = lrcToAss(rawLrc);
69+
}
70+
}
71+
} else if (playUrl.includes('hash=')) {
72+
let hash = playUrl.match(/hash=([^&]+)/)?.[1];
73+
if (hash) {
74+
let res = JSON.parse(await request(`https://m.kugou.com/app/i/getSongInfo.php?cmd=playInfo&hash=${hash}`));
75+
realUrl = res.url || res.backup_url?.[0] || '';
76+
if (realUrl) lyric = await getLrc(hash);
77+
}
78+
}
79+
} catch (e) {
80+
console.log(e);
81+
}
82+
83+
return realUrl ? {parse: 0, url: realUrl, header: rule.headers, subtitle: lyric} : playUrl;
84+
},
85+
86+
推荐: async function () {
87+
let VODS = [];
88+
try {
89+
let list = JSON.parse(await request('https://mobilecdnbj.kugou.com/api/v3/rank/list?version=9108&plat=0&showtype=2'))?.data?.info || [];
90+
VODS = list.filter(i => i.classify === 1 || /TOP|||/.test(i.rankname)).slice(0, 12).map(i => ({
91+
vod_id: `https://mobilecdnbj.kugou.com/api/v3/rank/song?rankid=${i.rankid}&page=1&pagesize=200`,
92+
vod_name: i.rankname,
93+
vod_pic: i.imgurl.replace('{size}', '400'),
94+
vod_remarks: i.update_frequency || ''
95+
}));
96+
} catch (e) {
97+
}
98+
return VODS
99+
},
100+
101+
一级: async function () {
102+
let {MY_CATE} = this;
103+
let VODS = [];
104+
try {
105+
let list = JSON.parse(await request('https://mobilecdnbj.kugou.com/api/v3/rank/list?version=9108&plat=0&showtype=2'))?.data?.info || [];
106+
if (MY_CATE === 'hot') list = list.filter(i => i.classify === 1);
107+
else if (MY_CATE === 'feature') list = list.filter(i => i.classify === 5);
108+
else if (MY_CATE === 'global') list = list.filter(i => /|||Billboard/.test(i.rankname));
109+
VODS = list.map(i => ({
110+
vod_id: `https://mobilecdnbj.kugou.com/api/v3/rank/song?rankid=${i.rankid}&page=1&pagesize=200`,
111+
vod_name: i.rankname,
112+
vod_pic: i.imgurl.replace('{size}', '400'),
113+
vod_remarks: i.update_frequency || ''
114+
}));
115+
} catch (e) {
116+
}
117+
return VODS;
118+
},
119+
120+
二级: async function () {
121+
let {input} = this;
122+
let VOD = {};
123+
try {
124+
let songs = JSON.parse(await request(input))?.data?.info || [];
125+
let music = [], mv = [];
126+
songs.forEach((s, i) => {
127+
music.push(`${i + 1}. 🎵 ${s.filename}$https://www.kugou.com/song/?hash=${s.hash}`);
128+
if (s.mvhash) mv.push(`${i + 1}. 🎬 ${s.filename}$https://www.kugou.com/mvweb/html/mv_${s.mvhash}.html`);
129+
});
130+
131+
let playFrom = ['音乐'];
132+
let playUrl = [music.join('#')];
133+
134+
if (mv.length > 0) {
135+
playFrom.push('MV');
136+
playUrl.push(mv.join('#'));
137+
}
138+
139+
VOD = {
140+
vod_name: '酷狗音乐榜单',
141+
vod_pic: songs[0]?.imgurl?.replace('{size}', '400') || '',
142+
vod_remarks: `共 ${songs.length} 首`,
143+
vod_play_from: playFrom.join('$$$'),
144+
vod_play_url: playUrl.join('$$$')
145+
};
146+
} catch (e) {
147+
VOD = {vod_name: '解析失败'};
148+
}
149+
return VOD;
150+
},
151+
152+
搜索: async function () {
153+
let {KEY, MY_PAGE} = this;
154+
let VODS = [];
155+
try {
156+
let list = JSON.parse(await request(`https://mobilecdnbj.kugou.com/api/v3/search/song?format=json&keyword=${encodeURIComponent(KEY)}&page=${MY_PAGE || 1}&pagesize=20`))?.data?.info || [];
157+
VODS = list.map(s => ({
158+
vod_id: `https://www.kugou.com/song/?hash=${s.hash}`,
159+
vod_name: `🎵 ${s.songname}`,
160+
vod_pic: s.album_img ? s.album_img.replace('{size}', '400') : '',
161+
vod_remarks: s.singername
162+
}));
163+
} catch (e) {
164+
}
165+
return VODS;
166+
}
167+
168+
};

0 commit comments

Comments
 (0)