Skip to content

Commit 4bb7b7e

Browse files
authored
Merge branch 'hjdhnx:main' into main
2 parents da10aef + 48d45c2 commit 4bb7b7e

File tree

10 files changed

+2802
-360
lines changed

10 files changed

+2802
-360
lines changed

dashboard/src/api/modules/module.js

Lines changed: 137 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ import { get, post } from '../request'
77
import { API_PATHS, MODULE_ACTIONS, PAGINATION } from '../config'
88
import axios from 'axios'
99

10+
/**
11+
* 处理extend参数,确保对象类型转换为JSON字符串
12+
* @param {string|object} extend - 扩展参数
13+
* @returns {string|undefined} 处理后的extend参数
14+
*/
15+
const processExtendParam = (extend) => {
16+
if (!extend) {
17+
return undefined
18+
}
19+
20+
// 如果extend是对象类型,转换为JSON字符串
21+
if (typeof extend === 'object' && extend !== null) {
22+
try {
23+
return JSON.stringify(extend)
24+
} catch (error) {
25+
console.warn('extend参数JSON序列化失败:', error)
26+
return undefined
27+
}
28+
}
29+
30+
// 如果已经是字符串,直接返回
31+
return extend
32+
}
33+
1034
/**
1135
* 构建模块接口URL
1236
* @param {string} module - 模块名称
@@ -51,16 +75,17 @@ const directApiCall = async (apiUrl, params = {}) => {
5175
* @param {string} module - 模块名称
5276
* @param {object} options - 选项参数
5377
* @param {number} options.filter - 过滤条件(1表示启用,默认启用)
54-
* @param {string} options.extend - 接口数据扩展参数
78+
* @param {string|object} options.extend - 接口数据扩展参数(对象类型会自动转换为JSON字符串)
5579
* @param {string} options.apiUrl - 站点API地址(可选,如果提供则直接使用)
5680
* @returns {Promise} 首页数据
5781
*/
5882
export const getHomeData = async (module, options = {}) => {
5983
const { filter = 1, extend, apiUrl } = options
6084
const params = { filter }
6185

62-
if (extend) {
63-
params.extend = extend
86+
const processedExtend = processExtendParam(extend)
87+
if (processedExtend) {
88+
params.extend = processedExtend
6489
}
6590

6691
// 如果提供了apiUrl,直接使用站点的API地址
@@ -80,7 +105,7 @@ export const getHomeData = async (module, options = {}) => {
80105
* @param {string} params.t - 分类ID
81106
* @param {number} params.pg - 页码(从1开始)
82107
* @param {string} params.ext - base64编码的筛选条件JSON字符串
83-
* @param {string} params.extend - 接口数据扩展参数
108+
* @param {string|object} params.extend - 接口数据扩展参数(对象类型会自动转换为JSON字符串)
84109
* @param {string} params.apiUrl - 可选的直接API地址
85110
* @returns {Promise} 分类数据
86111
*/
@@ -103,8 +128,9 @@ export const getCategoryData = async (module, params) => {
103128
requestParams.ext = ext
104129
}
105130

106-
if (extend) {
107-
requestParams.extend = extend
131+
const processedExtend = processExtendParam(extend)
132+
if (processedExtend) {
133+
requestParams.extend = processedExtend
108134
}
109135

110136
// 如果提供了apiUrl,直接使用站点的API地址
@@ -121,7 +147,7 @@ export const getCategoryData = async (module, params) => {
121147
* @param {string} module - 模块名称
122148
* @param {object} params - 详情参数
123149
* @param {string} params.ids - 视频ID
124-
* @param {string} params.extend - 接口数据扩展参数
150+
* @param {string|object} params.extend - 接口数据扩展参数(对象类型会自动转换为JSON字符串)
125151
* @param {string} params.apiUrl - 可选的直接API地址
126152
* @returns {Promise} 视频详情数据
127153
*/
@@ -133,8 +159,9 @@ export const getVideoDetail = async (module, params) => {
133159
ids
134160
}
135161

136-
if (extend) {
137-
requestParams.extend = extend
162+
const processedExtend = processExtendParam(extend)
163+
if (processedExtend) {
164+
requestParams.extend = processedExtend
138165
}
139166

140167
// 如果提供了apiUrl,直接使用站点的API地址
@@ -151,20 +178,27 @@ export const getVideoDetail = async (module, params) => {
151178
* @param {string} module - 模块名称
152179
* @param {object} params - 播放参数
153180
* @param {string} params.play - 播放地址或ID
154-
* @param {string} params.extend - 接口数据扩展参数
181+
* @param {string} params.flag - 源标识(线路名称)
182+
* @param {string|object} params.extend - 接口数据扩展参数(对象类型会自动转换为JSON字符串)
155183
* @param {string} params.apiUrl - 可选的直接API地址
156184
* @returns {Promise} 播放数据
157185
*/
158186
export const getPlayData = async (module, params) => {
159-
const { play, extend, apiUrl } = params
187+
const { play, flag, extend, apiUrl } = params
160188

161189
const requestParams = {
162190
ac: MODULE_ACTIONS.PLAY,
163191
play
164192
}
165193

166-
if (extend) {
167-
requestParams.extend = extend
194+
// 添加flag参数支持
195+
if (flag) {
196+
requestParams.flag = flag
197+
}
198+
199+
const processedExtend = processExtendParam(extend)
200+
if (processedExtend) {
201+
requestParams.extend = processedExtend
168202
}
169203

170204
// 如果提供了apiUrl,直接使用站点的API地址
@@ -176,13 +210,90 @@ export const getPlayData = async (module, params) => {
176210
return get(buildModuleUrl(module), requestParams)
177211
}
178212

213+
/**
214+
* 播放解析接口 - 专门用于选集播放解析
215+
* @param {string} module - 模块名称
216+
* @param {object} params - 播放参数
217+
* @param {string} params.play - 播放地址或ID(选集链接)
218+
* @param {string} params.flag - 源标识(线路名称)
219+
* @param {string|object} params.extend - 接口数据扩展参数
220+
* @param {string} params.apiUrl - 可选的直接API地址
221+
* @returns {Promise} 播放解析结果
222+
*/
223+
export const parsePlayUrl = async (module, params) => {
224+
try {
225+
console.log('T4播放解析请求:', { module, params })
226+
227+
const playData = await getPlayData(module, params)
228+
console.log('T4播放解析响应:', playData)
229+
230+
// 处理解析结果
231+
const result = {
232+
success: true,
233+
data: playData,
234+
// 解析播放类型
235+
playType: 'direct', // 默认直链
236+
url: '',
237+
needParse: false,
238+
needSniff: false,
239+
message: ''
240+
}
241+
242+
// 检查返回数据格式
243+
if (playData && typeof playData === 'object') {
244+
// 检查parse字段
245+
if (playData.parse === 0) {
246+
// 直链播放
247+
result.playType = 'direct'
248+
result.url = playData.url || playData.play_url || ''
249+
result.needParse = false
250+
result.needSniff = false
251+
result.message = '直链播放'
252+
} else if (playData.parse === 1) {
253+
// 需要嗅探
254+
result.playType = 'sniff'
255+
result.url = playData.url || playData.play_url || ''
256+
result.needSniff = true
257+
result.message = '需要嗅探才能播放,尽情期待'
258+
} else if (playData.jx === 1) {
259+
// 需要解析
260+
result.playType = 'parse'
261+
result.url = playData.url || playData.play_url || ''
262+
result.needParse = true
263+
result.message = '需要解析才能播放,尽情期待'
264+
} else {
265+
// 默认处理为直链
266+
result.url = playData.url || playData.play_url || playData
267+
result.message = '直链播放'
268+
}
269+
} else if (typeof playData === 'string') {
270+
// 如果返回的是字符串,直接作为播放地址
271+
result.url = playData
272+
result.message = '直链播放'
273+
}
274+
275+
return result
276+
} catch (error) {
277+
console.error('T4播放解析失败:', error)
278+
return {
279+
success: false,
280+
error: error.message || '播放解析失败',
281+
playType: 'error',
282+
url: '',
283+
needParse: false,
284+
needSniff: false,
285+
message: '播放解析失败: ' + (error.message || '未知错误')
286+
}
287+
}
288+
}
289+
179290
/**
180291
* 搜索接口
181292
* @param {string} module - 模块名称
182293
* @param {object} params - 搜索参数
183294
* @param {string} params.wd - 搜索关键词
184295
* @param {number} params.pg - 页码(从1开始)
185-
* @param {string} params.extend - 接口数据扩展参数
296+
* @param {string|object} params.extend - 接口数据扩展参数(对象类型会自动转换为JSON字符串)
186297
* @param {string} params.apiUrl - 可选的直接API地址
187298
* @returns {Promise} 搜索结果
188299
*/
@@ -199,8 +310,9 @@ export const searchVideos = async (module, params) => {
199310
pg
200311
}
201312

202-
if (extend) {
203-
requestParams.extend = extend
313+
const processedExtend = processExtendParam(extend)
314+
if (processedExtend) {
315+
requestParams.extend = processedExtend
204316
}
205317

206318
// 如果提供了apiUrl,直接使用站点的API地址
@@ -217,7 +329,7 @@ export const searchVideos = async (module, params) => {
217329
* @param {string} module - 模块名称
218330
* @param {object} data - 动作数据
219331
* @param {string} data.action - 动作类型
220-
* @param {string} data.extend - 接口数据扩展参数
332+
* @param {string|object} data.extend - 接口数据扩展参数(对象类型会自动转换为JSON字符串)
221333
* @param {string} data.apiUrl - 可选的直接API地址
222334
* @returns {Promise} 动作执行结果
223335
*/
@@ -230,8 +342,9 @@ export const executeAction = async (module, data) => {
230342
...otherData
231343
}
232344

233-
if (extend) {
234-
requestData.extend = extend
345+
const processedExtend = processExtendParam(extend)
346+
if (processedExtend) {
347+
requestData.extend = processedExtend
235348
}
236349

237350
console.log('executeAction调用参数:', {
@@ -243,7 +356,6 @@ export const executeAction = async (module, data) => {
243356

244357
// 如果提供了apiUrl,直接使用站点的API地址
245358
if (apiUrl) {
246-
const axios = (await import('axios')).default
247359
console.log('直接调用API:', apiUrl, requestData)
248360

249361
// 如果是测试用的JSON文件,使用GET请求
@@ -280,7 +392,7 @@ export const executeAction = async (module, data) => {
280392
/**
281393
* 刷新模块数据
282394
* @param {string} module - 模块名称
283-
* @param {string} extend - 接口数据扩展参数
395+
* @param {string|object} extend - 接口数据扩展参数(对象类型会自动转换为JSON字符串)
284396
* @param {string} apiUrl - 可选的直接API地址
285397
* @returns {Promise} 刷新结果
286398
*/
@@ -289,8 +401,9 @@ export const refreshModule = async (module, extend, apiUrl) => {
289401
refresh: '1'
290402
}
291403

292-
if (extend) {
293-
params.extend = extend
404+
const processedExtend = processExtendParam(extend)
405+
if (processedExtend) {
406+
params.extend = processedExtend
294407
}
295408

296409
// 如果提供了apiUrl,直接使用站点的API地址
@@ -325,6 +438,7 @@ export default {
325438
getCategoryData,
326439
getVideoDetail,
327440
getPlayData,
441+
parsePlayUrl,
328442
searchVideos,
329443
executeAction,
330444
refreshModule,

dashboard/src/api/services/video.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
getCategoryData,
99
getVideoDetail,
1010
getPlayData,
11+
parsePlayUrl,
1112
searchVideos,
1213
refreshModule,
1314
executeAction
@@ -323,6 +324,52 @@ class VideoService {
323324
}
324325
}
325326

327+
/**
328+
* 解析选集播放地址 - T4接口专用
329+
* @param {string} module - 模块名称
330+
* @param {object} params - 播放参数
331+
* @param {string} params.play - 播放地址或ID(选集链接)
332+
* @param {string} params.flag - 源标识(线路名称)
333+
* @param {string} params.apiUrl - API地址
334+
* @param {string} params.extend - 扩展参数
335+
* @returns {Promise} 播放解析结果
336+
*/
337+
async parseEpisodePlayUrl(module, params) {
338+
if (!validateModule(module)) {
339+
throw new Error('无效的模块名称')
340+
}
341+
342+
const { play, flag, apiUrl, extend } = params
343+
344+
if (!play) {
345+
throw new Error('播放地址不能为空')
346+
}
347+
348+
try {
349+
console.log('VideoService: 开始解析选集播放地址', { module, params })
350+
351+
const parseParams = { play, extend }
352+
353+
// 添加flag参数(线路名称)
354+
if (flag) {
355+
parseParams.flag = flag
356+
}
357+
358+
// 添加API地址
359+
if (apiUrl) {
360+
parseParams.apiUrl = apiUrl
361+
}
362+
363+
const result = await parsePlayUrl(module, parseParams)
364+
console.log('VideoService: 选集播放解析结果', result)
365+
366+
return result
367+
} catch (error) {
368+
console.error('VideoService: 解析选集播放地址失败:', error)
369+
throw error
370+
}
371+
}
372+
326373
/**
327374
* 执行T4 Action动作
328375
* @param {string} module - 模块名称

0 commit comments

Comments
 (0)