From 5e2a341a797af930ff8b11cd6fe01eb891e533ca Mon Sep 17 00:00:00 2001 From: tonghoil Date: Thu, 18 Sep 2025 16:43:07 +0800 Subject: [PATCH] improve BDInfo Extraction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 优化BDInfo中HDR和DIY字幕/音轨备注的提取 2. 修正Extras的翻译 --- nexus/Torrent/BdInfoExtra.php | 75 ++++++++++++++++++++++---------- resources/lang/zh_CN/torrent.php | 2 +- resources/lang/zh_TW/torrent.php | 2 +- 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/nexus/Torrent/BdInfoExtra.php b/nexus/Torrent/BdInfoExtra.php index 2f1e45f2..5385e0ad 100644 --- a/nexus/Torrent/BdInfoExtra.php +++ b/nexus/Torrent/BdInfoExtra.php @@ -315,19 +315,19 @@ class BdInfoExtra $video['aspect_ratio'] = $ratioMatches[1]; } } else { - // 隐藏视频流,检查是否包含Dolby Vision信息 - if (strpos($matches[4], 'Dolby Vision') !== false) { - // 将Dolby Vision信息添加到第一个视频流描述中 - if (isset($video[0]['description'])) { - $video[0]['description'] .= ' / ' . trim($matches[4]); - } - } + // 隐藏视频流 - 也作为独立的视频流处理,但标记为隐藏 + $video[] = [ + 'codec' => trim($matches[2]), + 'bitrate' => trim($matches[3]) . ' kbps', + 'description' => trim($matches[4]), + 'hidden' => true + ]; } } } /** - * 提取非英文内容 + * 提取字幕和音轨描述中的非英文内容 */ private function extractNonEnglishContent(string $text): array { @@ -336,6 +336,8 @@ class BdInfoExtra // 提取所有非英文字符的内容 if (preg_match_all('/[^\x{0000}-\x{007F}]+/u', $text, $matches)) { foreach ($matches[0] as $match) { + // 去除制表符和括号 + $match = preg_replace('/[\s\t\n\r()()【】\[\]]+/u', '', $match); $match = trim($match); if (!empty($match)) { $result['non_english_content'][] = $match; @@ -478,9 +480,9 @@ class BdInfoExtra { $profiles = []; - // 检查所有视频流 + // 检查所有视频流,跳过隐藏视频流 foreach ($this->bdInfoArr['video'] as $key => $video) { - if (is_array($video) && isset($video['description'])) { + if (is_array($video) && isset($video['description']) && !isset($video['hidden'])) { $description = $video['description']; if (preg_match('/([^\/]*?(?:profile|high|level|main)[^\/]*?)(?:\s*\/|$)/i', $description, $matches)) { $profiles[] = trim($matches[1]); @@ -612,27 +614,52 @@ class BdInfoExtra */ public function getHDRFormat(): string { - // 从第一个视频流获取HDR信息 - $firstVideo = $this->bdInfoArr['video'][0] ?? null; - $description = $firstVideo['description'] ?? ''; - $hdrFormats = []; + // 从所有视频流获取HDR信息 + $hdrTypes = []; + $bitDepths = []; + $nits = []; - // 从VIDEO描述中提取HDR格式 - if (preg_match('/\b(HDR10|HLG|Dolby Vision)\b/i', $description, $matches)) { - $hdrFormats[] = $matches[1]; + foreach ($this->bdInfoArr['video'] as $video) { + $description = $video['description'] ?? ''; + + // 从VIDEO描述中提取HDR格式 + if (preg_match('/\b(HDR10\+|HDR10|HDR|HLG|Dolby Vision)(?:\s|\/|$)/i', $description, $matches)) { + $hdrTypes[] = $matches[1]; + } + + // 检查比特深度 + if (preg_match('/(\d+)\s+bits/', $description, $matches)) { + $bitDepths[] = $matches[1] . ' bits'; + } + + // 检查亮度 + if (preg_match('/(\d+)nits/', $description, $matches)) { + $nits[] = $matches[1] . 'nits'; + } } - // 检查比特深度 - if (preg_match('/(\d+)\s+bits/', $description, $matches)) { - $hdrFormats[] = $matches[1] . ' bits'; + // 去重并构建结果 + $result = []; + + // HDR格式 + $hdrTypes = array_unique($hdrTypes); + if (!empty($hdrTypes)) { + $result[] = implode(' / ', $hdrTypes); } - // 检查亮度 - if (preg_match('/(\d+)nits/', $description, $matches)) { - $hdrFormats[] = $matches[1] . 'nits'; + // 比特深度 + $bitDepths = array_unique($bitDepths); + if (!empty($bitDepths)) { + $result[] = implode(' / ', $bitDepths); + } + + // 亮度 + $nits = array_unique($nits); + if (!empty($nits)) { + $result[] = implode(' / ', $nits); } - return implode(' / ', $hdrFormats); + return implode(' / ', $result); } /** diff --git a/resources/lang/zh_CN/torrent.php b/resources/lang/zh_CN/torrent.php index a7a209af..cb1d151b 100644 --- a/resources/lang/zh_CN/torrent.php +++ b/resources/lang/zh_CN/torrent.php @@ -96,7 +96,7 @@ return [ 'technicalinfo_frame_rate' => '帧率', 'technicalinfo_profile' => '档次', 'technicalinfo_format' => '格式', - 'technicalinfo_extras' => '附加内容', + 'technicalinfo_extras' => '附加信息', 'technicalinfo_ref_frames' => '参考帧', 'technicalinfo_audio' => '音轨 #', 'technicalinfo_subtitles' => '字幕 #', diff --git a/resources/lang/zh_TW/torrent.php b/resources/lang/zh_TW/torrent.php index c82664c5..62f35797 100644 --- a/resources/lang/zh_TW/torrent.php +++ b/resources/lang/zh_TW/torrent.php @@ -96,7 +96,7 @@ return [ 'technicalinfo_frame_rate' => '幀率', 'technicalinfo_profile' => '檔次', 'technicalinfo_format' => '格式', - 'technicalinfo_extras' => '附加內容', + 'technicalinfo_extras' => '附加資訊', 'technicalinfo_ref_frames' => '參考幀', 'technicalinfo_audio' => '音軌 #', 'technicalinfo_subtitles' => '字幕 #',