兼容茅台播放
This commit is contained in:
@@ -113,7 +113,9 @@ class Scheduler
|
||||
|
||||
|
||||
$intTotalPage = $arrCategory['total_page'];
|
||||
// $intTotalPage = 2 ; // test
|
||||
if(config("video.task_test")){
|
||||
$intTotalPage = 2 ; // test
|
||||
}
|
||||
$arrFilter = [];
|
||||
for ($intStartPage = 1; $intStartPage <= $intTotalPage; $intStartPage++) {
|
||||
|
||||
|
||||
@@ -66,25 +66,69 @@ 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];
|
||||
// print_r($arrVideo);
|
||||
|
||||
$strPlayUrl = $arrVideo['vod_play_url'];
|
||||
$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_filter(array_map('trim', $arrPlayUrl));
|
||||
// 转成二维数组:[[name,url], [name,url], ...]
|
||||
$arrPlayUrl = array_chunk($arrPlayUrl, 2);
|
||||
foreach ($arrPlayUrl as $intKey => $arrVal) {
|
||||
$arrPlayUrl[$intKey] = [
|
||||
'name' => $arrVal[0],
|
||||
'url' => $arrVal[1] ?? $arrVal[0],
|
||||
// 最终结构
|
||||
$cleanPlayUrl = [];
|
||||
foreach ($arrPlayUrl as $pair) {
|
||||
$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_director'] = trim($arrVideo['vod_director']);
|
||||
@@ -171,18 +215,62 @@ class VideoInfoPage extends BasePage
|
||||
|
||||
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;
|
||||
|
||||
// 数据库里的旧播放源
|
||||
$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 = [
|
||||
'updated_at' => new \MongoDB\BSON\UTCDateTime(),
|
||||
'v_play_url.maotai' => $arrPageVideo['v_play_url']['maotai'],
|
||||
'v_play_url' => $sortedPlayUrl,
|
||||
];
|
||||
|
||||
$this->getVideoModel()->updateOne(
|
||||
['v_name' => $arrPageVideo['v_name']],
|
||||
['$set' => $arrUpdate],
|
||||
['$set' => $arrUpdate]
|
||||
);
|
||||
|
||||
$this->strPicLocalPath = $arrExistsVideo['v_pic'];
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
$arrInsertVideo = [
|
||||
|
||||
Reference in New Issue
Block a user