From a66086577513629f6493aef402c4db4045d6eb3e Mon Sep 17 00:00:00 2001 From: filesite Date: Tue, 30 Jul 2024 08:25:14 +0800 Subject: [PATCH] show more videos in player page --- themes/beauty/controller/ListController.php | 4 +- themes/beauty/controller/SiteController.php | 13 +++- themes/beauty/views/site/index.php | 2 +- themes/beauty/views/site/player.php | 80 +++++++++++++++------ www/css/beauty.css | 2 +- www/js/beauty.js | 73 +++++++++++++++++++ 6 files changed, 148 insertions(+), 26 deletions(-) diff --git a/themes/beauty/controller/ListController.php b/themes/beauty/controller/ListController.php index 899b62f..f7bfd3a 100644 --- a/themes/beauty/controller/ListController.php +++ b/themes/beauty/controller/ListController.php @@ -32,8 +32,10 @@ Class ListController extends Controller { } $currentDir = $cachedParentData[$cateId]; - if (empty($currentDir)) { + if (strpos($cacheParentDataId, $cateId) === false && empty($currentDir)) { throw new Exception("缓存数据中找不到当前目录,请返回上一页重新进入!", 404); + }else if (strpos($cacheParentDataId, $cateId) !== false) { + $currentDir = $cachedParentData; } $scanner->setWebRoot($this->getCurrentWebroot($currentDir['realpath'])); diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index 6ce25d7..a2e3df9 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -427,8 +427,13 @@ Class SiteController extends Controller { public function actionPlayer() { $videoUrl = $this->get('url', ''); $videoId = $this->get('id', ''); - if (empty($videoUrl) || empty($videoId)) { - throw new Exception("缺少视频地址url或id参数!", 403); + + $cateId = $this->get('pid', ''); + $cacheParentDataId = $this->get('cid', ''); + $page = $this->get('page', 1); + + if (empty($videoUrl) || empty($videoId) || empty($cateId) || empty($cacheParentDataId)) { + throw new Exception("缺少参数!", 403); } $arr = parse_url($videoUrl); @@ -450,7 +455,9 @@ Class SiteController extends Controller { $this->layout = 'player'; $viewName = 'player'; $params = compact( - 'videoUrl', 'videoId', 'videoFilename', 'copyright' + 'videoUrl', 'videoId', 'videoFilename', + 'cateId', 'cacheParentDataId', 'page', + 'copyright' ); return $this->render($viewName, $params, $pageTitle); } diff --git a/themes/beauty/views/site/index.php b/themes/beauty/views/site/index.php index 1732ee1..5558383 100644 --- a/themes/beauty/views/site/index.php +++ b/themes/beauty/views/site/index.php @@ -320,7 +320,7 @@ eof; $videoUrl = urlencode($file['path']); echo << - + -
- -
- - - download icon - 下载视频 + +
+ +
+
+
+ 自动播放 +
+ + +
+
+ +
其它视频
+
+
+ + diff --git a/www/css/beauty.css b/www/css/beauty.css index d65bbe9..47ab6a6 100644 --- a/www/css/beauty.css +++ b/www/css/beauty.css @@ -25,7 +25,7 @@ a:visited{text-decoration:none} a:link{text-decoration:none} .lampshow{background-color:#222} -.main_style{padding-top:64px} +.main_style{padding-top:64px;overflow:hidden} .navbar-default { background-color:#FFF; } diff --git a/www/js/beauty.js b/www/js/beauty.js index 4dc3ad9..dbb80d3 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -603,6 +603,79 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { }); } +//加载更多视频 +if ($('.othervideos').length > 0) { + var videoId = $('.othervideos').attr('data-id'), + cateId = $('.othervideos').attr('data-pid'), + cacheId = $('.othervideos').attr('data-cid'), + currentPage = $('.othervideos').attr('data-page'); + var api = '/list/', + params = { + id: cateId, + cid: cacheId, + show: 'video', + dataType: 'video', + page: currentPage + }; + + var getVideoUrl = function(videoId, videoPath) { + var url = new URL(location.href); + var api = url.origin + url.pathname; + + var newParas = []; + for (var key of url.searchParams.keys()) { + if (key != 'id' && key != 'url' && key != 'other') { + newParas.push(key + '=' + url.searchParams.get(key)); + } + } + newParas.push('id=' + videoId); + newParas.push('url=' + encodeURIComponent(videoPath)); + + return api + '?other=1&' + newParas.join('&'); + }; + + var renderVideos = function(ignoreId, videos) { + var template = $('#template_video_item').html(), + html = '', tmp = ''; + + for (var index in videos) { + if (videos[index].id == ignoreId) {continue;} + tmp = template.replace('{videoUrl}', getVideoUrl(videos[index].id, videos[index].path)); + tmp = tmp.replaceAll('{title}', videos[index].filename); + tmp = tmp.replaceAll('{videoId}', videos[index].id); + tmp = tmp.replaceAll('{videoPath}', videos[index].path); + + html += tmp; + } + + return html; + }; + + $.ajax({ + url: api, + method: 'GET', + dataType: 'json', + data: params + }).done(function(data) { + //console.log('more videos', data); + if (typeof(data.videos) != 'undefined' && data.videos.length > 0) { + $('.othervideos').html(renderVideos(videoId, data.videos)); + setTimeout(function() { + $('.othervideos .video-poster').each(function(index, el) { + var videoId = $(el).attr('data-video-id'), + videoUrl = $(el).attr('data-video-url'); + getVideoMetaAndShowIt(videoId, videoUrl); + }); + }, 50); + }else { + //_noMoreData = true; + console.warn('获取更多视频数据出错啦', data.msg); + } + }).fail(function(jqXHR, textStatus, errorThrown) { + console.error('获取更多视频数据失败,错误信息:' + errorThrown); + }); +} + //目录收拢、展开 $('.btn-dir-ext').click(function(evt) {