|
|
@ -7,33 +7,37 @@ require_once __DIR__ . '/../../../plugins/Parsedown.php'; |
|
|
|
require_once __DIR__ . '/../../../plugins/Common.php'; |
|
|
|
require_once __DIR__ . '/../../../plugins/Common.php'; |
|
|
|
|
|
|
|
|
|
|
|
Class M3u8Controller extends Controller { |
|
|
|
Class M3u8Controller extends Controller { |
|
|
|
|
|
|
|
protected $allFilesCacheKey = 'MainBotAllFiles'; |
|
|
|
|
|
|
|
|
|
|
|
//参数 |
|
|
|
//参数 |
|
|
|
//@id - 文件id |
|
|
|
//@id - 文件id |
|
|
|
//@cid - 数据缓存id |
|
|
|
//@cid - 数据缓存id |
|
|
|
//支持nginx secure防盗链:md5={$md5}&expires={$expires} |
|
|
|
//支持nginx secure防盗链:md5={$md5}&expires={$expires} |
|
|
|
|
|
|
|
//支持只传video id,从索引数据中获取文件信息 |
|
|
|
public function actionIndex() { |
|
|
|
public function actionIndex() { |
|
|
|
$videoId = $this->get('id', ''); |
|
|
|
$videoId = $this->get('id', ''); |
|
|
|
$cacheParentDataId = $this->get('cid', ''); |
|
|
|
$cacheParentDataId = $this->get('cid', ''); |
|
|
|
if (empty($videoId) || empty($cacheParentDataId)) { |
|
|
|
if (empty($videoId)) { |
|
|
|
throw new Exception("参数缺失!", 403); |
|
|
|
throw new Exception("参数缺失!", 403); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//TODO: 防盗链检查 |
|
|
|
//TODO: 防盗链检查 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//渲染m3u8内容 |
|
|
|
if (!empty($cacheParentDataId)) { |
|
|
|
$cacheSeconds = 86400; |
|
|
|
$cacheSeconds = 86400; |
|
|
|
$cachedParentData = Common::getCacheFromFile($cacheParentDataId, $cacheSeconds); |
|
|
|
$cachedParentData = Common::getCacheFromFile($cacheParentDataId, $cacheSeconds); |
|
|
|
if (empty($cachedParentData)) { |
|
|
|
if (empty($cachedParentData)) { |
|
|
|
$err = '缓存数据已失效,如果重新点击目录依然打不开,请联系管理员。'; |
|
|
|
$err = '缓存数据已失效,如果重新点击目录依然打不开,请联系管理员。'; |
|
|
|
throw new Exception($err, 404); |
|
|
|
throw new Exception($err, 404); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (empty($cachedParentData[$videoId])) { |
|
|
|
if (!empty($cachedParentData) && empty($cachedParentData[$videoId])) { |
|
|
|
$erro = "缓存数据中找不到当前视频,请返回上一页重新进入!"; |
|
|
|
$erro = "缓存数据中找不到当前视频,请返回上一页重新进入!"; |
|
|
|
throw new Exception($err, 404); |
|
|
|
throw new Exception($err, 404); |
|
|
|
}else if (!empty($cachedParentData)) { |
|
|
|
}else if (!empty($cachedParentData[$videoId])) { |
|
|
|
|
|
|
|
//渲染m3u8内容 |
|
|
|
$m3u8 = $cachedParentData[$videoId]; |
|
|
|
$m3u8 = $cachedParentData[$videoId]; |
|
|
|
$m3u8Content = $this->getM3u8Content($m3u8['realpath'], $cachedParentData); |
|
|
|
$m3u8Content = $this->getM3u8Content($m3u8['realpath'], $cachedParentData); |
|
|
|
if (!empty($m3u8Content)) { |
|
|
|
if (!empty($m3u8Content)) { |
|
|
@ -42,6 +46,32 @@ Class M3u8Controller extends Controller { |
|
|
|
$err = 'm3u8内容为空!'; |
|
|
|
$err = 'm3u8内容为空!'; |
|
|
|
throw new Exception($err, 500); |
|
|
|
throw new Exception($err, 500); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}else { //尝试从索引数据中获取文件信息 |
|
|
|
|
|
|
|
$expireSeconds = 86400 * 365; //缓存 365 天 |
|
|
|
|
|
|
|
$cacheData = Common::getCacheFromFile($this->allFilesCacheKey . '_stats', $expireSeconds); |
|
|
|
|
|
|
|
if (!empty($cacheData)) { |
|
|
|
|
|
|
|
$dirNum = $cacheData['dirnum']; |
|
|
|
|
|
|
|
$index = Common::getIndexNumByFileId($videoId, $dirNum) + 1; |
|
|
|
|
|
|
|
$cacheKey = $this->allFilesCacheKey . "_{$index}"; |
|
|
|
|
|
|
|
$cacheFiles = Common::getCacheFromFile($cacheKey, $expireSeconds); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($cacheFiles[$videoId])) { |
|
|
|
|
|
|
|
$m3u8 = $cacheFiles[$videoId]; |
|
|
|
|
|
|
|
$m3u8Content = $this->getM3u8Content($m3u8['realpath']); |
|
|
|
|
|
|
|
if (!empty($m3u8Content)) { |
|
|
|
|
|
|
|
return $this->renderM3u8($m3u8Content); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
$err = 'm3u8内容为空!'; |
|
|
|
|
|
|
|
throw new Exception($err, 500); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
$err = '索引数据中找不到此视频!'; |
|
|
|
|
|
|
|
throw new Exception($err, 500); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
$err = '没有索引数据,请参考文档生成索引!'; |
|
|
|
|
|
|
|
throw new Exception($err, 500); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|