This commit is contained in:
make
2025-11-30 00:31:57 +08:00
parent 734527e8c7
commit 3cebb5b460
3 changed files with 17 additions and 85 deletions

View File

@@ -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;
}