diff --git a/lib/DirScanner.php b/lib/DirScanner.php index b937420..14ee655 100644 --- a/lib/DirScanner.php +++ b/lib/DirScanner.php @@ -69,6 +69,12 @@ Class DirScanner { 'jpeg', //图片 ); + public $exiftoolSupported = false; + public $exiftoolSupportFileExtensions = array( + 'mp4', //视频 + 'mov', //视频 + ); + //暂未使用 /* protected $maxReadFilesize = array( //默认每种文件读取内容最大大小 @@ -323,6 +329,21 @@ Class DirScanner { if ($photo_create_time > 0) { $data['original_ctime'] = $photo_create_time; } + }else if ($this->exiftoolSupported && in_array($extension, $this->exiftoolSupportFileExtensions)) { + //try to exec command to get original create time of videos + try { + $output = shell_exec( sprintf("exiftool -createdate %s", escapeshellarg($realpath)) ); + + //output samples: + //Create Date : 2024:06:01 20:47:06 + //Create Date : 0000:00:00 00:00:00 + if (!empty($output) && strpos($output, ': 0000:') === false) { + $dateArr = explode(' : ', $output); + $data['original_ctime'] = strtotime($dateArr[1]); + } + }catch(Exception $e) { + //do nothing + } } return $data; diff --git a/themes/beauty/controller/CommandController.php b/themes/beauty/controller/CommandController.php index 902f239..35c8174 100644 --- a/themes/beauty/controller/CommandController.php +++ b/themes/beauty/controller/CommandController.php @@ -144,6 +144,7 @@ eof; //扫描媒体文件:图片、视频、音乐 //TODO: 把它们按年份、月份归类,并缓存到/runtime/cache/目录,方便前端展示读取 //把当前扫描进度保存到单独的缓存文件,便于用户随时获取 + //TODO: 没有original_ctime的视频文件调用exiftool获取拍摄时间 protected function scanMediaFiles($dirpath = '') { $rootDir = __DIR__ . '/../../../www/' . FSC::$app['config']['content_directory']; if (empty($dirpath)) { diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index cb681e0..a44e461 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -8,6 +8,8 @@ require_once __DIR__ . '/../../../plugins/Common.php'; require_once __DIR__ . '/../../../plugins/Html.php'; Class SiteController extends Controller { + protected $dateIndexCacheKey = 'MainBotDateIndex'; + protected $noOriginalCtimeFilesCacheKey = 'MainBotNoOriginalCtimeFiles'; public function actionIndex() { //获取数据 @@ -257,11 +259,16 @@ Class SiteController extends Controller { $isAdminIp = Common::isAdminIp($this->getUserIp()); //判断是否拥有管理权限 + + //从缓存文件获取按年份、月份归类的索引数据 + $cacheDataByDate = Common::getCache($this->dateIndexCacheKey); + $viewName = 'index'; $params = compact( 'page', 'pageSize', 'cacheDataId', 'showType', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme', 'mp3File', 'copyright', - 'alertWarning', 'isAdminIp', 'allFiles' + 'alertWarning', 'isAdminIp', 'allFiles', + 'cacheDataByDate' ); return $this->render($viewName, $params, $pageTitle); } diff --git a/themes/beauty/views/site/index.php b/themes/beauty/views/site/index.php index 3fa4d01..95cf964 100644 --- a/themes/beauty/views/site/index.php +++ b/themes/beauty/views/site/index.php @@ -58,6 +58,17 @@ $main_view_cls = $menu_ext_status == 'opened' ? '' : 'full';