feat(core): 添加PSD/PSB图片格式支持并重构媒体文件处理
- 新增ReadPsdImage函数支持PSD/PSB格式图片信息读取 - 修改文件扫描逻辑,将视频处理改为媒体候选处理,使用ffprobe统一判定 - 添加对PSB格式的支持,与PSD共享相同8BPS文件头处理 - 重构handle_image.go中的图片处理逻辑,优化错误处理和记录保存 - 更新文件扫描过滤规则,支持更多图片格式并跳过数据库文件 - 添加文件MD5计算功能用于文件唯一性标识 - 修改媒体处理流程,支持音频文件识别和分类处理 - 移除废弃的视频时长转换函数和相关依赖 - 更新依赖版本并添加SQLite支持用于媒体信息存储
This commit is contained in:
+44
-13
@@ -18,26 +18,15 @@ func DoHandleImage(pickerDir string) {
|
||||
ignoreCount := 0 // 忽略数
|
||||
for _, imageFilePath := range vars.GlobalImagePathList {
|
||||
suffix := vars.GlobalFilePath2FileExtMap[imageFilePath]
|
||||
if util.IsSupportImage(suffix) {
|
||||
err, width, height := util.ReadImageInfo(imageFilePath)
|
||||
if err == nil {
|
||||
successCount = successCount + 1
|
||||
vars.ImagePath2WidthHeightMap[imageFilePath] = fmt.Sprintf("%d-%d", width, height)
|
||||
fmt.Printf("=== Image总数: %d, 已读取Info: %d, 成功数: %d, 失败数: %d \n", total, successCount+errorCount+ignoreCount, successCount, errorCount)
|
||||
} else {
|
||||
errorCount = errorCount + 1
|
||||
vars.ImageReadErrorPathList = append(vars.ImageReadErrorPathList, imageFilePath)
|
||||
fmt.Printf("=== 异常图片: %s \n", imageFilePath)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(suffix, ".webp") { // 特殊文件处理, webp为网络常用图片格式
|
||||
webpErr, webpWidth, webpHeight := ReadWebpImage(imageFilePath)
|
||||
if webpErr == nil {
|
||||
vars.ImagePath2WidthHeightMap[imageFilePath] = fmt.Sprintf("%d-%d", webpWidth, webpHeight)
|
||||
saveMediaRecord(imageFilePath, "image", webpWidth, webpHeight, 0, "", "", "")
|
||||
successCount = successCount + 1
|
||||
} else {
|
||||
errorCount = errorCount + 1
|
||||
vars.ImageReadErrorPathList = append(vars.ImageReadErrorPathList, imageFilePath)
|
||||
fmt.Printf("=== 异常图片: %s \n", imageFilePath)
|
||||
}
|
||||
continue
|
||||
@@ -46,9 +35,11 @@ func DoHandleImage(pickerDir string) {
|
||||
bpmErr, bmpWidth, bmpHeight := ReadBmpImage(imageFilePath)
|
||||
if bpmErr == nil {
|
||||
vars.ImagePath2WidthHeightMap[imageFilePath] = fmt.Sprintf("%d-%d", bmpWidth, bmpHeight)
|
||||
saveMediaRecord(imageFilePath, "image", int(bmpWidth), int(bmpHeight), 0, "", "", "")
|
||||
successCount = successCount + 1
|
||||
} else {
|
||||
errorCount = errorCount + 1
|
||||
vars.ImageReadErrorPathList = append(vars.ImageReadErrorPathList, imageFilePath)
|
||||
fmt.Printf("=== 异常图片: %s \n", imageFilePath)
|
||||
}
|
||||
continue
|
||||
@@ -58,6 +49,46 @@ func DoHandleImage(pickerDir string) {
|
||||
successCount = successCount + 1
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(suffix, ".psb") { // 特殊文件处理, psb与psd共享文件头
|
||||
psbErr, psbWidth, psbHeight := ReadPsdImage(imageFilePath)
|
||||
if psbErr == nil {
|
||||
vars.ImagePath2WidthHeightMap[imageFilePath] = fmt.Sprintf("%d-%d", psbWidth, psbHeight)
|
||||
saveMediaRecord(imageFilePath, "image", psbWidth, psbHeight, 0, "", "", "")
|
||||
successCount = successCount + 1
|
||||
} else {
|
||||
errorCount = errorCount + 1
|
||||
vars.ImageReadErrorPathList = append(vars.ImageReadErrorPathList, imageFilePath)
|
||||
fmt.Printf("=== 异常图片: %s \n", imageFilePath)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if util.IsSupportImage(suffix) {
|
||||
err, width, height := util.ReadImageInfo(imageFilePath)
|
||||
if err == nil {
|
||||
successCount = successCount + 1
|
||||
vars.ImagePath2WidthHeightMap[imageFilePath] = fmt.Sprintf("%d-%d", width, height)
|
||||
saveMediaRecord(imageFilePath, "image", width, height, 0, "", "", "")
|
||||
fmt.Printf("=== Image总数: %d, 已读取Info: %d, 成功数: %d, 失败数: %d \n", total, successCount+errorCount+ignoreCount, successCount, errorCount)
|
||||
} else if util.CheckFileIsExist(util.FFprobeExePath()) {
|
||||
// Go标准库解码失败,尝试用ffprobe兜底(ffmpeg支持的图片格式更广,如tiff/svg等)
|
||||
if probe, perr := util.ProbeMediaFile(util.FFprobeExePath(), imageFilePath); perr == nil {
|
||||
if w, h := probe.VideoResolution(); w > 0 && h > 0 {
|
||||
successCount = successCount + 1
|
||||
vars.ImagePath2WidthHeightMap[imageFilePath] = fmt.Sprintf("%d-%d", w, h)
|
||||
saveMediaRecord(imageFilePath, "image", w, h, 0, probe.VideoCodec(), probe.FormatName(), probe.RawJSON())
|
||||
continue
|
||||
}
|
||||
}
|
||||
errorCount = errorCount + 1
|
||||
vars.ImageReadErrorPathList = append(vars.ImageReadErrorPathList, imageFilePath)
|
||||
fmt.Printf("=== 异常图片: %s \n", imageFilePath)
|
||||
} else {
|
||||
errorCount = errorCount + 1
|
||||
vars.ImageReadErrorPathList = append(vars.ImageReadErrorPathList, imageFilePath)
|
||||
fmt.Printf("=== 异常图片: %s \n", imageFilePath)
|
||||
}
|
||||
continue
|
||||
}
|
||||
// 其他的直接先忽略吧, 爱改改, 不改拉倒
|
||||
ignoreCount = ignoreCount + 1
|
||||
vars.ImageIgnorePathList = append(vars.ImageIgnorePathList, imageFilePath)
|
||||
|
||||
Reference in New Issue
Block a user