Skip to content

Commit

Permalink
feat: 直播源模板精确匹配、关闭备注;fix: 直播源匹配异常、分组异常
Browse files Browse the repository at this point in the history
1. ✨新增:直播源模板支持精确匹配、关闭直播地址备注($精确匹配, 关闭备注)
2. 🐛修复:正则表达式导致直播源匹配异常
3. 🐛修复:使用缓存文件更新直播源时分组异常
  • Loading branch information
taksssss committed Dec 18, 2024
1 parent 54862cd commit a02cb76
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2024-12-18

1.**新增**:直播源模板支持精确匹配、关闭直播地址备注($精确匹配, 关闭备注)
2. 🐛**修复**:正则表达式导致直播源匹配异常
3. 🐛**修复**:使用缓存文件更新直播源时分组异常

## 2024-12-14

1.**新增**:cntv 接口
Expand Down
3 changes: 2 additions & 1 deletion epg/assets/html/manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ <h3 style="line-height: 0.5;">直播源管理</h3>
清理:删除服务器中未出现在列表中的直播源文件缓存<br>
停用:停用后不会出现在生成的直播源文件中,包括单个直播源<br>
保持:直播地址不变时,重新解析保持修改不变<br>
模板:生成直播源文件时仅包含模板数据,分组、频道名以模板为准
模板:生成直播源文件时仅包含模板数据,分组、频道名以模板为准,可选「$精确匹配, 关闭备注」


<h3 style="line-height: 0.5;">其他设置</h3>
数据保存天数:清理超过设定天数的数据,包括节目单、定时日志、更新日志<br>
Expand Down
29 changes: 22 additions & 7 deletions epg/public.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ function cleanChannelName($channel, $t2s = false) {
if (strpos($search, 'regex:') === 0) {
$pattern = substr($search, 6);
if (preg_match($pattern, $channel_ori)) {
return preg_replace($pattern, $replace, $channel_ori);
return strtoupper(preg_replace($pattern, $replace, $channel_ori));
}
} else {
// 普通映射,可能为多对一
$channels = array_map('trim', explode(',', $search));
foreach ($channels as $singleChannel) {
if (strcasecmp($channel, str_replace($channel_replacements, '', $singleChannel)) === 0) {
return $replace;
return strtoupper($replace);
}
}
}
Expand Down Expand Up @@ -470,7 +470,7 @@ function dbChannelNameMatch($channelName) {
// 检查该行是否已经修改
$existingRow = isset($existingData[$tag]) ? $existingData[$tag] : null;
$rowData = $existingRow ? $existingRow : [
'groupTitle' => trim($groupPrefix . $groupTitle),
'groupTitle' => trim(($groupPrefix && strpos($groupTitle, $groupPrefix) !== 0 ? $groupPrefix : '') . $groupTitle),
'channelName' => $liveChannelNameProcess ? $channelName : $originalChannelName,
'streamUrl' => $streamUrl,
'iconUrl' => $iconUrl ?? (preg_match('/tvg-logo="([^"]+)"/', $channelInfo, $match) ? $match[1] : ''),
Expand Down Expand Up @@ -513,7 +513,7 @@ function dbChannelNameMatch($channelName) {
// 检查该行是否已经修改
$existingRow = isset($existingData[$tag]) ? $existingData[$tag] : null;
$rowData = $existingRow ? $existingRow : [
'groupTitle' => trim($groupPrefix . $groupTitle),
'groupTitle' => trim(($groupPrefix && strpos($groupTitle, $groupPrefix) !== 0 ? $groupPrefix : '') . $groupTitle),
'channelName' => $liveChannelNameProcess ? $channelName : $originalChannelName,
'streamUrl' => $streamUrl,
'iconUrl' => $iconUrl,
Expand Down Expand Up @@ -546,6 +546,10 @@ function dbChannelNameMatch($channelName) {
function generateLiveFiles($channelData, $fileName) {
global $liveDir;

// 默认参数
$fuzzyMatchingEnable = true;
$commentEnabled = true;

// 读取 template.txt 文件内容
$templateFilePath = $liveDir . 'template.txt';
$templateGroups = [];
Expand All @@ -556,6 +560,16 @@ function generateLiveFiles($channelData, $fileName) {
$line = trim($line, " ,");
if (empty($line)) continue;

if (strpos($line, '$') === 0) {
if (strpos($line, '精确匹配') !== false) { // 关闭模糊匹配
$fuzzyMatchingEnable = false;
}
if (strpos($line, '关闭备注') !== false) { // 关闭备注
$commentEnabled = false;
}
continue;
}

if (strpos($line, '#') === 0) {
$currentGroup = substr($line, 1); // 提取分组名
$templateGroups[$currentGroup] = [];
Expand All @@ -582,12 +596,13 @@ function generateLiveFiles($channelData, $fileName) {

// 检查频道是否匹配
$cleanChannelNameData = cleanChannelName($channelNameData);
if ($cleanChannelNameData === $cleanChannelName ||
if ($channelNameData === $channelName ||
$fuzzyMatchingEnable && ($cleanChannelNameData === $cleanChannelName ||
$cleanChannelName !== 'CGTN' && stripos($cleanChannelName, 'CCTV') === false &&
(stripos($cleanChannelNameData, $cleanChannelName) !== false ||
stripos($cleanChannelName, $cleanChannelNameData) !== false)) {
stripos($cleanChannelName, $cleanChannelNameData) !== false))) {

$streamUrl .= strpos($streamUrl, '$') === false ? "\${$groupTitle}" : ""; // 更新流 URL
$streamUrl .= ($commentEnabled && strpos($streamUrl, '$') === false) ? "\${$groupTitle}" : ""; // 更新流 URL
$row['groupTitle'] = $templateGroup;
$row['channelName'] = $channelName;
$row['streamUrl'] = $streamUrl;
Expand Down

0 comments on commit a02cb76

Please sign in to comment.