feat(core): 添加PSD/PSB图片格式支持并重构媒体文件处理

- 新增ReadPsdImage函数支持PSD/PSB格式图片信息读取
- 修改文件扫描逻辑,将视频处理改为媒体候选处理,使用ffprobe统一判定
- 添加对PSB格式的支持,与PSD共享相同8BPS文件头处理
- 重构handle_image.go中的图片处理逻辑,优化错误处理和记录保存
- 更新文件扫描过滤规则,支持更多图片格式并跳过数据库文件
- 添加文件MD5计算功能用于文件唯一性标识
- 修改媒体处理流程,支持音频文件识别和分类处理
- 移除废弃的视频时长转换函数和相关依赖
- 更新依赖版本并添加SQLite支持用于媒体信息存储
This commit is contained in:
2025-03-18 21:04:15 +08:00
parent f5e3f6b4ef
commit b276e8c56f
16 changed files with 770 additions and 311 deletions
+27
View File
@@ -3,6 +3,7 @@ package core
import (
"encoding/binary"
"fmt"
"io"
"os"
)
@@ -85,3 +86,29 @@ func absInt32(v int32) int32 {
}
return v
}
// ReadPsdImage 读取PSD/PSB格式的图片信息(两者共享相同的8BPS文件头)
func ReadPsdImage(filePath string) (err error, width int, height int) {
file, err := os.Open(filePath)
if err != nil {
fmt.Printf("=== Failed to open file: %v\n", err)
return err, 0, 0
}
defer file.Close()
var header [26]byte
if _, err := io.ReadFull(file, header[:]); err != nil {
fmt.Printf("=== Failed to read PSD/PSB header: %v\n", err)
return err, 0, 0
}
if string(header[0:4]) != "8BPS" {
return fmt.Errorf("not a valid PSD/PSB file: magic %q, expected \"8BPS\"", string(header[0:4])), 0, 0
}
version := binary.BigEndian.Uint16(header[4:6])
if version != 1 && version != 2 {
return fmt.Errorf("unsupported PSD/PSB version: %d", version), 0, 0
}
height = int(binary.BigEndian.Uint32(header[14:18]))
width = int(binary.BigEndian.Uint32(header[18:22]))
return nil, width, height
}