|
|
本文原php代码来自666666的帖子:https://bbs.livecodes.vip/forum.php?mod=viewthread&tid=86
通过deepseek转译,自测可用。
使用方法:
自己在电脑上新建一个txt,将代码复制进去,然后改名为hnws.js
将js文件拷到播放设备的酷9文件夹下的js文件夹内本地使用,也可以将代码上传到平台或服务器去使用
使用以下播放地址:
本地js播放地址:
海南卫视,http://A/ku9/js/hnws.js?id=hnws JS上传到服务器或在线网站播放地址:
海南卫视,https://xxx/xxx/k-web/ku9/js/hnws.js?id=hnws
- // 识别名称main
- function main(item) {
- try {
- // 获取地址和参数
- const url = item.url || "";
- const id = ku9.getQuery(url, "id") || "hnws";
-
- // 频道映射表
- const ids = {
- "hnws": "STHaiNan_channel_lywsgq", // 海南卫视
- "ssws": "STHaiNan_channel_ssws", // 三沙卫视
- "xwpd": "STHaiNan_channel_xwpd", // 海南新闻频道
- "wlpd": "wlpd", // 海南文旅频道
- "jjpd": "jjpd", // 海南自贸频道
- "ggpd": "ggpd", // 海南公共频道
- "sepd": "sepd" // 海南少儿频道
- };
-
- // 频道ID映射
- const channelIdMap = {
- "hnws": 13,
- "ssws": 5,
- "jjpd": 1,
- "xwpd": 3,
- "ggpd": 4,
- "wlpd": 6,
- "sepd": 7
- };
-
- // 检查频道ID是否支持
- if (!ids[id]) {
- const supportedIds = Object.keys(ids).join(", ");
- return JSON.stringify({'error': `不支持的频道ID: ${id},支持的频道有: ${supportedIds}`});
- }
-
- // 获取频道ID
- const channelId = channelIdMap[id] || 13;
-
- // 检查是否有playseek参数(回看)
- const playseek = ku9.getQuery(url, "playseek");
- if (playseek) {
- // 解析playseek参数
- const [startTimeStr, endTimeStr] = playseek.split('-');
- const startTime = `${startTimeStr.substr(0, 4)}-${startTimeStr.substr(4, 2)}-${startTimeStr.substr(6, 2)} ${startTimeStr.substr(8, 2)}:${startTimeStr.substr(10, 2)}:${startTimeStr.substr(12, 2)}`;
- const endTime = `${endTimeStr.substr(0, 4)}-${endTimeStr.substr(4, 2)}-${endTimeStr.substr(6, 2)} ${endTimeStr.substr(8, 2)}:${endTimeStr.substr(10, 2)}:${endTimeStr.substr(12, 2)}`;
-
- // 获取节目时间表
- const scheduleUrl = `https://www.hnntv.cn/api/schedule/byDay?channelId=${channelId}`;
- const scheduleRes = ku9.request(scheduleUrl, "GET", {}, "", true);
-
- if (scheduleRes.code !== 200) {
- return JSON.stringify({'error': '无法获取节目表数据,请稍后重试。'});
- }
-
- let scheduleData;
- try {
- scheduleData = JSON.parse(scheduleRes.body);
- } catch (e) {
- return JSON.stringify({'error': '节目表数据解析失败。'});
- }
-
- // 查找匹配的节目
- let minTimeDiff = Number.MAX_SAFE_INTEGER;
- let matchedSchedules = [];
-
- if (scheduleData && scheduleData.resultSet) {
- const inputStartTime = new Date(startTime).getTime();
-
- scheduleData.resultSet.forEach(dateSchedule => {
- if (dateSchedule.schedules) {
- dateSchedule.schedules.forEach(schedule => {
- const scheduleStartTime = new Date(schedule.startDatetime).getTime();
- const timeDiff = Math.abs(scheduleStartTime - inputStartTime);
-
- if (timeDiff < minTimeDiff) {
- minTimeDiff = timeDiff;
- matchedSchedules = [schedule];
- } else if (timeDiff === minTimeDiff) {
- matchedSchedules.push(schedule);
- }
- });
- }
- });
- }
-
- // 处理匹配结果
- if (matchedSchedules.length > 0) {
- let bestMatch;
-
- if (matchedSchedules.length > 1) {
- // 策略一:选择节目时长最长的
- matchedSchedules.sort((a, b) => {
- const durationA = new Date(a.endDatetime).getTime() - new Date(a.startDatetime).getTime();
- const durationB = new Date(b.endDatetime).getTime() - new Date(b.startDatetime).getTime();
- return durationB - durationA;
- });
- bestMatch = matchedSchedules[0];
- } else {
- bestMatch = matchedSchedules[0];
- }
-
- // 获取回看播放地址
- const wbPlayUrl = `https://ps.hnntv.cn/ps/wbPlayUrl?scheduleId=${bestMatch.id}&channelCode=${ids[id]}&appCode=hnntv&token=&startTime=&endTime=`;
- const wbPlayRes = ku9.request(wbPlayUrl, "GET", {}, "", true);
-
- if (wbPlayRes.code !== 200) {
- return JSON.stringify({'error': '获取回看播放地址失败。'});
- }
-
- let wbPlayData;
- try {
- wbPlayData = JSON.parse(wbPlayRes.body);
- } catch (e) {
- return JSON.stringify({'error': '回看数据解析失败。'});
- }
-
- if (wbPlayData && wbPlayData.businessCode === 200 && wbPlayData.resultSet && wbPlayData.resultSet[0] && wbPlayData.resultSet[0].url) {
- const playUrl = wbPlayData.resultSet[0].url;
-
- return JSON.stringify({
- 'url': playUrl,
- 'headers': JSON.stringify({
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
- 'Referer': 'https://www.hnntv.cn/'
- })
- });
- } else {
- return JSON.stringify({'error': '未能获取到有效的回看播放地址。'});
- }
- } else {
- return JSON.stringify({'error': '未找到相近的节目时间表。'});
- }
- } else {
- // 直播处理
- const liveApiUrl = `http://ps.hnntv.cn/ps/livePlayUrl?appCode=&token=&channelCode=${ids[id]}`;
- const liveRes = ku9.request(liveApiUrl, "GET", {}, "", true);
-
- if (liveRes.code !== 200) {
- return JSON.stringify({'error': '无法获取直播数据,请稍后重试。'});
- }
-
- // 使用正则表达式提取m3u8地址
- const m3u8Match = liveRes.body.match(/"url":"(.*?)"/i);
- if (m3u8Match && m3u8Match[1]) {
- const playUrl = m3u8Match[1];
-
- return JSON.stringify({
- 'url': playUrl,
- 'headers': JSON.stringify({
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
- 'Referer': 'https://www.hnntv.cn/'
- })
- });
- } else {
- return JSON.stringify({'error': '未能获取到有效的直播地址。'});
- }
- }
-
- } catch (e) {
- return JSON.stringify({'error': `脚本执行错误: ${e.message}`});
- }
- }
复制代码
|
|