Browse Source

m3u8 play support no cid parameter

master
filesite 1 day ago
parent
commit
7c953e1314
  1. 19
      themes/beauty/controller/M3u8Controller.php
  2. 20
      themes/beauty/controller/SiteController.php
  3. 2
      themes/beauty/views/site/player.php
  4. 4
      www/js/beauty.js

19
themes/beauty/controller/M3u8Controller.php

@ -47,13 +47,14 @@ Class M3u8Controller extends Controller { @@ -47,13 +47,14 @@ Class M3u8Controller extends Controller {
throw new Exception($err, 500);
}
}else { //尝试从索引数据中获取文件信息
$cacheDir = 'index';
$expireSeconds = 86400 * 365; //缓存 365 天
$cacheData = Common::getCacheFromFile($this->allFilesCacheKey . '_stats', $expireSeconds);
$cacheData = Common::getCacheFromFile($this->allFilesCacheKey . '_stats', $expireSeconds, $cacheDir);
if (!empty($cacheData)) {
$dirNum = $cacheData['dirnum'];
$index = Common::getIndexNumByFileId($videoId, $dirNum) + 1;
$cacheKey = $this->allFilesCacheKey . "_{$index}";
$cacheFiles = Common::getCacheFromFile($cacheKey, $expireSeconds);
$cacheFiles = Common::getCacheFromFile($cacheKey, $expireSeconds, $cacheDir);
if (!empty($cacheFiles[$videoId])) {
$m3u8 = $cacheFiles[$videoId];
@ -130,17 +131,15 @@ Class M3u8Controller extends Controller { @@ -130,17 +131,15 @@ Class M3u8Controller extends Controller {
if (!empty($matchedTs)) {
return $matchedTs['path'];
}else {
$webroot = FSC::$app['config']['content_directory'];
$rootDir = __DIR__ . '/../../../www/' . $webroot;
$rootDir = realpath($rootDir);
$m3u8Dir = dirname($m3u8_realpath);
$relativeDir = str_replace("{$rootDir}/", '', $m3u8Dir);
return "/{$webroot}{$relativeDir}/{$ts_filename}";
}
}
return dirname($m3u8_realpath) . "/{$ts_filename}";
$webroot = FSC::$app['config']['content_directory'];
$rootDir = __DIR__ . '/../../../www/' . $webroot;
$rootDir = realpath($rootDir);
$m3u8Dir = dirname($m3u8_realpath);
$relativeDir = str_replace("{$rootDir}/", '', $m3u8Dir);
return "/{$webroot}{$relativeDir}/{$ts_filename}";
}
}

20
themes/beauty/controller/SiteController.php

@ -9,6 +9,7 @@ require_once __DIR__ . '/../../../plugins/Html.php'; @@ -9,6 +9,7 @@ require_once __DIR__ . '/../../../plugins/Html.php';
Class SiteController extends Controller {
protected $dateIndexCacheKey = 'MainBotDateIndex'; //索引数据的key单独缓存,缓存key为此{cacheKey}_keys
protected $allFilesCacheKey = 'MainBotAllFiles';
protected $noOriginalCtimeFilesCacheKey = 'MainBotNoOriginalCtimeFiles';
public function actionIndex() {
@ -811,7 +812,6 @@ Class SiteController extends Controller { @@ -811,7 +812,6 @@ Class SiteController extends Controller {
$page = $this->get('page', 1);
$pageSize = $this->get('limit', 100);
// || empty($cacheParentDataId)
if (empty($videoUrl) || empty($videoId) || empty($cateId)) {
throw new Exception("缺少参数!", 403);
}
@ -819,19 +819,23 @@ Class SiteController extends Controller { @@ -819,19 +819,23 @@ Class SiteController extends Controller {
$arr = parse_url($videoUrl);
$videoFilename = basename($arr['path']);
//增加文件后缀格式检查,区分:mp4, mov, m3u8
//增加文件后缀格式检查,区分:mp4, mov
$videoExtension = pathinfo($arr['path'], PATHINFO_EXTENSION);
//支持m3u8地址:/m3u8/?id=xxx
if ($videoFilename == 'm3u8' && !empty($cacheParentDataId)) {
if ($videoFilename == 'm3u8') {
$videoExtension = 'm3u8';
//从缓存数据获取文件名
$cacheSeconds = 86400;
$cachedParentData = Common::getCacheFromFile($cacheParentDataId, $cacheSeconds);
if (!empty($cachedParentData)) {
$m3u8 = $cachedParentData[$videoId];
$videoFilename = $m3u8['filename'] . '.m3u8';
if (!empty($cacheParentDataId)) {
$cacheSeconds = 86400;
$cachedParentData = Common::getCacheFromFile($cacheParentDataId, $cacheSeconds);
if (!empty($cachedParentData)) {
$m3u8 = $cachedParentData[$videoId];
$videoFilename = $m3u8['filename'] . '.m3u8';
}
}else {
//TODO: 从索引数据中获取
}
}

2
themes/beauty/views/site/player.php

@ -57,6 +57,7 @@ @@ -57,6 +57,7 @@
</div>
</div>
</div>
<?php if (!empty($viewData['cacheParentDataId'])) { ?>
<div class="col col-md-4 morevideos">
<hr class="visible-xs">
<div class="btn_autoplay text_dark">
@ -75,6 +76,7 @@ @@ -75,6 +76,7 @@
data-page-size="<?php echo $viewData['pageSize']; ?>"
class="othervideos"><div class="ml-1">...</div></div>
</div>
<?php } ?>
</div>
<script type="text/template" id="template_video_item">

4
www/js/beauty.js

@ -813,7 +813,9 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { @@ -813,7 +813,9 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') {
});
};
getOtherVideos();
if ($('.othervideos').length > 0) {
getOtherVideos();
}
//自动播放
var playNextVideo = function() {

Loading…
Cancel
Save