Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiram committed May 6, 2024
2 parents 0f55c81 + e006e4f commit 70735b1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/renderer/src/pages/Play.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,12 @@ const initFilmPlayer = async (isFirst) => {
try {
MessagePlugin.info('嗅探资源中, 如10s没有结果请换源,咻咻咻!');
let snifferPlayUrl: string = url;
let snifferTool = new URL(snifferMode.url);
let snifferApi = snifferTool.origin + snifferTool.pathname;
let snifferApi: string = '';
// 自定义嗅探器并且链接正确才有嗅探器api接口前缀
if(snifferMode.type=='custom' && /^http/.test(snifferMode.url)){
let snifferTool = new URL(snifferMode.url);
snifferApi = snifferTool.origin + snifferTool.pathname;
}
snifferPlayUrl = `${snifferApi}?url=${url}&script=${script}${extra}`;
playerUrl = await sniffer(snifferMode.type, snifferPlayUrl);
createPlayer(playerUrl);
Expand Down
26 changes: 23 additions & 3 deletions src/renderer/src/utils/sniffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ const getQueryParam = (url: string, paramName: string) => {
return searchParams.get(paramName);
}

/***
* 链接中问号后面的query字符串转为object对象
* @param url 链接,可以直接是?开头的
* @param paramName object对象键值,如果不传就返回整个object
*/
const getQuery = (url: string,paramName: string) => {
try {
let arr = url.split("?")[1].split("#")[0].split("&");
const resObj = {};
arr.forEach(item => {
let [key, value = ''] = item.split("=");
resObj[key] = value;
})
return paramName?resObj[paramName]:resObj;
} catch (err) {
console.log(`[t3][getQuery][error]${err}`);
return {};
}
}

const snifferPie = async (url: string, script: string, customRegex: string): Promise<string> => {
console.log('[detail][sniffer][pie][start]: pie嗅探流程开始');
let data: string = '';
Expand Down Expand Up @@ -177,11 +197,11 @@ const snifferCustom = async (url: string): Promise<string> => {
const sniffer = async (type: string, url: string): Promise<string> => {
let data: string = '';

let script = getQueryParam(url, 'script');
let script = getQuery(url, 'script');
if (script) script = Base64.parse(script).toString(Utf8);
const customRegex = getQueryParam(url, 'custom_regex');
const customRegex = getQuery(url, 'custom_regex');

const realUrl = getQueryParam(url, 'url');
const realUrl = getQuery(url, 'url');
if (type === 'iframe') {
data = await snifferIframe(realUrl!, script!, customRegex!);
} else if (type === 'pie') {
Expand Down

0 comments on commit 70735b1

Please sign in to comment.