Browse Source

auto play support list by date

master
filesite 20 hours ago
parent
commit
640a11bbe3
  1. 93
      themes/beauty/controller/ListController.php
  2. 14
      themes/beauty/controller/SiteController.php
  3. 20
      themes/beauty/views/list/bydate.php
  4. 4
      themes/beauty/views/site/index.php
  5. 7
      themes/beauty/views/site/player.php
  6. 10
      www/js/beauty.js

93
themes/beauty/controller/ListController.php

@ -281,7 +281,6 @@ Class ListController extends Controller { @@ -281,7 +281,6 @@ Class ListController extends Controller {
}
if (!empty($item['extension']) && in_array($item['extension'], $audioExts)) {
//print_r($subcate['files']);exit;
//为音乐文件获取封面图
if (empty($item['snapshot'])) {
$imgExts = !empty(FSC::$app['config']['supportedImageExts']) ? FSC::$app['config']['supportedImageExts'] : array('jpg', 'jpeg', 'png', 'webp', 'gif');
@ -422,6 +421,12 @@ Class ListController extends Controller { @@ -422,6 +421,12 @@ Class ListController extends Controller {
throw new Exception("索引数据已失效,请重新扫描所有文件以生成索引数据!", 404);
}
//把所有文件拼接到一个数组里
$allFiles = [];
foreach($cacheData as $month => $files) {
$allFiles = array_merge($allFiles, $files);
}
//其它数据获取
@ -498,6 +503,91 @@ Class ListController extends Controller { @@ -498,6 +503,91 @@ Class ListController extends Controller {
}
//dataType支持:[image, video, audio]
$dataType = $this->get('dataType', 'html');
if ($dataType == 'image' && !empty($allFiles)) {
$imgExts = !empty(FSC::$app['config']['supportedImageExts']) ? FSC::$app['config']['supportedImageExts'] : array('jpg', 'jpeg', 'png', 'webp', 'gif');
$imgs = array();
$pageStartIndex = ($page-1) * $pageSize;
$index = 0;
foreach ($allFiles as $id => $item) {
//翻页支持
if ($index < $pageStartIndex) {
$index ++;
continue;
}else if ($index >= $pageStartIndex + $pageSize) {
break;
}
//增加caption:图片、视频显示文件修改日期
$title = Common::getDateFromString($item['filename']);
if (empty($title) && !empty($item['fstat']['mtime']) && !empty($item['fstat']['ctime'])) {
$title = date('Y-m-d', min($item['fstat']['mtime'], $item['fstat']['ctime']));
}
$item['caption'] = "{$title} - {$item['filename']}";
if (!empty($item['extension']) && in_array($item['extension'], $imgExts)) {
array_push($imgs, $item);
$index ++;
}
}
return $this->renderJson(compact('page', 'pageSize', 'imgs'));
}else if ($dataType == 'video' && !empty($allFiles)) {
$videoExts = !empty(FSC::$app['config']['supportedVideoExts']) ? FSC::$app['config']['supportedVideoExts'] : array('mp4', 'mov', 'm3u8');
$videos = array();
$pageStartIndex = ($page-1) * $pageSize;
$index = 0;
foreach ($allFiles as $id => $item) {
//翻页支持
if ($index < $pageStartIndex) {
$index ++;
continue;
}else if ($index >= $pageStartIndex + $pageSize) {
break;
}
if (!empty($item['extension']) && in_array($item['extension'], $videoExts)) {
$item['videoType'] = Html::getMediaSourceType($item['extension']);
array_push($videos, $item);
$index ++;
}
}
return $this->renderJson(compact('page', 'pageSize', 'videos'));
}else if ($dataType == 'audio' && !empty($allFiles)) {
$audioExts = !empty(FSC::$app['config']['supportedAudioExts']) ? FSC::$app['config']['supportedAudioExts'] : array('mp3');
$audios = array();
$pageStartIndex = ($page-1) * $pageSize;
$index = 0;
foreach ($allFiles as $id => $item) {
//翻页支持
if ($index < $pageStartIndex) {
$index ++;
continue;
}else if ($index >= $pageStartIndex + $pageSize) {
break;
}
if (!empty($item['extension']) && in_array($item['extension'], $audioExts)) {
//为音乐文件获取封面图
if (empty($item['snapshot'])) {
$imgExts = !empty(FSC::$app['config']['supportedImageExts']) ? FSC::$app['config']['supportedImageExts'] : array('jpg', 'jpeg', 'png', 'webp', 'gif');
$matchedImage = Html::searchImageByFilename($item['filename'], $allFiles, $imgExts);
if (!empty($matchedImage)) {
$item['snapshot'] = $matchedImage['path'];
}else {
$item['snapshot'] = '/img/beauty/audio_icon.jpeg?v1';
}
}
array_push($audios, $item);
$index ++;
}
}
return $this->renderJson(compact('page', 'pageSize', 'audios'));
}
$pageTitlePrefix = "{$intYear}年的";
if (!empty($para_month)) {
$pageTitlePrefix = "{$intYear}年{$intMonth}月的";
@ -510,6 +600,7 @@ Class ListController extends Controller { @@ -510,6 +600,7 @@ Class ListController extends Controller {
'menus', 'breadcrumbs',
'htmlReadme', 'htmlCateReadme', 'copyright', 'mp3File', 'isAdminIp',
'page', 'pageSize', 'showType',
'allFiles',
'cacheData',
'cacheData_keys',
'para_year', 'para_month'

14
themes/beauty/controller/SiteController.php

@ -806,11 +806,16 @@ Class SiteController extends Controller { @@ -806,11 +806,16 @@ Class SiteController extends Controller {
public function actionPlayer() {
$videoUrl = $this->get('url', '');
$videoId = $this->get('id', '');
$videoName = $this->get('name', '');
$cateId = $this->get('pid', '');
$cacheParentDataId = $this->get('cid', '');
$page = $this->get('page', 1);
$pageSize = $this->get('limit', 100);
$page = $this->get('page', 0);
$pageSize = $this->get('limit', 10);
//增加按年、月查看视频自动播放更多视频支持
$para_year = $this->get('year', '');
$para_month = $this->get('month', '');
if (empty($videoUrl) || empty($videoId) || empty($cateId)) {
throw new Exception("缺少参数!", 403);
@ -834,8 +839,6 @@ Class SiteController extends Controller { @@ -834,8 +839,6 @@ Class SiteController extends Controller {
$m3u8 = $cachedParentData[$videoId];
$videoFilename = $m3u8['filename'] . '.m3u8';
}
}else {
//TODO: 从索引数据中获取
}
}
@ -860,7 +863,8 @@ Class SiteController extends Controller { @@ -860,7 +863,8 @@ Class SiteController extends Controller {
$params = compact(
'videoUrl', 'videoId', 'videoFilename',
'cateId', 'cacheParentDataId', 'page', 'pageSize',
'copyright', 'isAdminIp', 'videoExtension', 'videoSourceType'
'copyright', 'isAdminIp', 'videoExtension', 'videoSourceType',
'para_year', 'para_month', 'videoName'
);
return $this->render($viewName, $params, $pageTitle);
}

20
themes/beauty/views/list/bydate.php

@ -178,11 +178,7 @@ eof; @@ -178,11 +178,7 @@ eof;
//显示图片、视频、音乐
$allFiles = [];
foreach($cacheData as $month => $files) {
$allFiles = array_merge($allFiles, $files);
}
$allFiles = $viewData['allFiles'];
if(!empty($allFiles)) { //输出所有文件
$pageStartIndex = ($viewData['page']-1) * $viewData['pageSize'];
$index = 0;
@ -248,16 +244,16 @@ eof; @@ -248,16 +244,16 @@ eof;
</div>
eof;
}else if (in_array($file['extension'], $videoExts)) { //输出视频
//m3u8支持
if ($file['extension'] == 'm3u8') {
$videoUrl = urlencode("{$file['path']}");
}else {
$videoUrl = urlencode($file['path']);
}
$videoUrl = urlencode($file['path']);
$linkUrl = "/site/player?id={$file['id']}&pid={$file['pid']}&url={$videoUrl}";
if ($viewData['showType'] == 'video') {
$linkUrl .= "&page={$viewData['page']}&limit={$viewData['pageSize']}";
//支持按年、月查看视频时,获取更多视频以便自动播放
$linkUrl .= "&year={$viewData['para_year']}&month={$viewData['para_month']}";
}
if ($file['extension'] == 'm3u8') {
$linkUrl .= "&name=" . urlencode($file['filename']);
}
echo <<<eof

4
themes/beauty/views/site/index.php

@ -421,6 +421,10 @@ eof; @@ -421,6 +421,10 @@ eof;
$linkUrl .= "&page={$viewData['page']}&limit={$viewData['pageSize']}";
}
if ($file['extension'] == 'm3u8') {
$linkUrl .= "&name=" . urlencode($file['filename']);
}
echo <<<eof
<div class="im_item bor_radius col-xs-6 col-sm-4 col-md-3 col-lg-2">
<a href="{$linkUrl}" target="_blank" class="bor_radius" title="{$title} - {$file['filename']}">

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

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
<a class="navbar-brand" href="/">
<span class="verMiddle">正在播放</span>
</a>
<span class="navbar-text videotitle"><?php echo $viewData['videoFilename']; ?></span>
<span class="navbar-text videotitle"><?php echo !empty($viewData['videoName']) ? $viewData['videoName'] : $viewData['videoFilename']; ?></span>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
@ -57,7 +57,7 @@ @@ -57,7 +57,7 @@
</div>
</div>
</div>
<?php if (!empty($viewData['cacheParentDataId'])) { ?>
<?php if (!empty($viewData['cacheParentDataId']) || !empty($viewData['page'])) { ?>
<div class="col col-md-4 morevideos">
<hr class="visible-xs">
<div class="btn_autoplay text_dark">
@ -74,6 +74,9 @@ @@ -74,6 +74,9 @@
data-cid="<?php echo $viewData['cacheParentDataId']; ?>"
data-page="<?php echo $viewData['page']; ?>"
data-page-size="<?php echo $viewData['pageSize']; ?>"
data-api="<?php echo !empty($viewData['cacheParentDataId']) ? '/list/' : '/list/bydate/'; ?>"
data-year="<?php echo $viewData['para_year']; ?>"
data-month="<?php echo $viewData['para_month']; ?>"
class="othervideos"><div class="ml-1">...</div></div>
</div>
<?php } ?>

10
www/js/beauty.js

@ -746,7 +746,9 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { @@ -746,7 +746,9 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') {
var currentPage = $('.othervideos').attr('data-page'),
currentPageSize = $('.othervideos').attr('data-page-size'),
currentVideoId = $('.othervideos').attr('data-id'),
currentMediaType = $('.othervideos').attr('data-type');
currentMediaType = $('.othervideos').attr('data-type'),
currentYear = $('.othervideos').attr('data-year'),
currentMonth = $('.othervideos').attr('data-month');
if (!currentMediaType) {
currentMediaType = 'video';
}
@ -756,14 +758,16 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { @@ -756,14 +758,16 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') {
var videoId = $('.othervideos').attr('data-id'),
cateId = $('.othervideos').attr('data-pid'),
cacheId = $('.othervideos').attr('data-cid');
var api = '/list/',
var api = $('.othervideos').attr('data-api'),
params = {
id: cateId,
cid: cacheId,
show: currentMediaType,
dataType: currentMediaType,
page: currentPage,
limit: currentPageSize
limit: currentPageSize,
year: currentYear,
month: currentMonth
};
$.ajax({
url: api,

Loading…
Cancel
Save