Skip to content

Commit

Permalink
[feats] reserve cloud processing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiram committed Jun 2, 2024
1 parent 610ecfe commit 2abb41a
Show file tree
Hide file tree
Showing 39 changed files with 101,281 additions and 0 deletions.
120 changes: 120 additions & 0 deletions src/renderer/src/utils/cloud/cloud.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*!
* @module cloud
* @brief 网盘核心库
* @version 3.1.5
*
* @original-author jade
* @original-source {@link https://github.com/jadehh/TVSpider/blob/main/lib/cloud.js | Source on GitHub}
*
* @modified-by HiramWong <admin@catni.cn>
* @modification-date 2023-06-02T20:43:25+08:00
* @modification-description 使用TypeScript适配, 替换eval函数防止报错, 增加日志读取, 自定义请求头用于前端被自动丢失\底层拦截, 并采取措施防止 Tree-Shaking 删除关键代码
*
* **防止 Tree-Shake 说明**:
* - 为了确保 `drpy3.ts` 中的函数和变量不被 Tree Shaking, 已采取以下措施:
* - 作用域参数举例:`[a, b, c].forEach(item => item.length)` —— 显式遍历数组元素防止数组相关操作被优化掉。
* - 作用域函数举例:`let temp = _; temp.stringify({});` —— 对于 `_` 符合的对象,确保其方法被调用,防止被误删。
* - 全局函数与参数举例:`keepUnUse.useful._` —— 对于 `_` 符合的对象,确保其方法被调用,防止被误删。
*
* ---
*/

import { initAli, detailContentAli, playContentAli, aliPlayFormatList, aliName } from './utils/ali';
import {
initQuark,
detailContentQuark,
playContentQuark,
getQuarkPlayFormatList,
quarkName,
getQuarkHeaders,
} from './utils/quark';
import * as Utils from './utils';
import { _ } from './utils/encodings/cat';

async function initCloud(cfg) {
initAli(cfg['aliToken']);
initQuark(cfg['quarkCookie']);
}

async function detailContent(share_url_list, type_name = '电影') {
let ali_share_url_list = [],
quark_share_url_list = [];
const playVod = {};
for (const shareUrl of share_url_list) {
let aliMatches = shareUrl.match(Utils.patternAli);
if (!_.isEmpty(aliMatches)) {
ali_share_url_list.push(aliMatches[1]);
}
let quarkMatches = shareUrl.match(Utils.patternQuark);
if (!_.isEmpty(quarkMatches)) {
quark_share_url_list.push(quarkMatches[1]);
}
}
let aliItems = await detailContentAli(ali_share_url_list);
let quarkItems = await detailContentQuark(quark_share_url_list);
let quarkPlayFormatList = getQuarkPlayFormatList();
await getVod(aliPlayFormatList, aliName, playVod, aliItems.video_items, aliItems.sub_items, type_name);
await getVod(quarkPlayFormatList, quarkName, playVod, quarkItems.video_items, quarkItems.sub_items, type_name);

return playVod;
}

async function getVod(play_foramt_list, cloud_name, playVod, video_item_list, sub_item_list, type_name) {
if (video_item_list.length == 0) {
return;
}
for (let i = 0; i < video_item_list.slice(-1)[0].shareIndex; i++) {
for (let index = 0; index < play_foramt_list.length; index++) {
let vodItems = [];
for (const video_item of video_item_list) {
if (video_item.shareIndex === i + 1) {
vodItems.push(video_item.getEpisodeUrl(type_name) + findSubs(video_item.getName(), sub_item_list));
}
}
playVod[`${cloud_name}-${i + 1}-${play_foramt_list[index]}`] = vodItems.join('#');
}
}
}

//字幕匹配
function pair(name, item_list, sub_item_list) {
for (const item of item_list) {
const sub_name = Utils.removeExt(item.getName()).toLowerCase();
if (name.indexOf(sub_name) > -1 || sub_name.indexOf(name) > -1) {
sub_item_list.push(item);
}
}
}

//找出所有字幕
function findSubs(name, item_list) {
let sub_item_list = [];
pair(Utils.removeExt(name).toLowerCase(), item_list, sub_item_list);
if (sub_item_list.length === 0) {
for (const item of item_list) {
sub_item_list.push(item);
}
}
let sub_str = '';
for (const item of sub_item_list) {
sub_str += '+' + Utils.removeExt(item.getName()) + '@@@' + item.getExt() + '@@@' + item.getFileId();
}
return sub_str;
}
async function playContent(flag, id, flags) {
if (flag.indexOf(aliName) > -1) {
return await playContentAli(flag, id, flags);
} else if (flag.indexOf(quarkName) > -1) {
return await playContentQuark(flag, id, flags);
}
}

function getHeaders(flag) {
if (flag.indexOf(aliName) > -1) {
return {};
} else if (flag.indexOf(quarkName) > -1) {
return getQuarkHeaders();
}
}

export { initCloud, detailContent, playContent, getHeaders, aliName, quarkName };
117 changes: 117 additions & 0 deletions src/renderer/src/utils/cloud/push_agent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* @File : push_agent.js
* @Author : jade
* @Date : 2024/3/6 9:30
* @Email : jadehh@1ive.com
* @Software : Samples
* @Desc :
*/
import { _ } from './utils/encodings/cat';
import { Spider } from './utils/spider';
import { VodDetail } from './utils/spider/vod';
import * as Utils from './utils';
import { detailContent, initCloud, playContent, getHeaders } from './cloud';

class PushSpider extends Spider {
constructor() {
super();
}

getName() {
return '┃推送┃';
}

getAppName() {
return '推送';
}

getJSName() {
return 'push';
}

getType() {
return 4;
}

async init(cfg) {
try {
this.cfgObj = await this.SpiderInit(cfg);
this.catOpenStatus = this.cfgObj.CatOpenStatus;
await initCloud(this.cfgObj);
} catch (e) {
await this.jadeLog.error(`初始化失败,失败原因为:${e}`);
}
}

async check(args) {
// CatVodOpen目前支持http链接和https链接
await spider.jadeLog.debug(`剪切板输入内容为:${args}`);
if (this.catOpenStatus) {
return !!args.startsWith('http');
} else {
// TV目前支持http链接和https链接和Ftp和magnet等格式
return !!(args.startsWith('http') || args.startsWith('ftp') || args.startsWith('magnet'));
}
}

async parseVodDetailfromJson(id) {
let vodDetail = new VodDetail();
vodDetail.vod_pic = Utils.RESOURCEURL + '/resources/push.jpg';
let mather = Utils.patternAli.exec(id);
let quarkMatcher = Utils.patternQuark.exec(id);
if (mather !== null && mather.length > 0) {
let playVod = await detailContent([id]);
vodDetail.vod_play_from = _.keys(playVod).join('$$$');
vodDetail.vod_play_url = _.values(playVod).join('$$$');
} else if (quarkMatcher !== null && quarkMatcher.length > 0) {
let playVod = await detailContent([id]);
vodDetail.vod_play_from = _.keys(playVod).join('$$$');
vodDetail.vod_play_url = _.values(playVod).join('$$$');
} else {
vodDetail.vod_play_from = '推送';
vodDetail.vod_play_url = '推送$' + id;
}
return vodDetail;
}

async setDetail(id) {
this.vodDetail = await this.parseVodDetailfromJson(id);
}

async setPlay(flag, id, flags) {
if (flag === '推送') {
this.playUrl = id;
} else {
this.playUrl = await playContent(flag, id, flags);
this.result.setHeader(getHeaders(flag));
}
}
}

let spider = new PushSpider();

async function check(args) {
return await spider.check(args);
}

async function init(cfg) {
await spider.init(cfg);
}

async function detail(id) {
return await spider.detail(id);
}

async function play(flag, id, flags) {
return await spider.play(flag, id, flags);
}

export function __jsEvalReturn() {
return {
support: check,
init: init,
detail: detail,
play: play,
};
}
export { spider };
Loading

0 comments on commit 2abb41a

Please sign in to comment.