- 添加跳过ffprobe相关文件的逻辑,避免处理临时释放文件 - 修复图片处理中的变量引用错误 - 实现大文件指纹复用机制,避免重复全量读取计算MD5 - 新增文件头尾采样指纹算法,提升大文件处理性能 - 重构ffprobe内嵌资源管理,支持多平台自动选择对应版本 - 添加媒体信息数据库的指纹索引和去向跟踪功能 - 优化程序启动流程,失败时跳过媒体整理但保留图片处理 - 更新文档说明多平台ffprobe支持和构建要求
101 lines
3.1 KiB
Go
101 lines
3.1 KiB
Go
package core
|
||
|
||
import (
|
||
"fmt"
|
||
"github.com/redmask-hb/GoSimplePrint/goPrint"
|
||
"kenaito-media-picker/store"
|
||
"kenaito-media-picker/util"
|
||
"kenaito-media-picker/vars"
|
||
"log"
|
||
"os"
|
||
"path"
|
||
"path/filepath"
|
||
"strings"
|
||
)
|
||
|
||
type FileScanner struct {
|
||
}
|
||
|
||
func (FileScanner) DoScan(rootDir string) {
|
||
fmt.Printf("=== 开始扫描文件 \n")
|
||
if err := filepath.Walk(rootDir, visit); err != nil {
|
||
log.Fatal(err)
|
||
}
|
||
doReadFileMimeInfo()
|
||
}
|
||
|
||
func doReadFileMimeInfo() {
|
||
total := len(vars.GlobalFilePathList)
|
||
fmt.Printf("=== 文件总数: %d \n", total)
|
||
// 扫描文件mime信息
|
||
var count = 0
|
||
bar := goPrint.NewBar(100)
|
||
bar.SetNotice("=== 扫描文件Mime:")
|
||
bar.SetGraph(">")
|
||
bar.SetNoticeColor(goPrint.FontColor.Red)
|
||
for _, currentPath := range vars.GlobalFilePathList {
|
||
// mime
|
||
mt := util.ReadFileMimeInfo(currentPath)
|
||
if mt != nil {
|
||
vars.GlobalFilePath2MimeInfoMap[currentPath] = mt.String()
|
||
} else {
|
||
vars.GlobalFilePath2MimeInfoMap[currentPath] = ""
|
||
}
|
||
count = count + 1
|
||
bar.PrintBar(util.CalcPercentage(count, total))
|
||
}
|
||
bar.PrintEnd("=== Finish")
|
||
}
|
||
|
||
func (FileScanner) DoFilter() {
|
||
total := len(vars.GlobalFilePathList)
|
||
var count = 0
|
||
bar := goPrint.NewBar(100)
|
||
bar.SetNotice("=== 过滤已支持的媒体:")
|
||
bar.SetGraph(">")
|
||
for _, globalFilePath := range vars.GlobalFilePathList {
|
||
fileMime := vars.GlobalFilePath2MimeInfoMap[globalFilePath]
|
||
count = count + 1
|
||
// 图片
|
||
ext := path.Ext(globalFilePath)
|
||
if strings.Contains(fileMime, "image/") || util.IsSupportImage(ext) || strings.EqualFold(ext, ".psd") {
|
||
vars.GlobalImagePathList = append(vars.GlobalImagePathList, globalFilePath)
|
||
bar.PrintBar(util.CalcPercentage(count, total))
|
||
continue
|
||
}
|
||
// 其余作为媒体候选,由ffprobe最终判定(视频/音频/不支持),
|
||
// 只要ffmpeg支持的格式都会被识别,不再依赖扩展名白名单
|
||
if util.IsPotentialMedia(fileMime) {
|
||
vars.GlobalMediaPathList = append(vars.GlobalMediaPathList, globalFilePath)
|
||
bar.PrintBar(util.CalcPercentage(count, total))
|
||
continue
|
||
}
|
||
// 明显的非媒体文件(代码/文档/压缩包等)直接不处理
|
||
}
|
||
bar.PrintEnd("=== Finish")
|
||
}
|
||
|
||
// 定义walkFn回调函数visit
|
||
func visit(currentPath string, info os.FileInfo, err error) error {
|
||
if err != nil {
|
||
return err // 如果有错误,直接返回
|
||
}
|
||
if info.IsDir() && vars.GlobalPickerDir != "" && currentPath == vars.GlobalPickerDir {
|
||
return filepath.SkipDir // 跳过白名单目录(已整理文件的输出目录)
|
||
}
|
||
if !info.IsDir() {
|
||
if filepath.Base(currentPath) == store.DBFileName {
|
||
return nil // 跳过媒体信息数据库文件
|
||
}
|
||
if filepath.Base(currentPath) == util.FFprobeExeName || filepath.Base(currentPath) == "ffprobe_mac" {
|
||
return nil // 跳过ffprobe相关文件(中断残留的释放文件 / vars/bin内嵌源文件)
|
||
}
|
||
vars.GlobalFilePathList = append(vars.GlobalFilePathList, currentPath)
|
||
// filename, include ext
|
||
vars.GlobalFilePath2FileNameMap[currentPath] = filepath.Base(currentPath)
|
||
// file ext
|
||
vars.GlobalFilePath2FileExtMap[currentPath] = path.Ext(currentPath)
|
||
}
|
||
return nil
|
||
}
|