improve BDInfo Extraction

1. 优化BDInfo中HDR和DIY字幕/音轨备注的提取
2. 修正Extras的翻译
This commit is contained in:
tonghoil
2025-09-18 16:43:07 +08:00
parent d16a864841
commit 5e2a341a79
3 changed files with 53 additions and 26 deletions
+51 -24
View File
@@ -315,19 +315,19 @@ class BdInfoExtra
$video['aspect_ratio'] = $ratioMatches[1]; $video['aspect_ratio'] = $ratioMatches[1];
} }
} else { } else {
// 隐藏视频流,检查是否包含Dolby Vision信息 // 隐藏视频流 - 也作为独立的视频流处理,但标记为隐藏
if (strpos($matches[4], 'Dolby Vision') !== false) { $video[] = [
// 将Dolby Vision信息添加到第一个视频流描述中 'codec' => trim($matches[2]),
if (isset($video[0]['description'])) { 'bitrate' => trim($matches[3]) . ' kbps',
$video[0]['description'] .= ' / ' . trim($matches[4]); 'description' => trim($matches[4]),
} 'hidden' => true
} ];
} }
} }
} }
/** /**
* 提取非英文内容 * 提取字幕和音轨描述中的非英文内容
*/ */
private function extractNonEnglishContent(string $text): array private function extractNonEnglishContent(string $text): array
{ {
@@ -336,6 +336,8 @@ class BdInfoExtra
// 提取所有非英文字符的内容 // 提取所有非英文字符的内容
if (preg_match_all('/[^\x{0000}-\x{007F}]+/u', $text, $matches)) { if (preg_match_all('/[^\x{0000}-\x{007F}]+/u', $text, $matches)) {
foreach ($matches[0] as $match) { foreach ($matches[0] as $match) {
// 去除制表符和括号
$match = preg_replace('/[\s\t\n\r()()【】\[\]]+/u', '', $match);
$match = trim($match); $match = trim($match);
if (!empty($match)) { if (!empty($match)) {
$result['non_english_content'][] = $match; $result['non_english_content'][] = $match;
@@ -478,9 +480,9 @@ class BdInfoExtra
{ {
$profiles = []; $profiles = [];
// 检查所有视频流 // 检查所有视频流,跳过隐藏视频流
foreach ($this->bdInfoArr['video'] as $key => $video) { 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']; $description = $video['description'];
if (preg_match('/([^\/]*?(?:profile|high|level|main)[^\/]*?)(?:\s*\/|$)/i', $description, $matches)) { if (preg_match('/([^\/]*?(?:profile|high|level|main)[^\/]*?)(?:\s*\/|$)/i', $description, $matches)) {
$profiles[] = trim($matches[1]); $profiles[] = trim($matches[1]);
@@ -612,27 +614,52 @@ class BdInfoExtra
*/ */
public function getHDRFormat(): string public function getHDRFormat(): string
{ {
// 从第一个视频流获取HDR信息 // 从所有视频流获取HDR信息
$firstVideo = $this->bdInfoArr['video'][0] ?? null; $hdrTypes = [];
$description = $firstVideo['description'] ?? ''; $bitDepths = [];
$hdrFormats = []; $nits = [];
// 从VIDEO描述中提取HDR格式 foreach ($this->bdInfoArr['video'] as $video) {
if (preg_match('/\b(HDR10|HLG|Dolby Vision)\b/i', $description, $matches)) { $description = $video['description'] ?? '';
$hdrFormats[] = $matches[1];
// 从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)) { $result = [];
$hdrFormats[] = $matches[1] . ' bits';
// HDR格式
$hdrTypes = array_unique($hdrTypes);
if (!empty($hdrTypes)) {
$result[] = implode(' / ', $hdrTypes);
} }
// 检查亮 // 比特深
if (preg_match('/(\d+)nits/', $description, $matches)) { $bitDepths = array_unique($bitDepths);
$hdrFormats[] = $matches[1] . 'nits'; if (!empty($bitDepths)) {
$result[] = implode(' / ', $bitDepths);
}
// 亮度
$nits = array_unique($nits);
if (!empty($nits)) {
$result[] = implode(' / ', $nits);
} }
return implode(' / ', $hdrFormats); return implode(' / ', $result);
} }
/** /**
+1 -1
View File
@@ -96,7 +96,7 @@ return [
'technicalinfo_frame_rate' => '帧率', 'technicalinfo_frame_rate' => '帧率',
'technicalinfo_profile' => '档次', 'technicalinfo_profile' => '档次',
'technicalinfo_format' => '格式', 'technicalinfo_format' => '格式',
'technicalinfo_extras' => '附加内容', 'technicalinfo_extras' => '附加信息',
'technicalinfo_ref_frames' => '参考帧', 'technicalinfo_ref_frames' => '参考帧',
'technicalinfo_audio' => '音轨 #', 'technicalinfo_audio' => '音轨 #',
'technicalinfo_subtitles' => '字幕 #', 'technicalinfo_subtitles' => '字幕 #',
+1 -1
View File
@@ -96,7 +96,7 @@ return [
'technicalinfo_frame_rate' => '幀率', 'technicalinfo_frame_rate' => '幀率',
'technicalinfo_profile' => '檔次', 'technicalinfo_profile' => '檔次',
'technicalinfo_format' => '格式', 'technicalinfo_format' => '格式',
'technicalinfo_extras' => '附加內容', 'technicalinfo_extras' => '附加資訊',
'technicalinfo_ref_frames' => '參考幀', 'technicalinfo_ref_frames' => '參考幀',
'technicalinfo_audio' => '音軌 #', 'technicalinfo_audio' => '音軌 #',
'technicalinfo_subtitles' => '字幕 #', 'technicalinfo_subtitles' => '字幕 #',