upd:改版
This commit is contained in:
parent
fcc42041ca
commit
6400903610
Binary file not shown.
|
@ -10,6 +10,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -18,7 +19,7 @@ import (
|
||||||
//go:embed files/ffprobe.exe
|
//go:embed files/ffprobe.exe
|
||||||
var ffprobeWin64 []byte
|
var ffprobeWin64 []byte
|
||||||
|
|
||||||
var videoTag = "[PickVideo]" // 标记文件已经被整理过
|
var videoTag = "_[PickVideo]" // 标记文件已经被整理过
|
||||||
var ignoreVideoPathList []string // 忽略的文件路径
|
var ignoreVideoPathList []string // 忽略的文件路径
|
||||||
var readErrorVideoPathList []string // 读取信息异常的路径
|
var readErrorVideoPathList []string // 读取信息异常的路径
|
||||||
var videoPath2WidthHeightMap = make(map[string]string) // 视频路径和宽高比
|
var videoPath2WidthHeightMap = make(map[string]string) // 视频路径和宽高比
|
||||||
|
@ -312,37 +313,43 @@ func moveVerticalVideo(rootDir string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 移动文件到根目录
|
// 移动文件到根目录
|
||||||
func renameFile(rootDir string, modelType string, videoList []string, pathSeparator string) {
|
//func renameFile(rootDir string, modelType string, videoList []string, pathSeparator string) {
|
||||||
total := len(videoList)
|
// total := len(videoList)
|
||||||
var count = 0
|
// var count = 0
|
||||||
bar := goPrint.NewBar(100)
|
// bar := goPrint.NewBar(100)
|
||||||
bar.SetNotice("=== 重命名文件:")
|
// bar.SetNotice("=== 重命名文件:")
|
||||||
bar.SetGraph(">")
|
// bar.SetGraph(">")
|
||||||
for _, videoFilePath := range videoList {
|
// for _, videoFilePath := range videoList {
|
||||||
wh := videoPath2WidthHeightTagMap[videoFilePath]
|
// wh := videoPath2WidthHeightTagMap[videoFilePath]
|
||||||
fileName := vars.GlobalFilePath2FileNameMap[videoFilePath]
|
// fileName := vars.GlobalFilePath2FileNameMap[videoFilePath]
|
||||||
if strings.Contains(fileName, videoTag) { // 处理过了
|
// if strings.Contains(fileName, videoTag) { // 处理过了
|
||||||
fileNames := strings.Split(fileName, videoTag)
|
// fileNames := strings.Split(fileName, videoTag)
|
||||||
if len(fileNames) == 2 {
|
// if len(fileNames) == 2 {
|
||||||
fileName = fileNames[1]
|
// fileName = fileNames[0]
|
||||||
targetFilePath := rootDir + pathSeparator + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + fileName
|
// split := strings.Split(fileName, pathSeparator)
|
||||||
err := os.Rename(videoFilePath, targetFilePath)
|
// if len(split) > 0 {
|
||||||
if err != nil {
|
// realFileName := split[len(split)-1]
|
||||||
fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
|
// //targetFilePath := rootDir + pathSeparator + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + fileName
|
||||||
}
|
// targetFilePath := rootDir + pathSeparator + realFileName + videoTag + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh
|
||||||
}
|
// err := os.Rename(videoFilePath, targetFilePath)
|
||||||
} else {
|
// if err != nil {
|
||||||
targetFilePath := rootDir + pathSeparator + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + " - " + fileName
|
// fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
|
||||||
err := os.Rename(videoFilePath, targetFilePath)
|
// }
|
||||||
if err != nil {
|
// }
|
||||||
fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
|
// }
|
||||||
}
|
// } else {
|
||||||
}
|
// //targetFilePath := rootDir + pathSeparator + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + " - " + fileName
|
||||||
count = count + 1
|
// targetFilePath := rootDir + pathSeparator + fileName + videoTag + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh
|
||||||
bar.PrintBar(util.CalcPercentage(count, total))
|
// err := os.Rename(videoFilePath, targetFilePath)
|
||||||
}
|
// if err != nil {
|
||||||
bar.PrintEnd("=== Finish")
|
// fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
// count = count + 1
|
||||||
|
// bar.PrintBar(util.CalcPercentage(count, total))
|
||||||
|
// }
|
||||||
|
// bar.PrintEnd("=== Finish")
|
||||||
|
//}
|
||||||
|
|
||||||
// 移动文件到原目录
|
// 移动文件到原目录
|
||||||
func renameFileV2(modelType string, videoList []string) {
|
func renameFileV2(modelType string, videoList []string) {
|
||||||
|
@ -355,18 +362,41 @@ func renameFileV2(modelType string, videoList []string) {
|
||||||
wh := videoPath2WidthHeightTagMap[videoFilePath]
|
wh := videoPath2WidthHeightTagMap[videoFilePath]
|
||||||
fileName := vars.GlobalFilePath2FileNameMap[videoFilePath]
|
fileName := vars.GlobalFilePath2FileNameMap[videoFilePath]
|
||||||
filePath := util.GetFileDirectory(videoFilePath)
|
filePath := util.GetFileDirectory(videoFilePath)
|
||||||
if strings.Contains(fileName, videoTag) { // 处理过了
|
//if strings.Contains(fileName, videoTag) { // 处理过了
|
||||||
fileNames := strings.Split(fileName, videoTag)
|
// fileNames := strings.Split(fileName, videoTag)
|
||||||
if len(fileNames) == 2 {
|
// if len(fileNames) == 2 {
|
||||||
fileName = fileNames[1]
|
// fileName = fileNames[0]
|
||||||
targetFilePath := filePath + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + fileName
|
// split := strings.Split(fileName, string(os.PathSeparator))
|
||||||
err := os.Rename(videoFilePath, targetFilePath)
|
// if len(split) > 0 {
|
||||||
if err != nil {
|
// realFileName := split[len(split)-1]
|
||||||
fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
|
// //targetFilePath := filePath + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + fileName
|
||||||
}
|
// ext := filepath.Ext(fileNames[1])
|
||||||
}
|
// lowExt := strings.ToLower(ext)
|
||||||
} else {
|
// header := strings.ReplaceAll(realFileName, ext, "")
|
||||||
targetFilePath := filePath + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + " - " + fileName
|
// targetFilePath := filePath + header + videoTag + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + lowExt
|
||||||
|
// err := os.Rename(videoFilePath, targetFilePath)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//} else {
|
||||||
|
// //targetFilePath := filePath + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + " - " + fileName
|
||||||
|
// ext := filepath.Ext(fileName)
|
||||||
|
// lowExt := strings.ToLower(ext)
|
||||||
|
// header := strings.ReplaceAll(fileName, ext, "")
|
||||||
|
// targetFilePath := filePath + header + videoTag + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + lowExt
|
||||||
|
// err := os.Rename(videoFilePath, targetFilePath)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
if strings.Contains(fileName, videoTag) == false {
|
||||||
|
//targetFilePath := filePath + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + " - " + fileName
|
||||||
|
ext := filepath.Ext(fileName)
|
||||||
|
lowExt := strings.ToLower(ext)
|
||||||
|
header := strings.ReplaceAll(fileName, ext, "")
|
||||||
|
targetFilePath := filePath + header + videoTag + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + lowExt
|
||||||
err := os.Rename(videoFilePath, targetFilePath)
|
err := os.Rename(videoFilePath, targetFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
|
fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
|
||||||
|
|
12
main.go
12
main.go
|
@ -8,16 +8,16 @@ import (
|
||||||
_ "image/gif" // 导入gif支持
|
_ "image/gif" // 导入gif支持
|
||||||
_ "image/jpeg" // 导入jpeg支持
|
_ "image/jpeg" // 导入jpeg支持
|
||||||
_ "image/png" // 导入png支持
|
_ "image/png" // 导入png支持
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rootDir, err := os.Getwd()
|
//rootDir, err := os.Getwd()
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
fmt.Println("=== 获取当前路径异常", err)
|
// fmt.Println("=== 获取当前路径异常", err)
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
|
rootDir := "G:\\DZL_DATA\\D20240630\\Video\\other"
|
||||||
scanner := core.FileScanner{}
|
scanner := core.FileScanner{}
|
||||||
scanner.DoScan(rootDir)
|
scanner.DoScan(rootDir)
|
||||||
scanner.DoFilter()
|
scanner.DoFilter()
|
||||||
|
|
Loading…
Reference in New Issue