兼容茅台播放

This commit is contained in:
make
2025-11-29 22:53:25 +08:00
parent 0747eeaff3
commit 734527e8c7
11 changed files with 532 additions and 85 deletions

View File

@@ -54,6 +54,10 @@ VIEW_TPL_CACHE = false
VIEW_DATA_CACHE = false VIEW_DATA_CACHE = false
VIEW_DATA_CACHE_DRIVER = redis VIEW_DATA_CACHE_DRIVER = redis
# VIDEO
DEFAULT_LINE = maotai
TASK_TEST = true
# PROXY # PROXY
PROXY_STATUS = true PROXY_STATUS = true
# PROXY_CODE = XIONGMAO # PROXY_CODE = XIONGMAO

View File

@@ -112,7 +112,9 @@ class Scheduler
} }
$intTotalPage = $arrCategory['total_page']; $intTotalPage = $arrCategory['total_page'];
// $intTotalPage = 2 ; // test if(config("video.task_test")){
$intTotalPage = 2 ; // test
}
$arrFilter = []; $arrFilter = [];
for ($intStartPage = 1; $intStartPage <= $intTotalPage; $intStartPage++) { for ($intStartPage = 1; $intStartPage <= $intTotalPage; $intStartPage++) {

View File

@@ -66,37 +66,80 @@ class VideoInfoPage extends BasePage
{ {
if (empty($this->arrVideo)) { if (empty($this->arrVideo)) {
$arrVideo = json_decode($this->getContent(), true); // $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] ?? []; $arrVideo = $arrVideo['list'][0] ?? [];
// 如果结构不正确 → 返回空数组 // 如果结构不正确 → 返回空数组
if (!$arrVideo) { if (!$arrVideo) {
return []; return [];
} }
// 2. 检查播放地址 // 2. 检查播放地址
$strPlayUrl = $arrVideo['vod_play_url'] ?? null; $strPlayUrl = $arrVideo['vod_play_url'] ?? null;
// 2. 判断是否有播放地址 // 2. 判断是否有播放地址
if (empty($arrVideo['vod_play_url'])) { if (empty($arrVideo['vod_play_url'])) {
// 无播放地址 → 丢弃该数据 // 无播放地址 → 丢弃该数据
return []; return [];
} }
unset($arrVideo['vod_play_url']); unset($arrVideo['vod_play_url']);
// 替换分隔符
$arrPlayUrl = str_replace('#', '$', $strPlayUrl); $arrPlayUrl = str_replace('#', '$', $strPlayUrl);
// 拆成数组
$arrPlayUrl = explode('$', $arrPlayUrl); $arrPlayUrl = explode('$', $arrPlayUrl);
// 清理空值
$arrPlayUrl = array_filter($arrPlayUrl); $arrPlayUrl = array_filter(array_map('trim', $arrPlayUrl));
// 转成二维数组:[[name,url], [name,url], ...]
$arrPlayUrl = array_chunk($arrPlayUrl, 2); $arrPlayUrl = array_chunk($arrPlayUrl, 2);
foreach ($arrPlayUrl as $intKey => $arrVal) { // 最终结构
$arrPlayUrl[$intKey] = [ $cleanPlayUrl = [];
'name' => $arrVal[0], foreach ($arrPlayUrl as $pair) {
'url' => $arrVal[1] ?? $arrVal[0], $name = $pair[0] ?? '';
$url = $pair[1] ?? '';
// *** 过滤掉不是 m3u8 的链接 ***
if (!str_ends_with($url, '.m3u8')) {
continue;
}
$cleanPlayUrl[] = [
'name' => $name,
'url' => $url,
]; ];
} }
$arrPlayUrl = $cleanPlayUrl;
$arrVideo['vod_actor'] = trim($arrVideo['vod_actor']); $arrVideo['vod_actor'] = trim($arrVideo['vod_actor']);
$arrVideo['vod_director'] = trim($arrVideo['vod_director']); $arrVideo['vod_director'] = trim($arrVideo['vod_director']);
@@ -185,15 +228,44 @@ class VideoInfoPage extends BasePage
$arrExistsVideo = (array) $arrExistsVideo; $arrExistsVideo = (array) $arrExistsVideo;
// 数据库里的旧播放源
$oldPlayUrl = $arrExistsVideo['v_play_url'] ?? [];
// 本次抓取的新播放源(可能不完整)
$newPagePlayUrl = $arrPageVideo['v_play_url'] ?? [];
// 合并新老线路(新覆盖旧)
$mergedPlayUrl = array_merge($oldPlayUrl, $newPagePlayUrl);
// 构造一个重新排序的结构
$sortedPlayUrl = [];
// 默认线路
$strDefaultLine = config("video.default_line");
// 1. maotai 优先
if (!empty($mergedPlayUrl[$strDefaultLine])) {
$sortedPlayUrl[$strDefaultLine] = $mergedPlayUrl[$strDefaultLine];
}
// 2. 其他线路顺序不变
foreach ($mergedPlayUrl as $source => $value) {
if ($source !== $strDefaultLine) {
$sortedPlayUrl[$source] = $value;
}
}
// 更新数据
$arrUpdate = [ $arrUpdate = [
'updated_at' => new \MongoDB\BSON\UTCDateTime(), 'updated_at' => new \MongoDB\BSON\UTCDateTime(),
'v_play_url.douban' => $arrPageVideo['v_play_url']['douban'], 'v_play_url' => $sortedPlayUrl,
]; ];
$this->getVideoModel()->updateOne( $this->getVideoModel()->updateOne(
['v_name' => $arrPageVideo['v_name']], ['v_name' => $arrPageVideo['v_name']],
['$set' => $arrUpdate], ['$set' => $arrUpdate]
); );
$this->strPicLocalPath = $arrExistsVideo['v_pic']; $this->strPicLocalPath = $arrExistsVideo['v_pic'];
} else { } else {

View File

@@ -66,22 +66,65 @@ class VideoInfoPage extends BasePage
{ {
if (empty($this->arrVideo)) { 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_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 = json_decode($this->getContent(), true);
$arrVideo = $arrVideo['list'][0]; $arrVideo = $arrVideo['list'][0] ?? [];
// print_r($arrVideo); // 如果结构不正确 → 返回空数组
if (!$arrVideo) {
$strPlayUrl = $arrVideo['vod_play_url']; return [];
}
// 2. 检查播放地址
$strPlayUrl = $arrVideo['vod_play_url'] ?? null;
// 2. 判断是否有播放地址
if (empty($arrVideo['vod_play_url'])) {
// 无播放地址 → 丢弃该数据
return [];
}
unset($arrVideo['vod_play_url']); unset($arrVideo['vod_play_url']);
// 替换分隔符
$arrPlayUrl = str_replace('#', '$', $strPlayUrl); $arrPlayUrl = str_replace('#', '$', $strPlayUrl);
// 拆成数组
$arrPlayUrl = explode('$', $arrPlayUrl); $arrPlayUrl = explode('$', $arrPlayUrl);
// 清理空值
$arrPlayUrl = array_filter(array_map('trim', $arrPlayUrl));
// 转成二维数组:[[name,url], [name,url], ...]
$arrPlayUrl = array_chunk($arrPlayUrl, 2); $arrPlayUrl = array_chunk($arrPlayUrl, 2);
foreach ($arrPlayUrl as $intKey => $arrVal) { // 最终结构
$arrPlayUrl[$intKey] = [ $cleanPlayUrl = [];
'name' => $arrVal[0], foreach ($arrPlayUrl as $pair) {
'url' => $arrVal[1] ?? $arrVal[0], $name = $pair[0] ?? '';
$url = $pair[1] ?? '';
// *** 过滤掉不是 m3u8 的链接 ***
if (!str_ends_with($url, '.m3u8')) {
continue;
}
$cleanPlayUrl[] = [
'name' => $name,
'url' => $url,
]; ];
} }
$arrPlayUrl = $cleanPlayUrl;
$arrVideo['vod_actor'] = trim($arrVideo['vod_actor']); $arrVideo['vod_actor'] = trim($arrVideo['vod_actor']);
$arrVideo['vod_director'] = trim($arrVideo['vod_director']); $arrVideo['vod_director'] = trim($arrVideo['vod_director']);
@@ -170,15 +213,44 @@ class VideoInfoPage extends BasePage
$arrExistsVideo = (array) $arrExistsVideo; $arrExistsVideo = (array) $arrExistsVideo;
// 数据库里的旧播放源
$oldPlayUrl = $arrExistsVideo['v_play_url'] ?? [];
// 本次抓取的新播放源(可能不完整)
$newPagePlayUrl = $arrPageVideo['v_play_url'] ?? [];
// 合并新老线路(新覆盖旧)
$mergedPlayUrl = array_merge($oldPlayUrl, $newPagePlayUrl);
// 构造一个重新排序的结构
$sortedPlayUrl = [];
// 默认线路
$strDefaultLine = config("video.default_line");
// 1. maotai 优先
if (!empty($mergedPlayUrl[$strDefaultLine])) {
$sortedPlayUrl[$strDefaultLine] = $mergedPlayUrl[$strDefaultLine];
}
// 2. 其他线路顺序不变
foreach ($mergedPlayUrl as $source => $value) {
if ($source !== $strDefaultLine) {
$sortedPlayUrl[$source] = $value;
}
}
// 更新数据
$arrUpdate = [ $arrUpdate = [
'updated_at' => new \MongoDB\BSON\UTCDateTime(), 'updated_at' => new \MongoDB\BSON\UTCDateTime(),
'v_play_url.fengchao' => $arrPageVideo['v_play_url']['fengchao'], 'v_play_url' => $sortedPlayUrl,
]; ];
$this->getVideoModel()->updateOne( $this->getVideoModel()->updateOne(
['v_name' => $arrPageVideo['v_name']], ['v_name' => $arrPageVideo['v_name']],
['$set' => $arrUpdate], ['$set' => $arrUpdate]
); );
$this->strPicLocalPath = $arrExistsVideo['v_pic']; $this->strPicLocalPath = $arrExistsVideo['v_pic'];
} else { } else {

View File

@@ -113,7 +113,9 @@ class Scheduler
$intTotalPage = $arrCategory['total_page']; $intTotalPage = $arrCategory['total_page'];
// $intTotalPage = 2 ; // test if(config("video.task_test")){
$intTotalPage = 2 ; // test
}
$arrFilter = []; $arrFilter = [];
for ($intStartPage = 1; $intStartPage <= $intTotalPage; $intStartPage++) { for ($intStartPage = 1; $intStartPage <= $intTotalPage; $intStartPage++) {

View File

@@ -66,25 +66,69 @@ class VideoInfoPage extends BasePage
{ {
if (empty($this->arrVideo)) { 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 = json_decode($this->getContent(), true);
$arrVideo = $arrVideo['list'][0]; $arrVideo = $arrVideo['list'][0] ?? [];
// print_r($arrVideo); // 如果结构不正确 → 返回空数组
if (!$arrVideo) {
$strPlayUrl = $arrVideo['vod_play_url']; return [];
}
// 2. 检查播放地址
$strPlayUrl = $arrVideo['vod_play_url'] ?? null;
// 2. 判断是否有播放地址
if (empty($arrVideo['vod_play_url'])) {
// 无播放地址 → 丢弃该数据
return [];
}
unset($arrVideo['vod_play_url']); unset($arrVideo['vod_play_url']);
// 替换分隔符
$arrPlayUrl = str_replace('#', '$', $strPlayUrl); $arrPlayUrl = str_replace('#', '$', $strPlayUrl);
// 拆成数组
$arrPlayUrl = explode('$', $arrPlayUrl); $arrPlayUrl = explode('$', $arrPlayUrl);
// 清理空值
$arrPlayUrl = array_filter($arrPlayUrl); $arrPlayUrl = array_filter(array_map('trim', $arrPlayUrl));
// 转成二维数组:[[name,url], [name,url], ...]
$arrPlayUrl = array_chunk($arrPlayUrl, 2); $arrPlayUrl = array_chunk($arrPlayUrl, 2);
foreach ($arrPlayUrl as $intKey => $arrVal) { // 最终结构
$arrPlayUrl[$intKey] = [ $cleanPlayUrl = [];
'name' => $arrVal[0], foreach ($arrPlayUrl as $pair) {
'url' => $arrVal[1] ?? $arrVal[0], $name = $pair[0] ?? '';
$url = $pair[1] ?? '';
// *** 过滤掉不是 m3u8 的链接 ***
if (!str_ends_with($url, '.m3u8')) {
continue;
}
$cleanPlayUrl[] = [
'name' => $name,
'url' => $url,
]; ];
} }
$arrPlayUrl = $cleanPlayUrl;
$arrVideo['vod_actor'] = trim($arrVideo['vod_actor']); $arrVideo['vod_actor'] = trim($arrVideo['vod_actor']);
$arrVideo['vod_director'] = trim($arrVideo['vod_director']); $arrVideo['vod_director'] = trim($arrVideo['vod_director']);
@@ -171,18 +215,62 @@ class VideoInfoPage extends BasePage
if ($arrExistsVideo) { if ($arrExistsVideo) {
// $arrExistsVideo = (array) $arrExistsVideo;
// $arrUpdate = [
// 'updated_at' => new \MongoDB\BSON\UTCDateTime(),
// 'v_play_url.maotai' => $arrPageVideo['v_play_url']['maotai'],
// ];
// $this->getVideoModel()->updateOne(
// ['v_name' => $arrPageVideo['v_name']],
// ['$set' => $arrUpdate],
// );
// $this->strPicLocalPath = $arrExistsVideo['v_pic'];
$arrExistsVideo = (array) $arrExistsVideo; $arrExistsVideo = (array) $arrExistsVideo;
// 数据库里的旧播放源
$oldPlayUrl = $arrExistsVideo['v_play_url'] ?? [];
// 本次抓取的新播放源(可能不完整)
$newPagePlayUrl = $arrPageVideo['v_play_url'] ?? [];
// 合并新老线路(新覆盖旧)
$mergedPlayUrl = array_merge($oldPlayUrl, $newPagePlayUrl);
// 构造一个重新排序的结构
$sortedPlayUrl = [];
// 默认线路
$strDefaultLine = config("video.default_line");
// 1. maotai 优先
if (!empty($mergedPlayUrl[$strDefaultLine])) {
$sortedPlayUrl[$strDefaultLine] = $mergedPlayUrl[$strDefaultLine];
}
// 2. 其他线路顺序不变
foreach ($mergedPlayUrl as $source => $value) {
if ($source !== $strDefaultLine) {
$sortedPlayUrl[$source] = $value;
}
}
// 更新数据
$arrUpdate = [ $arrUpdate = [
'updated_at' => new \MongoDB\BSON\UTCDateTime(), 'updated_at' => new \MongoDB\BSON\UTCDateTime(),
'v_play_url.maotai' => $arrPageVideo['v_play_url']['maotai'], 'v_play_url' => $sortedPlayUrl,
]; ];
$this->getVideoModel()->updateOne( $this->getVideoModel()->updateOne(
['v_name' => $arrPageVideo['v_name']], ['v_name' => $arrPageVideo['v_name']],
['$set' => $arrUpdate], ['$set' => $arrUpdate]
); );
$this->strPicLocalPath = $arrExistsVideo['v_pic']; $this->strPicLocalPath = $arrExistsVideo['v_pic'];
} else { } else {
$arrInsertVideo = [ $arrInsertVideo = [

View File

@@ -67,22 +67,65 @@ class VideoInfoPage extends BasePage
{ {
if (empty($this->arrVideo)) { 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_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 = json_decode($this->getContent(), true);
$arrVideo = $arrVideo['list'][0]; $arrVideo = $arrVideo['list'][0] ?? [];
// print_r($arrVideo); // 如果结构不正确 → 返回空数组
if (!$arrVideo) {
$strPlayUrl = $arrVideo['vod_play_url']; return [];
}
// 2. 检查播放地址
$strPlayUrl = $arrVideo['vod_play_url'] ?? null;
// 2. 判断是否有播放地址
if (empty($arrVideo['vod_play_url'])) {
// 无播放地址 → 丢弃该数据
return [];
}
unset($arrVideo['vod_play_url']); unset($arrVideo['vod_play_url']);
// 替换分隔符
$arrPlayUrl = str_replace('#', '$', $strPlayUrl); $arrPlayUrl = str_replace('#', '$', $strPlayUrl);
// 拆成数组
$arrPlayUrl = explode('$', $arrPlayUrl); $arrPlayUrl = explode('$', $arrPlayUrl);
// 清理空值
$arrPlayUrl = array_filter(array_map('trim', $arrPlayUrl));
// 转成二维数组:[[name,url], [name,url], ...]
$arrPlayUrl = array_chunk($arrPlayUrl, 2); $arrPlayUrl = array_chunk($arrPlayUrl, 2);
foreach ($arrPlayUrl as $intKey => $arrVal) { // 最终结构
$arrPlayUrl[$intKey] = [ $cleanPlayUrl = [];
'name' => $arrVal[0], foreach ($arrPlayUrl as $pair) {
'url' => $arrVal[1] ?? $arrVal[0], $name = $pair[0] ?? '';
$url = $pair[1] ?? '';
// *** 过滤掉不是 m3u8 的链接 ***
if (!str_ends_with($url, '.m3u8')) {
continue;
}
$cleanPlayUrl[] = [
'name' => $name,
'url' => $url,
]; ];
} }
$arrPlayUrl = $cleanPlayUrl;
$arrVideo['vod_actor'] = trim($arrVideo['vod_actor']); $arrVideo['vod_actor'] = trim($arrVideo['vod_actor']);
$arrVideo['vod_director'] = trim($arrVideo['vod_director']); $arrVideo['vod_director'] = trim($arrVideo['vod_director']);
@@ -176,15 +219,44 @@ class VideoInfoPage extends BasePage
$arrExistsVideo = (array) $arrExistsVideo; $arrExistsVideo = (array) $arrExistsVideo;
// 数据库里的旧播放源
$oldPlayUrl = $arrExistsVideo['v_play_url'] ?? [];
// 本次抓取的新播放源(可能不完整)
$newPagePlayUrl = $arrPageVideo['v_play_url'] ?? [];
// 合并新老线路(新覆盖旧)
$mergedPlayUrl = array_merge($oldPlayUrl, $newPagePlayUrl);
// 构造一个重新排序的结构
$sortedPlayUrl = [];
// 默认线路
$strDefaultLine = config("video.default_line");
// 1. maotai 优先
if (!empty($mergedPlayUrl[$strDefaultLine])) {
$sortedPlayUrl[$strDefaultLine] = $mergedPlayUrl[$strDefaultLine];
}
// 2. 其他线路顺序不变
foreach ($mergedPlayUrl as $source => $value) {
if ($source !== $strDefaultLine) {
$sortedPlayUrl[$source] = $value;
}
}
// 更新数据
$arrUpdate = [ $arrUpdate = [
'updated_at' => new \MongoDB\BSON\UTCDateTime(), 'updated_at' => new \MongoDB\BSON\UTCDateTime(),
'v_play_url.wuxian' => $arrPageVideo['v_play_url']['wuxian'], 'v_play_url' => $sortedPlayUrl,
]; ];
$this->getVideoModel()->updateOne( $this->getVideoModel()->updateOne(
['v_name' => $arrPageVideo['v_name']], ['v_name' => $arrPageVideo['v_name']],
['$set' => $arrUpdate], ['$set' => $arrUpdate]
); );
$this->strPicLocalPath = $arrExistsVideo['v_pic']; $this->strPicLocalPath = $arrExistsVideo['v_pic'];
} else { } else {

View File

@@ -67,23 +67,65 @@ class VideoInfoPage extends BasePage
{ {
if (empty($this->arrVideo)) { 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_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 = json_decode($this->getContent(), true);
$arrVideo = $arrVideo['list'][0]; $arrVideo = $arrVideo['list'][0] ?? [];
// 如果结构不正确 → 返回空数组
// print_r($arrVideo); if (!$arrVideo) {
return [];
$strPlayUrl = $arrVideo['vod_play_url']; }
// 2. 检查播放地址
$strPlayUrl = $arrVideo['vod_play_url'] ?? null;
// 2. 判断是否有播放地址
if (empty($arrVideo['vod_play_url'])) {
// 无播放地址 → 丢弃该数据
return [];
}
unset($arrVideo['vod_play_url']); unset($arrVideo['vod_play_url']);
// 替换分隔符
$arrPlayUrl = str_replace('#', '$', $strPlayUrl); $arrPlayUrl = str_replace('#', '$', $strPlayUrl);
// 拆成数组
$arrPlayUrl = explode('$', $arrPlayUrl); $arrPlayUrl = explode('$', $arrPlayUrl);
// 清理空值
$arrPlayUrl = array_filter(array_map('trim', $arrPlayUrl));
// 转成二维数组:[[name,url], [name,url], ...]
$arrPlayUrl = array_chunk($arrPlayUrl, 2); $arrPlayUrl = array_chunk($arrPlayUrl, 2);
foreach ($arrPlayUrl as $intKey => $arrVal) { // 最终结构
$arrPlayUrl[$intKey] = [ $cleanPlayUrl = [];
'name' => $arrVal[0], foreach ($arrPlayUrl as $pair) {
'url' => $arrVal[1] ?? $arrVal[0], $name = $pair[0] ?? '';
$url = $pair[1] ?? '';
// *** 过滤掉不是 m3u8 的链接 ***
if (!str_ends_with($url, '.m3u8')) {
continue;
}
$cleanPlayUrl[] = [
'name' => $name,
'url' => $url,
]; ];
} }
$arrPlayUrl = $cleanPlayUrl;
$arrVideo['type_id_1'] = VideoCategory::$arrParent[$arrVideo['type_id']]; $arrVideo['type_id_1'] = VideoCategory::$arrParent[$arrVideo['type_id']];
@@ -174,15 +216,44 @@ class VideoInfoPage extends BasePage
$arrExistsVideo = (array) $arrExistsVideo; $arrExistsVideo = (array) $arrExistsVideo;
// 数据库里的旧播放源
$oldPlayUrl = $arrExistsVideo['v_play_url'] ?? [];
// 本次抓取的新播放源(可能不完整)
$newPagePlayUrl = $arrPageVideo['v_play_url'] ?? [];
// 合并新老线路(新覆盖旧)
$mergedPlayUrl = array_merge($oldPlayUrl, $newPagePlayUrl);
// 构造一个重新排序的结构
$sortedPlayUrl = [];
// 默认线路
$strDefaultLine = config("video.default_line");
// 1. maotai 优先
if (!empty($mergedPlayUrl[$strDefaultLine])) {
$sortedPlayUrl[$strDefaultLine] = $mergedPlayUrl[$strDefaultLine];
}
// 2. 其他线路顺序不变
foreach ($mergedPlayUrl as $source => $value) {
if ($source !== $strDefaultLine) {
$sortedPlayUrl[$source] = $value;
}
}
// 更新数据
$arrUpdate = [ $arrUpdate = [
'updated_at' => new \MongoDB\BSON\UTCDateTime(), 'updated_at' => new \MongoDB\BSON\UTCDateTime(),
'v_play_url.youzhi' => $arrPageVideo['v_play_url']['youzhi'], 'v_play_url' => $sortedPlayUrl,
]; ];
$this->getVideoModel()->updateOne( $this->getVideoModel()->updateOne(
['v_name' => $arrPageVideo['v_name']], ['v_name' => $arrPageVideo['v_name']],
['$set' => $arrUpdate], ['$set' => $arrUpdate]
); );
$this->strPicLocalPath = $arrExistsVideo['v_pic']; $this->strPicLocalPath = $arrExistsVideo['v_pic'];
} else { } else {

11
code/config/video.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
return [
// 默认播放线路
'default_line' => env('DEFAULT_LINE', 'douban'),
// 是否测试任务
'task_test' => env('TASK_TEST', false),
];

View File

@@ -1,4 +1,3 @@
// import { storageObj } from '../huiyuan/public/localstorage.js';
// 无限的 debugger 兼容性好 // 无限的 debugger 兼容性好
// setInterval(function () { // setInterval(function () {
// debuggerCheck(); // debuggerCheck();
@@ -503,15 +502,15 @@ function initDPlayer(strPlayUrl) {
} }
function findFirstUrl(obj) { function findFirstUrl(obj) {
// 优先取 douban // 优先取 默认
if (Array.isArray(obj?.douban) && obj.douban.length > 0 && obj.douban[0].url) { // if (Array.isArray(obj?.douban) && obj.douban.length > 0 && obj.douban[0].url) {
return obj.douban[0].url; // return obj.douban[0].url;
} // }
// 如果没有 douban尝试取对象中第一个数组的第一个 url // 如果没有 douban尝试取对象中第一个数组的第一个 url
for (const key in obj) { for (const key in obj) {
if (Array.isArray(obj[key]) && obj[key].length > 0 && obj[key][0].url) { if (Array.isArray(obj[key]) && obj[key].length > 0 && obj[key][0].url) {
return obj[key][0].url; return obj[key];
// return obj[key][0].url;
} }
} }
@@ -575,9 +574,9 @@ document.addEventListener("DOMContentLoaded", function () {
if (typeof strVideoId !== "undefined") { if (typeof strVideoId !== "undefined") {
if (typeof arrPlayUrl !== "undefined" && arrPlayUrl) { // if (typeof arrPlayUrl !== "undefined" && arrPlayUrl) {
arrPlayUrl = reorderObj(arrPlayUrl); // arrPlayUrl = reorderObj(arrPlayUrl);
} // }
// 使用示例 // 使用示例
const statsData = { const statsData = {
@@ -587,24 +586,57 @@ document.addEventListener("DOMContentLoaded", function () {
// 调用方法1 // 调用方法1
reportStats(statsData); reportStats(statsData);
// if (typeof strPlayType !== "undefined" && boolIsPlayPage) {
// if (strPlayType == 'default') {
// strPlayUrl = findFirstUrl(arrPlayUrl)
// checkLine('douban');
// } else {
// var ActivePlayUrl = arrPlayUrl[strPlayType][intPlayUrlIndex - 1]
// strPlayUrl = ActivePlayUrl.url
// checkLine(strPlayType);
// }
// initDPlayer(strPlayUrl)
// }else if(strPlayType == "default" && !boolIsPlayPage){
// checkLine('douban');
// }
if (typeof strPlayType !== "undefined" && boolIsPlayPage) { if (typeof strPlayType !== "undefined" && boolIsPlayPage) {
if (strPlayType == 'default') {
strPlayUrl = findFirstUrl(arrPlayUrl) // 用户指定线路
checkLine('douban'); if (strPlayType !== "default") {
} else { const activeUrl = arrPlayUrl[strPlayType][intPlayUrlIndex - 1];
var ActivePlayUrl = arrPlayUrl[strPlayType][intPlayUrlIndex - 1] strPlayUrl = activeUrl.url;
strPlayUrl = ActivePlayUrl.url
checkLine(strPlayType); checkLine(strPlayType);
// 默认播放第一个线路的第一个 URL
} else {
const defaultLine = getDefaultLine();
strPlayUrl = getFirstPlayUrl(defaultLine);
checkLine(defaultLine);
} }
initDPlayer(strPlayUrl)
}else if(strPlayType == "default" && !boolIsPlayPage){ initDPlayer(strPlayUrl);
checkLine('douban');
} else if (strPlayType == "default" && !boolIsPlayPage) {
const defaultLine = getDefaultLine();
checkLine(defaultLine);
} }
addHistoryFun(); addHistoryFun();
} }
// 获取第一个线路 key
function getDefaultLine() {
return Object.keys(arrPlayUrl)[0]; // 后端已经排序,第一位永远是默认线路
}
// 获取某个线路的第一个 url
function getFirstPlayUrl(playLine) {
return arrPlayUrl[playLine][0].url;
}
}) })

View File

@@ -48,6 +48,27 @@ db.video.find(
{ "v_play_url.douban": { $exists: true } } { "v_play_url.douban": { $exists: true } }
).limit(10) ).limit(10)
db.video.find(
{ "v_play_url.maotai": { $exists: true } }
).limit(10)
db.video.find(
{
"v_play_url.douban": { $exists: true },
"v_play_url.maotai": { $exists: true }
}
).limit(10)
db.video.find({
"v_play_url.maotai": { $exists: true },
$expr: {
$gt: [
{ $size: { $objectToArray: "$v_play_url" } },
1
]
}
})
// 删除某个资源线路的数据 // 删除某个资源线路的数据
db.video.updateMany( db.video.updateMany(
{}, {},