-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdddy.js
More file actions
234 lines (201 loc) · 6.68 KB
/
Copy pathdddy.js
File metadata and controls
234 lines (201 loc) · 6.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
var WidgetMetadata = {
id: "ddys_vod",
title: "低端影视",
description: "获取在线电影、电视剧、动漫",
author: "两块",
site: "https://github.com/2kuai/ForwardWidgets",
version: "1.0.1",
requiredVersion: "0.0.1",
modules: [
{
title: "电影",
description: "获取在线电影",
requiresWebView: false,
functionName: "getMovies",
params: [
{
name: "category",
title: "类型",
type: "enumeration",
enumOptions: [
{ title: "全部电影", value: "" },
{ title: "欧美电影", value: "western-movie" },
{ title: "日韩电影", value: "asian-movie" },
{ title: "华语电影", value: "chinese-movie" }
]
},
{
name: "page",
title: "页数",
type: "page"
}
]
},
{
title: "电视剧",
description: "获取在线电视剧",
requiresWebView: false,
functionName: "getTVSeries",
params: [
{
name: "category",
title: "类型",
type: "enumeration",
enumOptions: [
{ title: "全部剧集", value: "" },
{ title: "欧美剧集", value: "western-drama" },
{ title: "日剧", value: "jp-drama" },
{ title: "韩剧", value: "kr-drama" },
{ title: "华语剧", value: "cn-drama" },
{ title: "其他剧集", value: "other" }
]
},
{
name: "page",
title: "页数",
type: "page"
}
]
},
{
title: "动画",
description: "获取在线动画",
requiresWebView: false,
functionName: "getAnime",
params: [
{
name: "page",
title: "页数",
type: "page"
}
]
}
]
};
const domain = "ddys.pro"; // 主站域名
async function getVideos(params = {}, id) {
try {
// 1. 参数处理与URL构建
const categoryPath = params.category ? `${params.category}/` : '';
const page = params.page || 1;
const url = `https://${domain}/category/${id}/${categoryPath}page/${page}`;
// 2. HTTP请求
const response = await Widget.http.get(url);
if (!response?.data) {
throw new Error("获取数据失败:响应为空");
}
// 3. HTML解析与数据提取
const $ = Widget.html.load(response.data);
const articles = $('article.post-box');
if (articles.length === 0) {
throw new Error("未找到视频数据");
}
// 4. 数据转换
const movies = articles.map((i, el) => {
const $el = $(el);
const titleLink = $el.find('.post-box-title a');
const href = titleLink.attr('href')?.trim() || '';
const rawTitle = titleLink.text().trim();
const description = $el.find('.post-box-text p').text().trim();
// 提取标题和更新信息
const title = rawTitle.replace(/\s*(?:更新至|\().*$/, '');
// 提取季和集信息
let season = "1";
let episode = "";
const updateMatch = rawTitle.match(/更新至\s*(?:第(\d+)季)?(\d+)/);
if (updateMatch) {
season = updateMatch[1] || "1";
episode = updateMatch[2] || "";
}
// 提取封面图片(不使用辅助函数)
const imageStyle = $el.find('.post-box-image').attr('style');
const posterPath = imageStyle ? (imageStyle.match(/url\(['"]?(.*?)['"]?\)/) || [])[1] || '' : '';
const result = {
id: href,
title: title,
type: "url",
posterPath: posterPath,
description: description,
link: href
};
if (season !== "1" && episode !== "0") {
result.releaseDate = `更新至 第${season}季${episode}集`;
}
return result;
}).get().filter(movie => movie.id);
if (movies.length === 0) {
throw new Error("有效视频数据为空");
}
return movies;
} catch (error) {
throw new Error(`获取视频失败: ${error.message}`);
}
}
function extractImageUrl(style) {
if (!style) return '';
try {
return style.match(/url\(['"]?(.*?)['"]?\)/)?.[1] || '';
} catch (e) {
console.warn('封面URL提取失败:', e);
return '';
}
}
async function getMovies(params = {}) {
return getVideos(params, "movie");
}
async function getTVSeries(params = {}) {
return getVideos(params, "drama");
}
async function getAnime(params = {}) {
return getVideos(params, "anime");
}
async function loadDetail(link) {
if (!link) {
throw new Error("链接不能为空");
}
try {
const response = await Widget.http.get(link);
if (!response?.data) {
throw new Error("API返回数据结构不符合预期");
}
const $ = Widget.html.load(response.data);
const jsonData = $('.wp-playlist-script').html();
if (!jsonData) {
throw new Error("未找到视频详情数据");
}
const data = JSON.parse(jsonData);
if (data.type !== "video") {
throw new Error("不支持的详情类型");
}
const tracks = data.tracks;
if (!tracks || tracks.length === 0) {
throw new Error("未找到视频资源");
}
const mediaType = tracks.length > 1 ? "tv" : "movie";
const commonHeaders = {
"range": "bytes=0-1",
"referer": `https://${domain}/`,
"accept-encoding": "identity",
"accept-language": "zh-CN,zh-Hans;q=0.9",
"origin": `https://${domain}`
};
const baseResult = {
id: `https://${domain}${tracks[0].src0 || tracks[0].src3}`,
type: "url",
videoUrl: `https://v.${domain}${tracks[0].src0 || tracks[0].src3}`,
mediaType: mediaType,
customHeaders: commonHeaders
};
if (mediaType === "tv") {
baseResult.episodeItems = tracks.map(item => ({
id: `https://v.${domain}${item.src0 || item.src3}`,
type: "url",
videoUrl: `https://v.${domain}${item.src0 || item.src3}`,
customHeaders: commonHeaders
}));
}
return baseResult;
} catch (error) {
throw new Error(`加载详情失败: ${error.message}`);
}
}