From 792ef44871acd4b46a6c595c57052ff6a31e19e3 Mon Sep 17 00:00:00 2001 From: filesite Date: Wed, 17 Jul 2024 00:52:36 +0800 Subject: [PATCH] improve manual screenshot create --- themes/beauty/controller/SiteController.php | 17 +++++++++-- www/js/beauty.js | 31 +++++++++++++++------ 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index ac50ebf..7d61c34 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -283,20 +283,33 @@ Class SiteController extends Controller { return $this->renderJson(compact('code', 'msg', 'meta')); } - //保存视频meta数据到缓存 + //保存视频meta数据到缓存,支持手动生成 public function actionSavevideometa() { $code = 0; $msg = 'OK'; $videoId = $this->post('id', ''); $metaData = $this->post('meta', ''); + $manual = $this->post('manual', 0); if (empty($videoId) || empty($metaData)) { $code = 0; $msg = '参数不能为空'; }else { $cacheKey = $this->getCacheKey($videoId, 'vmeta'); $cacheSubDir = 'video'; - $saved = Common::saveCacheToFile($cacheKey, $metaData, $cacheSubDir); + $saved = true; + + if (!empty($manual)) { + $metaData['manual'] = 1; + $saved = Common::saveCacheToFile($cacheKey, $metaData, $cacheSubDir); + }else { + $expireSeconds = 86400*30; //有效期30天 + $cachedData = Common::getCacheFromFile($cacheKey, $expireSeconds, $cacheSubDir); + if (empty($cachedData) || empty($cachedData['manual'])) { + $saved = Common::saveCacheToFile($cacheKey, $metaData, $cacheSubDir); + } + } + if ($saved !== false) { $code = 1; } diff --git a/www/js/beauty.js b/www/js/beauty.js index d511d72..01f7c78 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -304,15 +304,20 @@ $('.video-poster').each(function(index, el) { }); //保存视频数据 -var saveVideoMeta = function(videoId, metaData) { +var saveVideoMeta = function(videoId, metaData, manual) { + var params = { + id: videoId, + meta: metaData + }; + if (typeof(manual) != 'undefined' && manual) { + params.manual = 1; + } + $.ajax({ url: '/site/savevideometa', method: 'POST', dataType: 'json', - data: { - id: videoId, - meta: metaData - } + data: params }).done(function(data) { if (data.code != 1) { console.warn('视频数据保存失败', data.msg); @@ -331,7 +336,7 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { preload: 'auto' }); - var takeScreenshot = function() { + var takeScreenshot = function(manual) { //myPlayer.pause(); var height = myPlayer.videoHeight(), width = myPlayer.videoWidth(), @@ -351,7 +356,7 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { saveVideoMeta($('video.vjs-tech').attr('data-id'), { duration: duration, snapshot: snapshotImg - }); + }, manual); } //myPlayer.play(); @@ -371,7 +376,15 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { setTimeout(takeScreenshot, screenshot_start); }); - $('.btn-snapshot').click(function() { - takeScreenshot(); + $('.btn-snapshot').click(function(e) { + var clickedBtn = $(e.target); + clickedBtn.prop('disabled', true); + + var manual = 1; + takeScreenshot(manual); + + setTimeout(function() { + clickedBtn.prop('disabled', false); + }, 3000); }); } \ No newline at end of file