Skip to content

Commit

Permalink
修复:生成 xmltv 时,频道匹配错误;修复:频道映射为空时,显示 =>
Browse files Browse the repository at this point in the history
  • Loading branch information
taksssss committed Sep 3, 2024
1 parent cc6d534 commit 8250124
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ PHP 实现的 EPG(电子节目指南)服务端, `Docker` 部署,自带
## 更新日志 📝

### 2024-9-4:

1. 修复:生成 `xmltv` 时,频道匹配错误
2. 修复:频道映射为空时,显示 ` => `

### 2024-9-3:

- 新增:数据导入导出(包括 `config.json``data.db` 文件)
Expand All @@ -48,18 +53,6 @@ PHP 实现的 EPG(电子节目指南)服务端, `Docker` 部署,自带
3. 优化:去掉绝大部分 `频道忽略字符串``频道映射`
4. 优化:跨天数据处理逻辑

### 2024-8-30:

1. 新增:从频道列表新建映射关系(`频道映射` -> `点击编辑`
2. 优化:定时任务 `pid` 获取方式
3. 优化:解析后预加载频道匹配结果

### 2024-8-29:

1. 新增:查看频道匹配结果(`更多设置` -> `解析` -> `查看匹配`
2. 优化:非 `Docker` 用户体验
3. 优化:频道忽略字符串替换顺序

### 其他见[历史更新日志](#历史更新记录)

## TODO:
Expand Down Expand Up @@ -172,6 +165,18 @@ PHP 实现的 EPG(电子节目指南)服务端, `Docker` 部署,自带

## 历史更新记录

### 2024-8-30:

1. 新增:从频道列表新建映射关系(`频道映射` -> `点击编辑`
2. 优化:定时任务 `pid` 获取方式
3. 优化:解析后预加载频道匹配结果

### 2024-8-29:

1. 新增:查看频道匹配结果(`更多设置` -> `解析` -> `查看匹配`
2. 优化:非 `Docker` 用户体验
3. 优化:频道忽略字符串替换顺序

### 2024-8-26:

1. 优化:数据重复时的更新逻辑(越前面,优先级越高)
Expand Down
9 changes: 5 additions & 4 deletions epg/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ function showChangePasswordForm() {
$channel_replacements = array_map('trim', explode("\n", trim($_POST['channel_replacements'])));

// 处理频道映射
$channel_mappings_lines = array_map('trim', explode("\n", trim($_POST['channel_mappings'])));
$channel_mappings = [];
foreach ($channel_mappings_lines as $line) {
list($search, $replace) = preg_split('/=》|=>/', $line);
$channel_mappings[trim(trim(str_replace("", ",", $search)), '[]')] = trim($replace);
if ($mappings = trim($_POST['channel_mappings'] ?? '')) {
foreach (array_filter(array_map('trim', explode("\n", $mappings))) as $line) {
list($search, $replace) = preg_split('/=》|=>/', $line);
$channel_mappings[trim(str_replace("", ",", trim($search)), '[]')] = trim($replace);
}
}

// 获取旧的配置
Expand Down
21 changes: 14 additions & 7 deletions epg/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,25 @@ function getGenList($db) {
$cleanedChannels = array_map('cleanChannelName', $channelsSimplified);

foreach ($cleanedChannels as $index => $cleanedChannel) {
$dbChannel = $cleanedChannel; // 默认使用清理后的频道名
$bestMatch = $cleanedChannel; // 默认使用清理后的频道名
$bestMatchLength = 0; // 初始为0,表示未找到任何匹配

foreach ($allEpgChannels as $epgChannel) {
if (strcasecmp($cleanedChannel, $epgChannel) === 0 ||
stripos($epgChannel, $cleanedChannel) === 0 ||
stripos($cleanedChannel, $epgChannel) !== false) {
$dbChannel = $epgChannel;
break; // 找到最优匹配后跳出循环
if (strcasecmp($cleanedChannel, $epgChannel) === 0) {
$bestMatch = $epgChannel;
break; // 精确匹配,立即跳出循环
}

// 模糊匹配并选择最长的频道名称
if ((stripos($epgChannel, $cleanedChannel) === 0 || stripos($cleanedChannel, $epgChannel) !== false)
&& strlen($epgChannel) > $bestMatchLength) {
$bestMatch = $epgChannel;
$bestMatchLength = strlen($epgChannel); // 更新为更长的匹配
}
}

// 将原始频道名称添加到映射数组中
$gen_list_mapping[$dbChannel][] = $channels[$index];
$gen_list_mapping[$bestMatch][] = $channels[$index];
}

return [
Expand Down

0 comments on commit 8250124

Please sign in to comment.