From a02cb762bc6872f7f95b6a39cd04071bb3b782e1 Mon Sep 17 00:00:00 2001 From: Tak Date: Wed, 18 Dec 2024 23:13:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=9B=B4=E6=92=AD=E6=BA=90=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E7=B2=BE=E7=A1=AE=E5=8C=B9=E9=85=8D=E3=80=81=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E5=A4=87=E6=B3=A8=EF=BC=9Bfix:=20=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E6=BA=90=E5=8C=B9=E9=85=8D=E5=BC=82=E5=B8=B8=E3=80=81=E5=88=86?= =?UTF-8?q?=E7=BB=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. ✨新增:直播源模板支持精确匹配、关闭直播地址备注($精确匹配, 关闭备注) 2. 🐛修复:正则表达式导致直播源匹配异常 3. 🐛修复:使用缓存文件更新直播源时分组异常 --- CHANGELOG.md | 6 ++++++ epg/assets/html/manage.html | 3 ++- epg/public.php | 29 ++++++++++++++++++++++------- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab88179..631f8f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2024-12-18 + +1. ✨**新增**:直播源模板支持精确匹配、关闭直播地址备注($精确匹配, 关闭备注) +2. 🐛**修复**:正则表达式导致直播源匹配异常 +3. 🐛**修复**:使用缓存文件更新直播源时分组异常 + ## 2024-12-14 1. ✨**新增**:cntv 接口 diff --git a/epg/assets/html/manage.html b/epg/assets/html/manage.html index 4b52434..8c69907 100644 --- a/epg/assets/html/manage.html +++ b/epg/assets/html/manage.html @@ -174,7 +174,8 @@

直播源管理

清理:删除服务器中未出现在列表中的直播源文件缓存
停用:停用后不会出现在生成的直播源文件中,包括单个直播源
保持:直播地址不变时,重新解析保持修改不变
- 模板:生成直播源文件时仅包含模板数据,分组、频道名以模板为准 + 模板:生成直播源文件时仅包含模板数据,分组、频道名以模板为准,可选「$精确匹配, 关闭备注」 +

其他设置

数据保存天数:清理超过设定天数的数据,包括节目单、定时日志、更新日志
diff --git a/epg/public.php b/epg/public.php index 8e0266d..653f1cc 100644 --- a/epg/public.php +++ b/epg/public.php @@ -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); } } } @@ -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] : ''), @@ -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, @@ -546,6 +546,10 @@ function dbChannelNameMatch($channelName) { function generateLiveFiles($channelData, $fileName) { global $liveDir; + // 默认参数 + $fuzzyMatchingEnable = true; + $commentEnabled = true; + // 读取 template.txt 文件内容 $templateFilePath = $liveDir . 'template.txt'; $templateGroups = []; @@ -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] = []; @@ -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;