Browse Source

add exiftool support

master
filesite 2 days ago
parent
commit
d447ffc59e
  1. 21
      lib/DirScanner.php
  2. 1
      themes/beauty/controller/CommandController.php
  3. 9
      themes/beauty/controller/SiteController.php
  4. 11
      themes/beauty/views/site/index.php

21
lib/DirScanner.php

@ -69,6 +69,12 @@ Class DirScanner { @@ -69,6 +69,12 @@ Class DirScanner {
'jpeg', //图片
);
public $exiftoolSupported = false;
public $exiftoolSupportFileExtensions = array(
'mp4', //视频
'mov', //视频
);
//暂未使用
/*
protected $maxReadFilesize = array( //默认每种文件读取内容最大大小
@ -323,6 +329,21 @@ Class DirScanner { @@ -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;

1
themes/beauty/controller/CommandController.php

@ -144,6 +144,7 @@ eof; @@ -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)) {

9
themes/beauty/controller/SiteController.php

@ -8,6 +8,8 @@ require_once __DIR__ . '/../../../plugins/Common.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 { @@ -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);
}

11
themes/beauty/views/site/index.php

@ -58,6 +58,17 @@ $main_view_cls = $menu_ext_status == 'opened' ? '' : 'full'; @@ -58,6 +58,17 @@ $main_view_cls = $menu_ext_status == 'opened' ? '' : 'full';
<!--侧边栏-->
<ul class="nav navbar-fixed-left <?=$menu_expand_icon_cls?>">
<li class="menu-title">按年月归类</li>
<?php
if (!empty($viewData['cacheDataByDate'])) {
print_r($viewData['cacheDataByDate']);
}else {
echo <<<eof
<li>还没有按年月归类的索引数据,点击马上生成</li>
eof;
}
?>
<li class="menu-title">目录</li>
<?php
$breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : [];

Loading…
Cancel
Save