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

20
themes/beauty/controller/SiteController.php

@ -187,15 +187,27 @@ Class SiteController extends Controller { @@ -187,15 +187,27 @@ Class SiteController extends Controller {
$scanner->setRootDir($realpath);
$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');
$firstVideoPath = $scanner->getSnapshotImage($realpath, $videoExts);
if (!empty($firstVideoPath)) {
$firstVideo = $scanner->getSnapshotImage($realpath, $videoExts);
if (!empty($firstVideo)) {
$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 {
$code = 0;

Loading…
Cancel
Save