From a898202a84dd8b40818c404a68b33dbeb8af84ea Mon Sep 17 00:00:00 2001 From: Default Date: Wed, 23 Apr 2025 14:59:27 +0800 Subject: [PATCH] debug --- code/app/common.php | 21 ++++++++++++------- code/app/services/ChapterService.php | 6 ++++-- .../crawler/youzhi/page/VideoInfoPage.php | 5 +++-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/code/app/common.php b/code/app/common.php index fd9e926..49ca04b 100644 --- a/code/app/common.php +++ b/code/app/common.php @@ -847,19 +847,26 @@ namespace { if ($intReturnCode === 0) { return true; } else { - echo "Conversion failed: " . implode("\n", $strOutput); return false; } } - function ensureUtf8(string $input): string + /** + * Ensures the input string is valid UTF-8, discarding invalid characters + * + * @param string $strInput + * @return string + */ + function ensureUtf8(string $strInput): string { - // 检查是否为有效的 UTF-8 - if (mb_check_encoding($input, 'UTF-8')) { - return $input; // 已经是有效的 UTF-8 + if (mb_check_encoding($strInput, 'UTF-8')) { + return $strInput; } - // 尝试将非 UTF-8 转换为 UTF-8,忽略无效字符 - return iconv('UTF-8', 'UTF-8//IGNORE', $input); + // 设置无效字符直接丢弃 + mb_substitute_character('none'); + + // 转换为 UTF-8,丢弃无效字符 + return mb_convert_encoding($strInput, 'UTF-8', 'UTF-8'); } } diff --git a/code/app/services/ChapterService.php b/code/app/services/ChapterService.php index 1959b58..1ddab19 100644 --- a/code/app/services/ChapterService.php +++ b/code/app/services/ChapterService.php @@ -53,11 +53,13 @@ class ChapterService $intCacheLifeTime = (int)$arrParams['cache_life'] ?? 0; $arrFilter = [ - 'n_id' => $intNId, 'c_page' => 0, ]; - $arrFilter['n_id'] = $intNId; + if ($intNId > 0) { + $arrFilter['n_id'] = $intNId; + } + $arrSort = []; diff --git a/code/app/task/crawler/youzhi/page/VideoInfoPage.php b/code/app/task/crawler/youzhi/page/VideoInfoPage.php index c6810d5..12ae063 100644 --- a/code/app/task/crawler/youzhi/page/VideoInfoPage.php +++ b/code/app/task/crawler/youzhi/page/VideoInfoPage.php @@ -88,7 +88,8 @@ class VideoInfoPage extends BasePage $arrVideo['vod_director'] = explode(',', $arrVideo['vod_director']); $arrVideo['vod_class'] = explode(',', $arrVideo['vod_class']); $arrVideo['vod_content'] = trim($arrVideo['vod_content']); - $arrVideo['vod_content'] = trim($arrVideo['vod_content'], '\ '); + $arrVideo['vod_content'] = mb_rtrim($arrVideo['vod_content'], '\ '); + $arrVideo['vod_content'] = ensureUtf8($arrVideo['vod_content']); foreach ($arrVideo as $strKey => $mixedVal) { @@ -165,7 +166,7 @@ class VideoInfoPage extends BasePage 'v_director' => $arrPageVideo['v_director'], 'v_class' => $arrPageVideo['v_class'], 'v_letter' => $arrPageVideo['v_letter'], - // 'v_pic' => $arrPageVideo['v_pic'], + 'v_pic' => '', 'v_lang' => $arrPageVideo['v_lang'], 'v_area' => $arrPageVideo['v_area'], 'v_year' => $arrPageVideo['v_year'],