Files
uzVideo/js/core/uzCode.js

241 lines
4.5 KiB
JavaScript
Raw Normal View History

2024-06-15 19:04:15 +08:00
/**
* 视频分类
*/
class VideoClass {
constructor() {
// 当前分类的链接
this.type_id = "";
// 分类名称
this.type_name = "";
}
}
/**
* 视频详情
*/
class VideoDetail {
constructor() {
// 当前视频详情链接
this.vod_id = "";
// 视频名称
this.vod_name = "";
/**
2024-06-27 17:59:35 +08:00
* 线路列表 (没什么特殊区别可为空) 线路1$$$线路2$$$
*/
this.vod_play_from = "";
/**
* 所有剧集 使用 $$$ 分割线路# 分割剧集$ 分割剧集名称和剧集链接
* 第一集$第一集的视频详情链接#第二集$第二集的视频详情链接$$$第一集$第一集的视频详情链接#第二集$第二集的视频详情链接
2024-06-15 19:04:15 +08:00
*/
this.vod_play_url = "";
// 封面
this.vod_pic = "";
// 视频分类
this.type_name = "";
// 更新到
this.vod_remarks = "";
// 豆瓣
this.vod_douban_score = "";
// 语言
this.vod_lang = "";
// 年份
this.vod_year = "";
// 演员
this.vod_actor = "";
// 导演
this.vod_director = "";
// 描述
this.vod_content = "";
// 地区
this.vod_area = "";
}
}
/**
* 返回分类列表
*/
class RepVideoClassList {
constructor() {
/**
* @type {VideoClass[]}
*/
this.data = [];
this.error = "";
}
}
/**
* 视频列表
*/
class VideoList {
constructor() {
/**
* @type {VideoDetail[]}
*/
this.data = [];
this.total = 0;
}
}
/**
* 返回视频列表
*/
class RepVideoList {
constructor() {
/**
* @type {VideoList}
*/
this.data = null;
this.error = "";
}
}
/**
* 返回视频详情
*/
class RepVideoDetail {
constructor() {
/**
* @type {VideoDetail}
*/
this.data = null;
this.error = "";
}
}
/**
* 返回播放地址
*/
class RepVideoPlayUrl {
constructor() {
this.data = "";
this.error = "";
}
}
/**
* UZArgs 封装一组参数用于构建请求URL或进行数据查询
*/
class UZArgs {
constructor() {
// 请求的URL
this.url = "";
// 当前页码
this.page = 1;
//搜索关键词
this.searchWord = "";
}
}
2024-06-22 14:25:29 +08:00
/**
* 脚本基类
*/
2024-06-15 19:04:15 +08:00
class WebApiBase {
/**
* 异步获取分类列表的方法
* @param {UZArgs} args
2024-06-16 10:06:17 +08:00
* @returns {@Promise<JSON.stringify(new RepVideoClassList())>}
2024-06-15 19:04:15 +08:00
*/
async getClassList(args) {
2024-06-16 10:06:17 +08:00
return JSON.stringify(new RepVideoClassList());
2024-06-15 19:04:15 +08:00
}
/**
* 获取分类视频列表
* @param {UZArgs} args
2024-06-16 10:06:17 +08:00
* @returns {@Promise<JSON.stringify(new RepVideoList())>}
2024-06-15 19:04:15 +08:00
*/
async getVideoList(args) {
2024-06-16 10:06:17 +08:00
return JSON.stringify(new RepVideoList());
2024-06-15 19:04:15 +08:00
}
/**
* 获取视频详情
* @param {UZArgs} args
2024-06-16 10:06:17 +08:00
* @returns {@Promise<JSON.stringify(new RepVideoDetail())>}
2024-06-15 19:04:15 +08:00
*/
async getVideoDetail(args) {
2024-06-16 10:06:17 +08:00
return JSON.stringify(new RepVideoDetail());
2024-06-15 19:04:15 +08:00
}
/**
* 获取视频的播放地址
* @param {UZArgs} args
2024-06-16 10:06:17 +08:00
* @returns {@Promise<JSON.stringify(new RepVideoPlayUrl())>}
2024-06-15 19:04:15 +08:00
*/
async getVideoPlayUrl(args) {
2024-06-16 10:06:17 +08:00
return JSON.stringify(new RepVideoPlayUrl());
2024-06-15 19:04:15 +08:00
}
/**
* 搜索视频
* @param {UZArgs} args
2024-06-16 10:06:17 +08:00
* @returns {@Promise<JSON.stringify(new RepVideoList())>}
2024-06-15 19:04:15 +08:00
*/
async searchVideo(args) {
2024-06-16 10:06:17 +08:00
return JSON.stringify(new RepVideoList());
2024-06-15 19:04:15 +08:00
}
}
/**
2024-06-22 14:25:29 +08:00
* req 返回的数据
2024-06-15 19:04:15 +08:00
*/
class ProData {
constructor() {
this.error = "";
this.data;
}
}
/**
2024-06-22 14:25:29 +08:00
* 网络请求也可以使用 fetch
2024-06-27 17:59:35 +08:00
* @param {string} url 请求的URL
* @param {object} options 请求参数 {headers:{},method:"POST",data:{}}
2024-06-15 19:04:15 +08:00
* @returns {Promise<ProData>}
*/
async function req(url, options) {
let pro = await sendMessage(
"req",
JSON.stringify({ url: url, options: options })
);
return pro;
}
class UZUtils {
2024-06-22 14:25:29 +08:00
/**
* 从链接中获取域名
* @param {string} url
* @returns
*/
2024-06-15 19:04:15 +08:00
static getHostFromURL(url) {
2024-06-16 10:06:17 +08:00
const protocolEndIndex = url.indexOf("://");
2024-06-15 19:04:15 +08:00
if (protocolEndIndex === -1) {
return null;
}
const hostStartIndex = protocolEndIndex + 3;
2024-06-16 10:06:17 +08:00
const hostEndIndex = url.indexOf("/", hostStartIndex);
const host =
hostEndIndex === -1
? url.slice(hostStartIndex)
: url.slice(hostStartIndex, hostEndIndex);
2024-06-15 19:04:15 +08:00
return `${url.slice(0, protocolEndIndex + 3)}${host}`;
}
2024-06-22 14:25:29 +08:00
/**
* 去除尾部的斜杠
* @param {string} str
* @returns
*/
static removeTrailingSlash(str) {
if (str.endsWith("/")) {
return str.slice(0, -1);
}
return str;
}
/**
* 用于在 uz 脚本调试模式中展示 log 信息
*/
static debugLog() {
sendMessage("debugLog", JSON.stringify([...arguments]));
}
2024-06-15 19:04:15 +08:00
}