From 3cebb5b4604bd10266da06b1e8c571d9f893ad76 Mon Sep 17 00:00:00 2001 From: make Date: Sun, 30 Nov 2025 00:31:57 +0800 Subject: [PATCH] debug --- .../crawler/douban/page/VideoInfoPage.php | 54 +++---------------- .../crawler/maotai/page/VideoInfoPage.php | 41 ++------------ code/public/public/video/common.js | 7 ++- 3 files changed, 17 insertions(+), 85 deletions(-) diff --git a/code/app/task/crawler/douban/page/VideoInfoPage.php b/code/app/task/crawler/douban/page/VideoInfoPage.php index e3af309..f1ad36a 100644 --- a/code/app/task/crawler/douban/page/VideoInfoPage.php +++ b/code/app/task/crawler/douban/page/VideoInfoPage.php @@ -65,72 +65,30 @@ class VideoInfoPage extends BasePage public function getVideo(): array { if (empty($this->arrVideo)) { - - // $arrVideo = json_decode($this->getContent(), true); - - // $arrVideo = $arrVideo['list'][0] ?? []; - // // 如果结构不正确 → 返回空数组 - // if (!$arrVideo) { - // return []; - // } - - // // 2. 检查播放地址 - // $strPlayUrl = $arrVideo['vod_play_url'] ?? null; - - // // 2. 判断是否有播放地址 - // if (empty($arrVideo['vod_play_url'])) { - // // 无播放地址 → 丢弃该数据 - // return []; - // } - - // unset($arrVideo['vod_play_url']); - - // $arrPlayUrl = str_replace('#', '$', $strPlayUrl); - // $arrPlayUrl = explode('$', $arrPlayUrl); - - // $arrPlayUrl = array_filter($arrPlayUrl); - - // $arrPlayUrl = array_chunk($arrPlayUrl, 2); - // foreach ($arrPlayUrl as $intKey => $arrVal) { - // $strUrl = $arrVal[1] ?? ''; - // // *** 过滤掉不是 m3u8 的链接 *** - // if (!str_ends_with($strUrl, '.m3u8')) { - // continue; - // } - // $arrPlayUrl[$intKey] = [ - // 'name' => $arrVal[0], - // 'url' => $strUrl, - // ]; - // } - + $arrVideo = json_decode($this->getContent(), true); $arrVideo = $arrVideo['list'][0] ?? []; - // 如果结构不正确 → 返回空数组 if (!$arrVideo) { return []; } - // 2. 检查播放地址 + $strPlayUrl = $arrVideo['vod_play_url'] ?? null; - // 2. 判断是否有播放地址 if (empty($arrVideo['vod_play_url'])) { - // 无播放地址 → 丢弃该数据 return []; } + unset($arrVideo['vod_play_url']); - // 替换分隔符 + $arrPlayUrl = str_replace('#', '$', $strPlayUrl); - // 拆成数组 $arrPlayUrl = explode('$', $arrPlayUrl); - // 清理空值 + $arrPlayUrl = array_filter(array_map('trim', $arrPlayUrl)); - // 转成二维数组:[[name,url], [name,url], ...] $arrPlayUrl = array_chunk($arrPlayUrl, 2); - // 最终结构 + $cleanPlayUrl = []; foreach ($arrPlayUrl as $pair) { $name = $pair[0] ?? ''; $url = $pair[1] ?? ''; - // *** 过滤掉不是 m3u8 的链接 *** if (!str_ends_with($url, '.m3u8')) { continue; } diff --git a/code/app/task/crawler/maotai/page/VideoInfoPage.php b/code/app/task/crawler/maotai/page/VideoInfoPage.php index f8ed94b..7f21b0c 100644 --- a/code/app/task/crawler/maotai/page/VideoInfoPage.php +++ b/code/app/task/crawler/maotai/page/VideoInfoPage.php @@ -66,58 +66,29 @@ class VideoInfoPage extends BasePage { if (empty($this->arrVideo)) { - // $arrVideo = json_decode($this->getContent(), true); - // $arrVideo = $arrVideo['list'][0]; - // // print_r($arrVideo); - - // $strPlayUrl = $arrVideo['vod_play_url']; - // unset($arrVideo['vod_play_url']); - - // $arrPlayUrl = str_replace('#', '$', $strPlayUrl); - // $arrPlayUrl = explode('$', $arrPlayUrl); - - // $arrPlayUrl = array_filter($arrPlayUrl); - // $arrPlayUrl = array_chunk($arrPlayUrl, 2); - // foreach ($arrPlayUrl as $intKey => $arrVal) { - // $strUrl = $arrVal[1] ?? ''; - // // *** 过滤掉不是 m3u8 的链接 *** - // if (!str_ends_with($strUrl, '.m3u8')) { - // continue; - // } - // $arrPlayUrl[$intKey] = [ - // 'name' => $arrVal[0], - // 'url' => $strUrl, - // ]; - // } - $arrVideo = json_decode($this->getContent(), true); $arrVideo = $arrVideo['list'][0] ?? []; - // 如果结构不正确 → 返回空数组 if (!$arrVideo) { return []; } - // 2. 检查播放地址 + $strPlayUrl = $arrVideo['vod_play_url'] ?? null; - // 2. 判断是否有播放地址 if (empty($arrVideo['vod_play_url'])) { - // 无播放地址 → 丢弃该数据 return []; } + unset($arrVideo['vod_play_url']); - // 替换分隔符 + $arrPlayUrl = str_replace('#', '$', $strPlayUrl); - // 拆成数组 $arrPlayUrl = explode('$', $arrPlayUrl); - // 清理空值 + $arrPlayUrl = array_filter(array_map('trim', $arrPlayUrl)); - // 转成二维数组:[[name,url], [name,url], ...] $arrPlayUrl = array_chunk($arrPlayUrl, 2); - // 最终结构 + $cleanPlayUrl = []; foreach ($arrPlayUrl as $pair) { $name = $pair[0] ?? ''; $url = $pair[1] ?? ''; - // *** 过滤掉不是 m3u8 的链接 *** if (!str_ends_with($url, '.m3u8')) { continue; } @@ -127,8 +98,6 @@ class VideoInfoPage extends BasePage ]; } $arrPlayUrl = $cleanPlayUrl; - - $arrVideo['vod_actor'] = trim($arrVideo['vod_actor']); $arrVideo['vod_director'] = trim($arrVideo['vod_director']); diff --git a/code/public/public/video/common.js b/code/public/public/video/common.js index 653b599..6555f97 100644 --- a/code/public/public/video/common.js +++ b/code/public/public/video/common.js @@ -633,8 +633,13 @@ document.addEventListener("DOMContentLoaded", function () { // 获取某个线路的第一个 url function getFirstPlayUrl(playLine) { - return arrPlayUrl[playLine][0].url; + if (!arrPlayUrl || !arrPlayUrl[playLine] || !arrPlayUrl[playLine][0]) { + console.warn("播放线路不存在:", playLine, arrPlayUrl); + return null; + } + return arrPlayUrl[playLine][0].url || null; } + })