Browse Source

show snapshot of first video file for video directories

master
filesite 4 months ago
parent
commit
e1764b6ac2
  1. 7
      lib/DirScanner.php
  2. 20
      themes/beauty/controller/SiteController.php

7
lib/DirScanner.php

@ -815,22 +815,19 @@ Class DirScanner {
RecursiveIteratorIterator::SELF_FIRST RecursiveIteratorIterator::SELF_FIRST
); );
$imgUrl = ''; $imgData = null;
foreach ($iterator as $item) { foreach ($iterator as $item) {
if ($item->isFile()) { if ($item->isFile()) {
$extension = $item->getExtension(); $extension = $item->getExtension();
if (in_array(strtolower($extension), $imgExts)) { if (in_array(strtolower($extension), $imgExts)) {
$imgPath = $item->getPath() . '/' . $item->getFilename(); $imgPath = $item->getPath() . '/' . $item->getFilename();
$imgData = $this->getFileData($imgPath); $imgData = $this->getFileData($imgPath);
if (!empty($imgData['path'])) {
$imgUrl = $imgData['path'];
}
break; break;
} }
} }
} }
return $imgUrl; return $imgData;
} }
} }

20
themes/beauty/controller/SiteController.php

@ -187,16 +187,28 @@ Class SiteController extends Controller {
$scanner->setRootDir($realpath); $scanner->setRootDir($realpath);
$imgExts = !empty(FSC::$app['config']['supportedImageExts']) ? FSC::$app['config']['supportedImageExts'] : array('jpg', 'jpeg', 'png', 'webp', 'gif'); $imgExts = !empty(FSC::$app['config']['supportedImageExts']) ? FSC::$app['config']['supportedImageExts'] : array('jpg', 'jpeg', 'png', 'webp', 'gif');
$url = $scanner->getSnapshotImage($realpath, $imgExts); $imgFile = $scanner->getSnapshotImage($realpath, $imgExts);
//支持视频目录 //支持视频目录
if (empty($url)) { if (empty($imgFile)) {
$videoExts = !empty(FSC::$app['config']['supportedVideoExts']) ? FSC::$app['config']['supportedVideoExts'] : array('mp4', 'mov', 'm3u8'); $videoExts = !empty(FSC::$app['config']['supportedVideoExts']) ? FSC::$app['config']['supportedVideoExts'] : array('mp4', 'mov', 'm3u8');
$firstVideoPath = $scanner->getSnapshotImage($realpath, $videoExts); $firstVideo = $scanner->getSnapshotImage($realpath, $videoExts);
if (!empty($firstVideoPath)) { if (!empty($firstVideo)) {
$url = '/img/beauty/video_dir.png'; $url = '/img/beauty/video_dir.png';
//尝试从缓存数据中获取封面图
$cacheKey = $firstVideo['id'];
$expireSeconds = 86400*30; //有效期30天
$cacheSubDir = 'video';
$cachedData = Common::getCacheFromFile($cacheKey, $expireSeconds, $cacheSubDir);
if (!empty($cachedData)) {
$url = $cachedData['snapshot'];
} }
} }
}else {
$url = $imgFile['path'];
}
}else { }else {
$code = 0; $code = 0;
$msg = '缓存数据已失效,请刷新网页'; $msg = '缓存数据已失效,请刷新网页';

Loading…
Cancel
Save