找回密码
 立即注册
搜索
查看: 537|回复: 5

【js代码】海南官网

  [复制链接]

4

主题

63

回帖

123

积分

注册会员

积分
123
发表于 2025-10-21 09:35:20 | 显示全部楼层 |阅读模式
本文原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
  1. // 识别名称main
  2. function main(item) {
  3.     try {
  4.         // 获取地址和参数
  5.         const url = item.url || "";
  6.         const id = ku9.getQuery(url, "id") || "hnws";
  7.         
  8.         // 频道映射表
  9.         const ids = {
  10.             "hnws": "STHaiNan_channel_lywsgq", // 海南卫视
  11.             "ssws": "STHaiNan_channel_ssws", // 三沙卫视
  12.             "xwpd": "STHaiNan_channel_xwpd", // 海南新闻频道
  13.             "wlpd": "wlpd", // 海南文旅频道
  14.             "jjpd": "jjpd", // 海南自贸频道
  15.             "ggpd": "ggpd", // 海南公共频道
  16.             "sepd": "sepd" // 海南少儿频道
  17.         };
  18.         
  19.         // 频道ID映射
  20.         const channelIdMap = {
  21.             "hnws": 13,
  22.             "ssws": 5,
  23.             "jjpd": 1,
  24.             "xwpd": 3,
  25.             "ggpd": 4,
  26.             "wlpd": 6,
  27.             "sepd": 7
  28.         };
  29.         
  30.         // 检查频道ID是否支持
  31.         if (!ids[id]) {
  32.             const supportedIds = Object.keys(ids).join(", ");
  33.             return JSON.stringify({'error': `不支持的频道ID: ${id},支持的频道有: ${supportedIds}`});
  34.         }
  35.         
  36.         // 获取频道ID
  37.         const channelId = channelIdMap[id] || 13;
  38.         
  39.         // 检查是否有playseek参数(回看)
  40.         const playseek = ku9.getQuery(url, "playseek");
  41.         if (playseek) {
  42.             // 解析playseek参数
  43.             const [startTimeStr, endTimeStr] = playseek.split('-');
  44.             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)}`;
  45.             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)}`;
  46.             
  47.             // 获取节目时间表
  48.             const scheduleUrl = `https://www.hnntv.cn/api/schedule/byDay?channelId=${channelId}`;
  49.             const scheduleRes = ku9.request(scheduleUrl, "GET", {}, "", true);
  50.             
  51.             if (scheduleRes.code !== 200) {
  52.                 return JSON.stringify({'error': '无法获取节目表数据,请稍后重试。'});
  53.             }
  54.             
  55.             let scheduleData;
  56.             try {
  57.                 scheduleData = JSON.parse(scheduleRes.body);
  58.             } catch (e) {
  59.                 return JSON.stringify({'error': '节目表数据解析失败。'});
  60.             }
  61.             
  62.             // 查找匹配的节目
  63.             let minTimeDiff = Number.MAX_SAFE_INTEGER;
  64.             let matchedSchedules = [];
  65.             
  66.             if (scheduleData && scheduleData.resultSet) {
  67.                 const inputStartTime = new Date(startTime).getTime();
  68.                
  69.                 scheduleData.resultSet.forEach(dateSchedule => {
  70.                     if (dateSchedule.schedules) {
  71.                         dateSchedule.schedules.forEach(schedule => {
  72.                             const scheduleStartTime = new Date(schedule.startDatetime).getTime();
  73.                             const timeDiff = Math.abs(scheduleStartTime - inputStartTime);
  74.                            
  75.                             if (timeDiff < minTimeDiff) {
  76.                                 minTimeDiff = timeDiff;
  77.                                 matchedSchedules = [schedule];
  78.                             } else if (timeDiff === minTimeDiff) {
  79.                                 matchedSchedules.push(schedule);
  80.                             }
  81.                         });
  82.                     }
  83.                 });
  84.             }
  85.             
  86.             // 处理匹配结果
  87.             if (matchedSchedules.length > 0) {
  88.                 let bestMatch;
  89.                
  90.                 if (matchedSchedules.length > 1) {
  91.                     // 策略一:选择节目时长最长的
  92.                     matchedSchedules.sort((a, b) => {
  93.                         const durationA = new Date(a.endDatetime).getTime() - new Date(a.startDatetime).getTime();
  94.                         const durationB = new Date(b.endDatetime).getTime() - new Date(b.startDatetime).getTime();
  95.                         return durationB - durationA;
  96.                     });
  97.                     bestMatch = matchedSchedules[0];
  98.                 } else {
  99.                     bestMatch = matchedSchedules[0];
  100.                 }
  101.                
  102.                 // 获取回看播放地址
  103.                 const wbPlayUrl = `https://ps.hnntv.cn/ps/wbPlayUrl?scheduleId=${bestMatch.id}&channelCode=${ids[id]}&appCode=hnntv&token=&startTime=&endTime=`;
  104.                 const wbPlayRes = ku9.request(wbPlayUrl, "GET", {}, "", true);
  105.                
  106.                 if (wbPlayRes.code !== 200) {
  107.                     return JSON.stringify({'error': '获取回看播放地址失败。'});
  108.                 }
  109.                
  110.                 let wbPlayData;
  111.                 try {
  112.                     wbPlayData = JSON.parse(wbPlayRes.body);
  113.                 } catch (e) {
  114.                     return JSON.stringify({'error': '回看数据解析失败。'});
  115.                 }
  116.                
  117.                 if (wbPlayData && wbPlayData.businessCode === 200 && wbPlayData.resultSet && wbPlayData.resultSet[0] && wbPlayData.resultSet[0].url) {
  118.                     const playUrl = wbPlayData.resultSet[0].url;
  119.                     
  120.                     return JSON.stringify({
  121.                         'url': playUrl,
  122.                         'headers': JSON.stringify({
  123.                             'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
  124.                             'Referer': 'https://www.hnntv.cn/'
  125.                         })
  126.                     });
  127.                 } else {
  128.                     return JSON.stringify({'error': '未能获取到有效的回看播放地址。'});
  129.                 }
  130.             } else {
  131.                 return JSON.stringify({'error': '未找到相近的节目时间表。'});
  132.             }
  133.         } else {
  134.             // 直播处理
  135.             const liveApiUrl = `http://ps.hnntv.cn/ps/livePlayUrl?appCode=&token=&channelCode=${ids[id]}`;
  136.             const liveRes = ku9.request(liveApiUrl, "GET", {}, "", true);
  137.             
  138.             if (liveRes.code !== 200) {
  139.                 return JSON.stringify({'error': '无法获取直播数据,请稍后重试。'});
  140.             }
  141.             
  142.             // 使用正则表达式提取m3u8地址
  143.             const m3u8Match = liveRes.body.match(/"url":"(.*?)"/i);
  144.             if (m3u8Match && m3u8Match[1]) {
  145.                 const playUrl = m3u8Match[1];
  146.                
  147.                 return JSON.stringify({
  148.                     'url': playUrl,
  149.                     'headers': JSON.stringify({
  150.                         'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
  151.                         'Referer': 'https://www.hnntv.cn/'
  152.                     })
  153.                 });
  154.             } else {
  155.                 return JSON.stringify({'error': '未能获取到有效的直播地址。'});
  156.             }
  157.         }
  158.         
  159.     } catch (e) {
  160.         return JSON.stringify({'error': `脚本执行错误: ${e.message}`});
  161.     }
  162. }
复制代码



点评

可以流畅播放,谢谢分享!  发表于 2025-10-21 13:13

0

主题

32

回帖

116

积分

注册会员

积分
116
发表于 2025-10-21 09:36:27 | 显示全部楼层
谢谢分享!

0

主题

14

回帖

96

积分

注册会员

积分
96
发表于 2025-10-21 17:49:24 | 显示全部楼层
谢谢分享~~~

0

主题

27

回帖

62

积分

注册会员

积分
62
发表于 2025-10-23 06:22:28 | 显示全部楼层
谢谢楼主的分享

0

主题

10

回帖

9

积分

新手上路

积分
9
发表于 6 天前 | 显示全部楼层

可以流畅播放,谢谢分享!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|直播源论坛