-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhainan2.js
More file actions
162 lines (139 loc) · 7.22 KB
/
hainan2.js
File metadata and controls
162 lines (139 loc) · 7.22 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
// 识别名称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}`});
}
}