Skip to content

Commit

Permalink
Merge pull request #184 from hjdhnx/main
Browse files Browse the repository at this point in the history
hipy相关源解析和播放增强
  • Loading branch information
Hiram-Wong authored May 3, 2024
2 parents b0bca41 + 36f50a4 commit 4f3380f
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 46 deletions.
56 changes: 41 additions & 15 deletions src/renderer/src/pages/Play.vue
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ import '@/style/player/veplayer.css';
import 'v3-infinite-loading/lib/style.css';
import 'xgplayer/es/plugins/danmu/index.css';
import Base64 from 'crypto-js/enc-base64';
import Utf8 from 'crypto-js/enc-utf8.js';
import DPlayer from 'dplayer';
import flvjs from 'flv.js';
import Hls from 'hls.js';
Expand Down Expand Up @@ -555,7 +558,7 @@ const VIDEO_PROCESS_DOC = reactive({
const analyzeConfig = ref({
default: {
url: ''
}, //
}, //
flag: [] //标识
})
Expand Down Expand Up @@ -867,38 +870,46 @@ const destroyPlayer = () => {
};
// Helper functions
const fetchHipyPlayUrlHelper = async (site: { [key: string]: any }, flag: string, url: string): Promise<string> => {
const fetchHipyPlayUrlHelper = async (site: { [key: string]: any }, flag: string, url: string): Promise<object> => {
console.log('[detail][hipy][start]获取服务端播放链接开启');
let data: string = '';
let playUrl: string = '';
let script: string = '';
let extra: string = '';
try {
const res = await fetchHipyPlayUrl(site, flag, url);
data = res;
console.log(`[detail][hipy][return]${data}`);
const playRes = await fetchHipyPlayUrl(site, flag, url);
playUrl = playRes.url;
script = playRes.js?Base64.stringify(Utf8.parse(playRes.js)):'';
extra = playRes.parse_extra||extra;
console.log(`[detail][hipy][return]${playUrl}`);
} catch (err) {
console.log(`[detail][hipy][error]${err}`);
} finally {
console.log(`[detail][hipy][end]获取服务端播放链接结束`);
return data;
return {playUrl,script,extra};
};
};
const fetchT3PlayUrlHelper = async (flag: string, id: string, flags: string[] = []): Promise<string> => {
const fetchT3PlayUrlHelper = async (flag: string, id: string, flags: string[] = []): Promise<object> => {
console.log('[detail][t3][start]获取服务端播放链接开启');
let data: string = '';
let playUrl: string = '';
let script: string = '';
let extra: string = '';
try {
const playRes = await fetchT3PlayUrl(flag, id, flags);
if (playRes?.parse === 0 && playRes?.url.indexOf('http://127.0.0.1:9978/proxy') > -1) {
const proxyRes: any = await t3RuleProxy(playRes.url);
await setT3Proxy(proxyRes);
};
data = playRes.url;
console.log(`[detail][t3][return]${data}`);
playUrl = playRes.url;
script = playRes.js?Base64.stringify(Utf8.parse(playRes.js)):'';
extra = playRes.parse_extra||extra;
console.log(`[detail][t3][return]${playUrl}`);
} catch (err) {
console.log(`[detail][t3][error]${err}`);
} finally {
console.log(`[detail][t3][end]获取服务端播放链接结束`);
return data;
return {playUrl,script,extra};
};
};
Expand Down Expand Up @@ -1006,6 +1017,9 @@ const initFilmPlayer = async (isFirst) => {
tmp.url = url;
tmp.sourceUrl = url;
let playerUrl = url;
let script:string = '';
let extra:string = '';
let playData: object = {playUrl:url,script:'',extra:''};
if (site.playUrl) {
playerUrl = await fetchJsonPlayUrlHelper(site.playUrl, url);
Expand Down Expand Up @@ -1034,12 +1048,18 @@ const initFilmPlayer = async (isFirst) => {
break;
case 6:
// hipy获取服务端播放链接
playerUrl = await fetchHipyPlayUrlHelper(site, active.flimSource, url);
playData = await fetchHipyPlayUrlHelper(site, active.flimSource, url);
playerUrl = playData.playUrl;
script = playData.script;
extra = playData.extra;
break;
case 7:
// t3获取服务端播放链接
await t3RuleInit(site);
playerUrl = await fetchT3PlayUrlHelper(active.flimSource, url, []);
playData = await fetchT3PlayUrlHelper(active.flimSource, url, []);
playerUrl = playData.playUrl;
script = playData.script;
extra = playData.extra;
break;
case 8:
// catvox获取服务端播放链接
Expand All @@ -1064,7 +1084,13 @@ const initFilmPlayer = async (isFirst) => {
console.log(`[detail][sniffer][reveal]尝试提取播放链接,type:${site.type}`);
try {
MessagePlugin.info('嗅探资源中, 如10s没有结果请换源,咻咻咻!');
playerUrl = await sniffer(snifferMode.type, snifferMode.type === 'custom' ? `${snifferMode.url}${url}` : url);
let snifferPlayUrl:string = url;
if(snifferMode.type === 'custom'){
let snifferTool = new URL(snifferMode.url);
let snifferApi = snifferTool.origin + snifferTool.pathname;
snifferPlayUrl = `${snifferApi}?url=${url}&script=${script}${extra}`;
}
playerUrl = await sniffer(snifferMode.type, snifferPlayUrl);
createPlayer(playerUrl);
} catch (err) {
console.error(err);
Expand Down
63 changes: 44 additions & 19 deletions src/renderer/src/pages/film/Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@

<script setup lang="ts">
import jsonpath from 'jsonpath';
import Base64 from 'crypto-js/enc-base64';
import Utf8 from 'crypto-js/enc-utf8.js';
import {
HeartIcon,
HeartFilledIcon,
Expand Down Expand Up @@ -202,7 +204,7 @@ watch(
() => props.data,
(val) => {
info.value = val;
getDetailInfo();
}
);
Expand All @@ -226,39 +228,47 @@ const getAnalyzeFlag = async (): Promise<void> => {
};
// Helper functions
const fetchHipyPlayUrlHelper = async (site: { [key: string]: any }, flag: string, url: string): Promise<string> => {
const fetchHipyPlayUrlHelper = async (site: { [key: string]: any }, flag: string, url: string): Promise<object> => {
console.log('[detail][hipy][start]获取服务端播放链接开启');
let data: string = '';
let playUrl: string = '';
let script: string = '';
let extra: string = '';
try {
const res = await fetchHipyPlayUrl(site, flag, url);
data = res;
console.log(`[detail][hipy][return]${data}`);
const playRes = await fetchHipyPlayUrl(site, flag, url);
playUrl = playRes.url;
script = playRes.js?Base64.stringify(Utf8.parse(playRes.js)):'';
extra = playRes.parse_extra||extra;
console.log(`[detail][hipy][return]${playUrl}`);
} catch (err) {
console.log(`[detail][hipy][error]${err}`);
} finally {
console.log(`[detail][hipy][end]获取服务端播放链接结束`);
return data;
}
return {playUrl,script,extra};
};
};
const fetchT3PlayUrlHelper = async (flag: string, id: string, flags: string[] = []): Promise<string> => {
const fetchT3PlayUrlHelper = async (flag: string, id: string, flags: string[] = []): Promise<object> => {
console.log('[detail][t3][start]获取服务端播放链接开启');
let data: string = '';
let playUrl: string = '';
let script: string = '';
let extra: string = '';
try {
const playRes = await fetchT3PlayUrl(flag, id, flags);
if (playRes?.parse === 0 && playRes?.url.indexOf('http://127.0.0.1:9978/proxy') > -1) {
const proxyRes: any = await t3RuleProxy(playRes.url);
await setT3Proxy(proxyRes);
}
};
data = playRes.url;
console.log(`[detail][t3][return]${data}`);
playUrl = playRes.url;
script = playRes.js?Base64.stringify(Utf8.parse(playRes.js)):'';
extra = playRes.parse_extra||extra;
console.log(`[detail][t3][return]${playUrl}`);
} catch (err) {
console.log(`[detail][t3][error]${err}`);
} finally {
console.log(`[detail][t3][end]获取服务端播放链接结束`);
return data;
}
return {playUrl,script,extra};
};
};
const fetchCatvodPlayUrlHelper = async (site: { [key: string]: any }, flag: string, id: string): Promise<string> => {
Expand Down Expand Up @@ -334,6 +344,9 @@ const gotoPlay = async (item) => {
const { snifferMode } = set.value;
let playerUrl = url;
let script:string = '';
let extra:string = '';
let playData: object = {playUrl:url,script:'',extra:''};
if (playUrl) {
playerUrl = await fetchJsonPlayUrlHelper(playUrl, url);
Expand Down Expand Up @@ -362,11 +375,17 @@ const gotoPlay = async (item) => {
break;
case 6:
// hipy获取服务端播放链接
playerUrl = await fetchHipyPlayUrlHelper(formData.value, active.flimSource, url);
playData = await fetchHipyPlayUrlHelper(formData.value, active.flimSource, url);
playerUrl = playData.playUrl;
script = playData.script;
extra = playData.extra;
break;
case 7:
// t3获取服务端播放链接
playerUrl = await fetchT3PlayUrlHelper(active.flimSource, url, []);
playData = await fetchT3PlayUrlHelper(active.flimSource, url, []);
playerUrl = playData.playUrl;
script = playData.script;
extra = playData.extra;
break;
case 8:
// catvod获取服务端播放链接
Expand All @@ -390,7 +409,13 @@ const gotoPlay = async (item) => {
console.log(`[detail][sniffer][reveal]尝试提取播放链接,type:${type}`);
try {
MessagePlugin.info('嗅探资源中, 如10s没有结果请换源,咻咻咻!');
playerUrl = await sniffer(snifferMode.type, snifferMode.type === 'custom' ? `${snifferMode.url}${url}` : url);
let snifferPlayUrl:string = url;
if(snifferMode.type === 'custom'){
let snifferTool = new URL(snifferMode.url);
let snifferApi = snifferTool.origin + snifferTool.pathname;
snifferPlayUrl = `${snifferApi}?url=${url}&script=${script}${extra}`;
}
playerUrl = await sniffer(snifferMode.type, snifferPlayUrl);
if (playerUrl) callSysPlayer(playerUrl);
} catch (err) {
console.error(err);
Expand Down Expand Up @@ -457,7 +482,7 @@ const getHistoryData = async (): Promise<void> => {
try {
const { id } = formData.value;
const res = await detailHistory({ relateId: id, videoId: info.value.vod_id });
if (res) {
dataHistory.value = { ...res };
active.flimSource = res.siteSource;
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/src/utils/cms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,10 @@ const fetchHipyPlayUrl = async(site, flag, play) => {
try {
const url = buildUrl(site.api, `?extend=${site.ext}&flag=${flag}&play=${play}`);
const { data } = await axios.get(url);
let playUrl = data;
if (data?.url) playUrl = data.url;
return playUrl;
return data;
// let playUrl = data;
// if (data?.url) playUrl = data.url;
// return playUrl;
} catch (err) {
throw err;
}
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/src/utils/drpy/drpy3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@

import CryptoJS from 'crypto-js';
import pako from 'pako';
import joinUrl from 'url';
import JSEncrypt from 'wxmp-rsa';

import cheerio from "./cheerio.min";
import { getMubans } from './template';
import gbkTool from './gbk';
import { pdfh as pdfhModule, pdfa as pdfaModule, pd as pdModule, local, req } from './drpyInject';
import { pdfh as pdfhModule, pdfa as pdfaModule, pd as pdModule, local, req, resolve } from './drpyInject';

let consoleHistory: string[] = [];
console["oldLog"] = console.log;
Expand Down Expand Up @@ -93,7 +92,7 @@ const pre = () => {
let rule = {};
// @ts-ignore
let vercode = typeof pdfl === 'function' ? 'drpy3.1' : 'drpy3';
const VERSION = `${vercode} 3.9.50beta3 202400428`;
const VERSION = `${vercode} 3.9.50beta5 202400502`;
/** 已知问题记录
* 1.影魔的jinjia2引擎不支持 {{fl}}对象直接渲染 (有能力解决的话尽量解决下,支持对象直接渲染字符串转义,如果加了|safe就不转义)[影魔牛逼,最新的文件发现这问题已经解决了]
* Array.prototype.append = Array.prototype.push; 这种js执行后有毛病,for in 循环列表会把属性给打印出来 (这个大毛病需要重点排除一下)
Expand Down Expand Up @@ -944,7 +943,7 @@ const getQuery = (url: string) => {
const urljoin = (fromPath, nowPath) => {
fromPath = fromPath || '';
nowPath = nowPath || '';
return joinUrl.resolve(fromPath, nowPath);
return resolve(fromPath, nowPath);
}

var urljoin2 = urljoin;
Expand Down Expand Up @@ -1777,7 +1776,8 @@ const categoryParse = (cateObj) => {
} else {
url = url.replace('fyfilter', rule["filter_url"]);
}

// filter_url支持fyclass
url = url.replaceAll('fyclass', cateObj.tid);
let fl = cateObj.filter ? cateObj.extend : {};
// 自动合并 不同分类对应的默认筛选
if (rule["filter_def"] && typeof rule["filter_def"] === 'object') {
Expand Down
19 changes: 15 additions & 4 deletions src/renderer/src/utils/drpy/drpyInject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @module drpyInject
* @brief T3网络请求、缓存模块处理库
* @version 3.1.1
*
*
* @original-author hjdhnx
* @original-source {@link https://github.com/hjdhnx/hipy-server/blob/master/app/utils/quickjs_ctx.py | Source on GitHub}
*
*
* @modified-by HiramWong <[email protected]>
* @modification-date 2023-03-29T23:02:29+08:00
* @modification-description Python转TypeScript, 适用于JavaScript项目
Expand Down Expand Up @@ -58,7 +58,7 @@ const baseRequest = (_url: string, _object: RequestOptions, _js_type: number = 0
'User-Agent': 'custom-ua',
'Referer': 'custom-referer',
};

for (const [originalHeader, customHeader] of Object.entries(customHeaders)) {
if (headers.hasOwnProperty(originalHeader)) {
headers[customHeader] = headers[originalHeader];
Expand Down Expand Up @@ -147,6 +147,17 @@ const joinUrl = (base: string, url: string) => {
return u.toString();
}

const resolve = (from, to) => {
const resolvedUrl = new URL(to, new URL(from, 'resolve://'));
if (resolvedUrl.protocol === 'resolve:') {
// `from` is a relative URL.
const { pathname, search, hash } = resolvedUrl;
return pathname + search + hash;
}
// return resolvedUrl.toString();
return resolvedUrl.href;
}

const pdfh = (html: string, parse: string, base_url: string = '') => {
const jsp = new jsoup(base_url);
return jsp.pdfh(html, parse, base_url);
Expand Down Expand Up @@ -205,4 +216,4 @@ const local = {
'delete': local_delete
}

export { pdfh, pdfa, pdfl, pd, local , req, joinUrl }
export { pdfh, pdfa, pdfl, pd, local , req, joinUrl, resolve }
20 changes: 20 additions & 0 deletions src/renderer/src/utils/drpy/drpy_test/test_urljoin.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import joinUrl from 'url';

let a = '/api.php/provide/vod/?ac=detail&t={{rule.homeTid}}#next=123&cate=jki';
let b = 'https://suoniapi.com';
let c = joinUrl.resolve(b, a);
console.log(c);

function resolve(from, to) {
const resolvedUrl = new URL(to, new URL(from, 'resolve://'));
if (resolvedUrl.protocol === 'resolve:') {
// `from` is a relative URL.
const { pathname, search, hash } = resolvedUrl;
return pathname + search + hash;
}
// return resolvedUrl.toString();
return resolvedUrl.href;
}

let d = resolve(b, a);
console.log('d:', d);

0 comments on commit 4f3380f

Please sign in to comment.