diff --git a/themes/beauty/controller/ListController.php b/themes/beauty/controller/ListController.php index 0bc231a..dc188f6 100644 --- a/themes/beauty/controller/ListController.php +++ b/themes/beauty/controller/ListController.php @@ -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 { throw new Exception("索引数据已失效,请重新扫描所有文件以生成索引数据!", 404); } + //把所有文件拼接到一个数组里 + $allFiles = []; + foreach($cacheData as $month => $files) { + $allFiles = array_merge($allFiles, $files); + } + //其它数据获取 @@ -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 { 'menus', 'breadcrumbs', 'htmlReadme', 'htmlCateReadme', 'copyright', 'mp3File', 'isAdminIp', 'page', 'pageSize', 'showType', + 'allFiles', 'cacheData', 'cacheData_keys', 'para_year', 'para_month' diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index 8a5bd07..5030cba 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -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 { $m3u8 = $cachedParentData[$videoId]; $videoFilename = $m3u8['filename'] . '.m3u8'; } - }else { - //TODO: 从索引数据中获取 } } @@ -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); } diff --git a/themes/beauty/views/list/bydate.php b/themes/beauty/views/list/bydate.php index 1085a77..04e834b 100644 --- a/themes/beauty/views/list/bydate.php +++ b/themes/beauty/views/list/bydate.php @@ -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; 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 << diff --git a/themes/beauty/views/site/player.php b/themes/beauty/views/site/player.php index cea3e4d..980e7d9 100644 --- a/themes/beauty/views/site/player.php +++ b/themes/beauty/views/site/player.php @@ -14,7 +14,7 @@ 正在播放 - + @@ -57,7 +57,7 @@ - +

@@ -74,6 +74,9 @@ data-cid="" data-page="" data-page-size="" + data-api="" + data-year="" + data-month="" class="othervideos">
...
diff --git a/www/js/beauty.js b/www/js/beauty.js index 7ee0003..2b46623 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -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') { 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,