🦄 reactor: userAgent 深度清洁

This commit is contained in:
zhiyu1998 2024-07-24 16:23:52 +08:00
parent 3d2a2f3676
commit 6db22d4ffa
3 changed files with 22 additions and 37 deletions

View File

@ -5,7 +5,7 @@ import puppeteer from "../../../lib/puppeteer/puppeteer.js";
// http库 // http库
import axios from "axios"; import axios from "axios";
// 常量 // 常量
import { CAT_LIMIT } from "../constants/constant.js"; import { CAT_LIMIT, COMMON_USER_AGENT } from "../constants/constant.js";
// 配置文件 // 配置文件
import config from "../model/index.js"; import config from "../model/index.js";
// 书库 // 书库
@ -253,8 +253,7 @@ export class query extends plugin {
}, },
{ {
headers: { headers: {
"User-Agent": "User-Agent": COMMON_USER_AGENT,
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
}, },
}, },
) )
@ -287,8 +286,7 @@ export class query extends plugin {
axios axios
.get(bdUrl, { .get(bdUrl, {
headers: { headers: {
"User-Agent": "User-Agent": COMMON_USER_AGENT,
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
}, },
timeout: 10000, timeout: 10000,
}) })
@ -298,8 +296,7 @@ export class query extends plugin {
axios axios
.get(url, { .get(url, {
headers: { headers: {
"User-Agent": "User-Agent": COMMON_USER_AGENT,
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
}, },
timeout: 10000, timeout: 10000,
}) })

View File

@ -23,7 +23,7 @@ import {
} from "../utils/bilibili.js"; } from "../utils/bilibili.js";
import { downloadM3u8Videos, mergeAcFileToMp4, parseM3u8, parseUrl } from "../utils/acfun.js"; import { downloadM3u8Videos, mergeAcFileToMp4, parseM3u8, parseUrl } from "../utils/acfun.js";
import { import {
BILI_DEFAULT_INTRO_LEN_LIMIT, BILI_DEFAULT_INTRO_LEN_LIMIT, COMMON_USER_AGENT,
DIVIDING_LINE, DIVIDING_LINE,
douyinTypeMap, douyinTypeMap,
HELP_DOC, IMAGE_TRANSLATION_PROMPT, HELP_DOC, IMAGE_TRANSLATION_PROMPT,
@ -266,8 +266,7 @@ export class tools extends plugin {
// 感谢 Evil0ctalhttps://github.com/Evil0ctal提供的header 和 B1gM8chttps://github.com/B1gM8c的逆向算法X-Bogus // 感谢 Evil0ctalhttps://github.com/Evil0ctal提供的header 和 B1gM8chttps://github.com/B1gM8c的逆向算法X-Bogus
const headers = { const headers = {
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"User-Agent": "User-Agent": COMMON_USER_AGENT,
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
Referer: "https://www.douyin.com/", Referer: "https://www.douyin.com/",
cookie: this.douyinCookie, cookie: this.douyinCookie,
}; };
@ -366,7 +365,7 @@ export class tools extends plugin {
} }
/** /**
* 获取 DY 评论暂时由群友 @慢热 提供 * 获取 DY 评论
* @param e * @param e
* @param douId * @param douId
* @param headers * @param headers
@ -754,7 +753,7 @@ export class tools extends plugin {
async getBiliStream(liveId) { async getBiliStream(liveId) {
return axios.get(`${ BILI_STREAM_INFO }?room_id=${ liveId }`, { return axios.get(`${ BILI_STREAM_INFO }?room_id=${ liveId }`, {
headers: { headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36', 'User-Agent': COMMON_USER_AGENT,
} }
}); });
} }
@ -859,7 +858,7 @@ export class tools extends plugin {
'Sec-Fetch-Site': 'none', 'Sec-Fetch-Site': 'none',
'Sec-Fetch-User': '?1', 'Sec-Fetch-User': '?1',
'Upgrade-Insecure-Requests': '1', 'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36', 'User-Agent': COMMON_USER_AGENT,
}, },
timeout: 10000 // 设置超时时间 timeout: 10000 // 设置超时时间
} }
@ -1028,8 +1027,7 @@ export class tools extends plugin {
}; };
await fetch(API, { await fetch(API, {
headers: { headers: {
"User-Agent": "User-Agent": COMMON_USER_AGENT,
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
}, },
}).then(async resp => { }).then(async resp => {
const html = await resp.text(); const html = await resp.text();
@ -1144,8 +1142,7 @@ export class tools extends plugin {
// 请求netease数据 // 请求netease数据
axios.get(AUTO_NETEASE_SONG_DOWNLOAD.replace("{}", id), { axios.get(AUTO_NETEASE_SONG_DOWNLOAD.replace("{}", id), {
headers: { headers: {
"User-Agent": "User-Agent": COMMON_USER_AGENT,
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
}, },
}).then(async resp => { }).then(async resp => {
// 国内解决方案替换API后这里也需要修改 // 国内解决方案替换API后这里也需要修改
@ -1185,8 +1182,7 @@ export class tools extends plugin {
// 临时接口title经过变换后搜索到的音乐质量提升 // 临时接口title经过变换后搜索到的音乐质量提升
const vipMusicData = await axios.get(NETEASE_TEMP_API.replace("{}", title.replace("-", " ")), { const vipMusicData = await axios.get(NETEASE_TEMP_API.replace("{}", title.replace("-", " ")), {
headers: { headers: {
"User-Agent": "User-Agent": COMMON_USER_AGENT,
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
}, },
}); });
const messageTitle = title + "\nR插件检测到当前为VIP音乐正在转换..."; const messageTitle = title + "\nR插件检测到当前为VIP音乐正在转换...";
@ -1220,8 +1216,7 @@ export class tools extends plugin {
const that = this; const that = this;
axios.get(WEIBO_SINGLE_INFO.replace("{}", id), { axios.get(WEIBO_SINGLE_INFO.replace("{}", id), {
headers: { headers: {
"User-Agent": "User-Agent": COMMON_USER_AGENT,
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"cookie": "_T_WM=40835919903; WEIBOCN_FROM=1110006030; MLOGIN=0; XSRF-TOKEN=4399c8", "cookie": "_T_WM=40835919903; WEIBOCN_FROM=1110006030; MLOGIN=0; XSRF-TOKEN=4399c8",
} }
@ -1264,8 +1259,7 @@ export class tools extends plugin {
if (!videoUrl) return true if (!videoUrl) return true
try { try {
this.downloadVideo(videoUrl, false, { this.downloadVideo(videoUrl, false, {
"User-Agent": "User-Agent": COMMON_USER_AGENT,
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"referer": "https://weibo.com/", "referer": "https://weibo.com/",
}).then(path => { }).then(path => {
@ -1461,7 +1455,7 @@ export class tools extends plugin {
const feedId = idMatch[1]; const feedId = idMatch[1];
const response = await axios.get(WEISHI_VIDEO_INFO.replace("{}", feedId), { const response = await axios.get(WEISHI_VIDEO_INFO.replace("{}", feedId), {
headers: { headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36", "User-Agent": COMMON_USER_AGENT,
} }
}); });
@ -1491,7 +1485,7 @@ export class tools extends plugin {
try { try {
const response = await axios.get(url, { const response = await axios.get(url, {
headers: { headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36", "User-Agent": COMMON_USER_AGENT,
} }
}); });
const html = response.data; const html = response.data;
@ -1573,7 +1567,7 @@ export class tools extends plugin {
if (freyrName === "Apple Music" && (title === "N/A" || album === "N/A" || artist === "N/A")) { if (freyrName === "Apple Music" && (title === "N/A" || album === "N/A" || artist === "N/A")) {
const data = await axios.get(`https://api.fabdl.com/apple-music/get?url=${ message }`, { const data = await axios.get(`https://api.fabdl.com/apple-music/get?url=${ message }`, {
headers: { headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36", "User-Agent": COMMON_USER_AGENT,
"Referer": "https://apple-music-downloader.com/", "Referer": "https://apple-music-downloader.com/",
"Origin": "https://apple-music-downloader.com", "Origin": "https://apple-music-downloader.com",
"Accept": "application/json, text/plain, */*", "Accept": "application/json, text/plain, */*",
@ -1767,8 +1761,7 @@ export class tools extends plugin {
async douyinRequest(url) { async douyinRequest(url) {
const params = { const params = {
headers: { headers: {
"User-Agent": "User-Agent": COMMON_USER_AGENT,
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
}, },
timeout: 10000, timeout: 10000,
}; };

View File

@ -47,15 +47,10 @@ export const TEN_THOUSAND = 10000;
export const CAT_LIMIT = 10; export const CAT_LIMIT = 10;
/** /**
* 有水印的头请求 * 公共的 User-Agent
* @type {{cookie: string, "User-Agent": string, accept: string}} * @type {string}
*/ */
export const XHS_WATERMARK_HEADER = { export const COMMON_USER_AGENT = "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36";
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'cookie': '',
'User-Agent':
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1 Edg/110.0.0.0",
}
/** /**
* 无水印的头请求 * 无水印的头请求
@ -64,7 +59,7 @@ export const XHS_WATERMARK_HEADER = {
export const XHS_NO_WATERMARK_HEADER = { export const XHS_NO_WATERMARK_HEADER = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 ', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 ',
'cookie': '', 'cookie': '',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36', 'User-Agent': COMMON_USER_AGENT,
} }
/** /**