upd:编码规范
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
*.exe filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
+1
-1
@@ -30,7 +30,7 @@ type BMPInfoHeader struct {
|
|||||||
ColorsImportant uint32
|
ColorsImportant uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func readBmpInfo(filePath string) (error, int32, int32) {
|
func ReadBmpImage(filePath string) (error, int32, int32) {
|
||||||
file, err := os.Open(filePath)
|
file, err := os.Open(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("=== Failed to open file: %v\n", err)
|
fmt.Printf("=== Failed to open file: %v\n", err)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"OdMediaPicker/util"
|
"ImageVideoResolutionPickerTool/util"
|
||||||
"OdMediaPicker/vars"
|
"ImageVideoResolutionPickerTool/vars"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/redmask-hb/GoSimplePrint/goPrint"
|
"github.com/redmask-hb/GoSimplePrint/goPrint"
|
||||||
"log"
|
"log"
|
||||||
@@ -57,7 +57,7 @@ func (FileScanner) DoFilter() {
|
|||||||
}
|
}
|
||||||
// mime格式为application/octet-stream的视频
|
// mime格式为application/octet-stream的视频
|
||||||
ext := path.Ext(globalFilePath)
|
ext := path.Ext(globalFilePath)
|
||||||
if isSupportVideo(ext) {
|
if util.IsSupportVideo(ext) {
|
||||||
vars.GlobalVideoPathList = append(vars.GlobalVideoPathList, globalFilePath)
|
vars.GlobalVideoPathList = append(vars.GlobalVideoPathList, globalFilePath)
|
||||||
bar.PrintBar(util.CalcPercentage(count, total))
|
bar.PrintBar(util.CalcPercentage(count, total))
|
||||||
continue
|
continue
|
||||||
@@ -67,7 +67,7 @@ func (FileScanner) DoFilter() {
|
|||||||
bar.PrintBar(util.CalcPercentage(count, total))
|
bar.PrintBar(util.CalcPercentage(count, total))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if isSupportImage(ext) {
|
if util.IsSupportImage(ext) {
|
||||||
vars.GlobalImagePathList = append(vars.GlobalImagePathList, globalFilePath)
|
vars.GlobalImagePathList = append(vars.GlobalImagePathList, globalFilePath)
|
||||||
bar.PrintBar(util.CalcPercentage(count, total))
|
bar.PrintBar(util.CalcPercentage(count, total))
|
||||||
continue
|
continue
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+280
-299
@@ -1,11 +1,10 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"OdMediaPicker/util"
|
"ImageVideoResolutionPickerTool/util"
|
||||||
"OdMediaPicker/vars"
|
"ImageVideoResolutionPickerTool/vars"
|
||||||
"fmt"
|
"fmt"
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
"image"
|
|
||||||
_ "image/gif" // 导入gif支持
|
_ "image/gif" // 导入gif支持
|
||||||
_ "image/jpeg" // 导入jpeg支持
|
_ "image/jpeg" // 导入jpeg支持
|
||||||
_ "image/png" // 导入png支持
|
_ "image/png" // 导入png支持
|
||||||
@@ -13,94 +12,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ignoreImagePathList []string // 忽略的文件路径
|
|
||||||
var readErrorImagePathList []string // 读取信息异常的路径
|
|
||||||
var imagePath2WidthHeightMap = make(map[string]string) // 图片路径和宽高比
|
|
||||||
var supportImageTypes = []string{
|
|
||||||
".bmp",
|
|
||||||
".gif",
|
|
||||||
".jpg",
|
|
||||||
".jpeg",
|
|
||||||
".jpe",
|
|
||||||
".png",
|
|
||||||
".webp",
|
|
||||||
".psb",
|
|
||||||
".jfif",
|
|
||||||
}
|
|
||||||
|
|
||||||
// gif图片
|
|
||||||
var gifImageList []string
|
|
||||||
|
|
||||||
// 横向图片
|
|
||||||
var horizontalNormalImageList []string
|
|
||||||
var horizontal1KImageList []string
|
|
||||||
var horizontal2KImageList []string
|
|
||||||
var horizontal3KImageList []string
|
|
||||||
var horizontal4KImageList []string
|
|
||||||
var horizontal5KImageList []string
|
|
||||||
var horizontal6KImageList []string
|
|
||||||
var horizontal7KImageList []string
|
|
||||||
var horizontal8KImageList []string
|
|
||||||
var horizontal9KImageList []string
|
|
||||||
var horizontalHKImageList []string
|
|
||||||
var horizontalStandard720PImageList []string
|
|
||||||
var horizontalStandard1080PImageList []string
|
|
||||||
var horizontalStandard4KImageList []string
|
|
||||||
var horizontalStandard8KImageList []string
|
|
||||||
|
|
||||||
// 纵向图片
|
|
||||||
var verticalNormalImageList []string
|
|
||||||
var vertical1KImageList []string
|
|
||||||
var vertical2KImageList []string
|
|
||||||
var vertical3KImageList []string
|
|
||||||
var vertical4KImageList []string
|
|
||||||
var vertical5KImageList []string
|
|
||||||
var vertical6KImageList []string
|
|
||||||
var vertical7KImageList []string
|
|
||||||
var vertical8KImageList []string
|
|
||||||
var vertical9KImageList []string
|
|
||||||
var verticalHKImageList []string
|
|
||||||
|
|
||||||
// 等比图片
|
|
||||||
var squareNormalImageList []string
|
|
||||||
var square1KImageList []string
|
|
||||||
var square2KImageList []string
|
|
||||||
var square3KImageList []string
|
|
||||||
var square4KImageList []string
|
|
||||||
var square5KImageList []string
|
|
||||||
var square6KImageList []string
|
|
||||||
var square7KImageList []string
|
|
||||||
var square8KImageList []string
|
|
||||||
var square9KImageList []string
|
|
||||||
var squareHKImageList []string
|
|
||||||
|
|
||||||
// psd图片
|
|
||||||
var psdImageList []string
|
|
||||||
|
|
||||||
// 判断是否属于支持的图片文件
|
|
||||||
func isSupportImage(imageType string) bool {
|
|
||||||
for _, supportImageType := range supportImageTypes {
|
|
||||||
if strings.EqualFold(supportImageType, strings.ToLower(imageType)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读取一般图片文件信息
|
|
||||||
func readImageInfo(filePath string) (err error, width int, height int) {
|
|
||||||
file, err := os.Open(filePath) // 图片文件路径
|
|
||||||
if err != nil {
|
|
||||||
return err, 0, 0
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
img, _, err := image.DecodeConfig(file)
|
|
||||||
if err != nil {
|
|
||||||
return err, 0, 0
|
|
||||||
}
|
|
||||||
return nil, img.Width, img.Height
|
|
||||||
}
|
|
||||||
|
|
||||||
func DoHandleImage(rootDir string) {
|
func DoHandleImage(rootDir string) {
|
||||||
total := len(vars.GlobalImagePathList) // 总数
|
total := len(vars.GlobalImagePathList) // 总数
|
||||||
successCount := 0 // 成功数
|
successCount := 0 // 成功数
|
||||||
@@ -108,23 +19,23 @@ func DoHandleImage(rootDir string) {
|
|||||||
ignoreCount := 0 // 忽略数
|
ignoreCount := 0 // 忽略数
|
||||||
for _, imageFilePath := range vars.GlobalImagePathList {
|
for _, imageFilePath := range vars.GlobalImagePathList {
|
||||||
suffix := vars.GlobalFilePath2FileExtMap[imageFilePath]
|
suffix := vars.GlobalFilePath2FileExtMap[imageFilePath]
|
||||||
if isSupportImage(suffix) {
|
if util.IsSupportImage(suffix) {
|
||||||
err, width, height := readImageInfo(imageFilePath)
|
err, width, height := util.ReadImageInfo(imageFilePath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
successCount = successCount + 1
|
successCount = successCount + 1
|
||||||
imagePath2WidthHeightMap[imageFilePath] = fmt.Sprintf("%d-%d", width, height)
|
vars.ImagePath2WidthHeightMap[imageFilePath] = fmt.Sprintf("%d-%d", width, height)
|
||||||
fmt.Printf("=== Image总数: %d, 已读取Info: %d, 成功数: %d, 失败数: %d \n", total, successCount+errorCount+ignoreCount, successCount, errorCount)
|
fmt.Printf("=== Image总数: %d, 已读取Info: %d, 成功数: %d, 失败数: %d \n", total, successCount+errorCount+ignoreCount, successCount, errorCount)
|
||||||
} else {
|
} else {
|
||||||
errorCount = errorCount + 1
|
errorCount = errorCount + 1
|
||||||
readErrorImagePathList = append(readErrorImagePathList, imageFilePath)
|
vars.ImageReadErrorPathList = append(vars.ImageReadErrorPathList, imageFilePath)
|
||||||
fmt.Printf("=== 异常图片: %s \n", imageFilePath)
|
fmt.Printf("=== 异常图片: %s \n", imageFilePath)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.EqualFold(suffix, ".webp") { // 特殊文件处理, webp为网络常用图片格式
|
if strings.EqualFold(suffix, ".webp") { // 特殊文件处理, webp为网络常用图片格式
|
||||||
webpErr, webpWidth, webpHeight := readWebpTypeImage(imageFilePath)
|
webpErr, webpWidth, webpHeight := ReadWebpImage(imageFilePath)
|
||||||
if webpErr == nil {
|
if webpErr == nil {
|
||||||
imagePath2WidthHeightMap[imageFilePath] = fmt.Sprintf("%d-%d", webpWidth, webpHeight)
|
vars.ImagePath2WidthHeightMap[imageFilePath] = fmt.Sprintf("%d-%d", webpWidth, webpHeight)
|
||||||
successCount = successCount + 1
|
successCount = successCount + 1
|
||||||
} else {
|
} else {
|
||||||
errorCount = errorCount + 1
|
errorCount = errorCount + 1
|
||||||
@@ -133,9 +44,9 @@ func DoHandleImage(rootDir string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.EqualFold(suffix, ".bmp") { // 特殊文件处理
|
if strings.EqualFold(suffix, ".bmp") { // 特殊文件处理
|
||||||
bpmErr, bmpWidth, bmpHeight := readBmpInfo(imageFilePath)
|
bpmErr, bmpWidth, bmpHeight := ReadBmpImage(imageFilePath)
|
||||||
if bpmErr == nil {
|
if bpmErr == nil {
|
||||||
imagePath2WidthHeightMap[imageFilePath] = fmt.Sprintf("%d-%d", bmpWidth, bmpHeight)
|
vars.ImagePath2WidthHeightMap[imageFilePath] = fmt.Sprintf("%d-%d", bmpWidth, bmpHeight)
|
||||||
successCount = successCount + 1
|
successCount = successCount + 1
|
||||||
} else {
|
} else {
|
||||||
errorCount = errorCount + 1
|
errorCount = errorCount + 1
|
||||||
@@ -144,40 +55,40 @@ func DoHandleImage(rootDir string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.EqualFold(suffix, ".psd") { // 特殊文件处理
|
if strings.EqualFold(suffix, ".psd") { // 特殊文件处理
|
||||||
psdImageList = append(psdImageList, imageFilePath)
|
vars.ImagePsdList = append(vars.ImagePsdList, imageFilePath)
|
||||||
successCount = successCount + 1
|
successCount = successCount + 1
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// 其他的直接先忽略吧, 爱改改, 不改拉倒
|
// 其他的直接先忽略吧, 爱改改, 不改拉倒
|
||||||
ignoreCount = ignoreCount + 1
|
ignoreCount = ignoreCount + 1
|
||||||
ignoreImagePathList = append(ignoreImagePathList, imageFilePath)
|
vars.ImageIgnorePathList = append(vars.ImageIgnorePathList, imageFilePath)
|
||||||
}
|
}
|
||||||
uid := strings.ReplaceAll(uuid.NewV4().String(), "-", "")
|
uid := strings.ReplaceAll(uuid.NewV4().String(), "-", "")
|
||||||
if len(psdImageList) > 0 {
|
if len(vars.ImagePsdList) > 0 {
|
||||||
psdImagePath := rootDir + string(os.PathSeparator) + uid + "-图片_PSD"
|
psdImagePath := rootDir + string(os.PathSeparator) + uid + "-图片_PSD"
|
||||||
if util.CreateDir(psdImagePath) {
|
if util.CreateDir(psdImagePath) {
|
||||||
doMoveFileToDir(psdImageList, psdImagePath)
|
util.DoMoveFileToDir(vars.ImagePsdList, psdImagePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(readErrorImagePathList) > 0 {
|
if len(vars.ImageReadErrorPathList) > 0 {
|
||||||
readInfoErrorPath := rootDir + string(os.PathSeparator) + uid + "-图片_读取异常"
|
readInfoErrorPath := rootDir + string(os.PathSeparator) + uid + "-图片_读取异常"
|
||||||
if util.CreateDir(readInfoErrorPath) {
|
if util.CreateDir(readInfoErrorPath) {
|
||||||
doMoveFileToDir(readErrorImagePathList, readInfoErrorPath)
|
util.DoMoveFileToDir(vars.ImageReadErrorPathList, readInfoErrorPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(ignoreImagePathList) > 0 {
|
if len(vars.ImageIgnorePathList) > 0 {
|
||||||
ignorePath := rootDir + string(os.PathSeparator) + uid + "-图片_已忽略"
|
ignorePath := rootDir + string(os.PathSeparator) + uid + "-图片_已忽略"
|
||||||
if util.CreateDir(ignorePath) {
|
if util.CreateDir(ignorePath) {
|
||||||
doMoveFileToDir(ignoreImagePathList, ignorePath)
|
util.DoMoveFileToDir(vars.ImageIgnorePathList, ignorePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
doPickImageFile(uid, rootDir, imagePath2WidthHeightMap)
|
doPickImageFile(uid, rootDir, vars.ImagePath2WidthHeightMap)
|
||||||
fmt.Printf("=== 图片处理完毕(UID): %s \n\n", uid)
|
fmt.Printf("=== 图片处理完毕(UID): %s \n\n", uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 条件图片并分组存放
|
// 条件图片并分组存放
|
||||||
func doPickImageFile(uid string, rootDir string, imagePath2WidthHeightMap map[string]string) {
|
func doPickImageFile(uid string, rootDir string, imagePath2WidthHeightMap map[string]string) {
|
||||||
if len(imagePath2WidthHeightMap) == 0 {
|
if len(vars.ImagePath2WidthHeightMap) == 0 {
|
||||||
fmt.Printf("=== 当前目录下没有扫描到图片文件, %s \n", rootDir)
|
fmt.Printf("=== 当前目录下没有扫描到图片文件, %s \n", rootDir)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -207,82 +118,117 @@ func doPickImageFile(uid string, rootDir string, imagePath2WidthHeightMap map[st
|
|||||||
|
|
||||||
// 统一处理gif
|
// 统一处理gif
|
||||||
func handleGifImage(path string) {
|
func handleGifImage(path string) {
|
||||||
gifImageList = append(gifImageList, path)
|
vars.ImageGifList = append(vars.ImageGifList, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理垂直图片
|
// 处理垂直图片
|
||||||
func handleVerticalImage(currentImagePath string, height int) {
|
func handleVerticalImage(currentImagePath string, height int) {
|
||||||
// 非标规格
|
// 非标规格
|
||||||
if height < 1000 {
|
if height < 1000 {
|
||||||
verticalNormalImageList = append(verticalNormalImageList, currentImagePath)
|
vars.ImageVerticalNormalList = append(vars.ImageVerticalNormalList, currentImagePath)
|
||||||
} else if height < 2000 {
|
} else if height < 2000 {
|
||||||
vertical1KImageList = append(vertical1KImageList, currentImagePath)
|
vars.ImageVertical1KList = append(vars.ImageVertical1KList, currentImagePath)
|
||||||
} else if height < 3000 {
|
} else if height < 3000 {
|
||||||
vertical2KImageList = append(vertical2KImageList, currentImagePath)
|
vars.ImageVertical2KList = append(vars.ImageVertical2KList, currentImagePath)
|
||||||
} else if height < 4000 {
|
} else if height < 4000 {
|
||||||
vertical3KImageList = append(vertical3KImageList, currentImagePath)
|
vars.ImageVertical3KList = append(vars.ImageVertical3KList, currentImagePath)
|
||||||
} else if height < 5000 {
|
} else if height < 5000 {
|
||||||
vertical4KImageList = append(vertical4KImageList, currentImagePath)
|
vars.ImageVertical4KList = append(vars.ImageVertical4KList, currentImagePath)
|
||||||
} else if height < 6000 {
|
} else if height < 6000 {
|
||||||
vertical5KImageList = append(vertical5KImageList, currentImagePath)
|
vars.ImageVertical5KList = append(vars.ImageVertical5KList, currentImagePath)
|
||||||
} else if height < 7000 {
|
} else if height < 7000 {
|
||||||
vertical6KImageList = append(vertical6KImageList, currentImagePath)
|
vars.ImageVertical6KList = append(vars.ImageVertical6KList, currentImagePath)
|
||||||
} else if height < 8000 {
|
} else if height < 8000 {
|
||||||
vertical7KImageList = append(vertical7KImageList, currentImagePath)
|
vars.ImageVertical7KList = append(vars.ImageVertical7KList, currentImagePath)
|
||||||
} else if height < 9000 {
|
} else if height < 9000 {
|
||||||
vertical8KImageList = append(vertical8KImageList, currentImagePath)
|
vars.ImageVertical8KList = append(vars.ImageVertical8KList, currentImagePath)
|
||||||
} else if height < 10000 {
|
} else if height < 10000 {
|
||||||
vertical9KImageList = append(vertical9KImageList, currentImagePath)
|
vars.ImageVertical9KList = append(vars.ImageVertical9KList, currentImagePath)
|
||||||
} else if height >= 10000 { // 提示请忽略
|
} else if height >= 10000 { // 提示请忽略
|
||||||
verticalHKImageList = append(verticalHKImageList, currentImagePath)
|
vars.ImageVerticalHKList = append(vars.ImageVerticalHKList, currentImagePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理横向图片
|
// 处理横向图片
|
||||||
func handleHorizontalImage(currentImagePath string, width int, height int) {
|
func handleHorizontalImage(currentImagePath string, width int, height int) {
|
||||||
// 1280 x 720 -> 720p
|
// 1280×720(720p)—— 标准高清(HD),常用于早期高清视频或小型屏幕
|
||||||
if width == 1280 && height == 720 {
|
if width == 1280 && height == 720 {
|
||||||
horizontalStandard720PImageList = append(horizontalStandard720PImageList, currentImagePath)
|
vars.ImageHorizontalStandard720PList = append(vars.ImageHorizontalStandard720PList, currentImagePath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 1920 x 1080 -> 1080p
|
// 1600×900—— 介于HD和FHD之间
|
||||||
|
if width == 1600 && height == 900 {
|
||||||
|
vars.ImageHorizontalStandard1D5KList = append(vars.ImageHorizontalStandard1D5KList, currentImagePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 1920×1080(1080p)—— 全高清,主流显示器、电视和视频的分辨率
|
||||||
if width == 1920 && height == 1080 {
|
if width == 1920 && height == 1080 {
|
||||||
horizontalStandard1080PImageList = append(horizontalStandard1080PImageList, currentImagePath)
|
vars.ImageHorizontalStandard1080PList = append(vars.ImageHorizontalStandard1080PList, currentImagePath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 3840 x 2160 -> 4k
|
// 2048×1080(2dk)—— 影院2k
|
||||||
|
if width == 2048 && height == 1080 {
|
||||||
|
vars.ImageHorizontalStandard2DKList = append(vars.ImageHorizontalStandard2DKList, currentImagePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 2560×1440(1440p)—— 俗称“2.5K”,电竞显示器或高端手机屏幕
|
||||||
|
if width == 2560 && height == 1440 {
|
||||||
|
vars.ImageHorizontalStandard2D5KList = append(vars.ImageHorizontalStandard2D5KList, currentImagePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 2560×1080—— 带鱼屏显示器(超宽屏)
|
||||||
|
if width == 2560 && height == 1080 {
|
||||||
|
vars.ImageHorizontalStandardUltraWide2List = append(vars.ImageHorizontalStandardUltraWide2List, currentImagePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 3440×1440—— 带鱼屏显示器(超宽屏)
|
||||||
|
if width == 3440 && height == 1440 {
|
||||||
|
vars.ImageHorizontalStandardUltraWide3List = append(vars.ImageHorizontalStandardUltraWide3List, currentImagePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 5120×2160—— 带鱼屏显示器(超宽屏)
|
||||||
|
if width == 5120 && height == 2160 {
|
||||||
|
vars.ImageHorizontalStandardUltraWide4List = append(vars.ImageHorizontalStandardUltraWide4List, currentImagePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 3840×2160(主流4K)—— 超高清,现代高端显示器、电视和影视制作
|
||||||
if width == 3840 && height == 2160 {
|
if width == 3840 && height == 2160 {
|
||||||
horizontalStandard4KImageList = append(horizontalStandard4KImageList, currentImagePath)
|
vars.ImageHorizontalStandard4KList = append(vars.ImageHorizontalStandard4KList, currentImagePath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 7680 x 4320 -> 8k
|
// 4096×2160(DCI 4K)—— 电影行业标准
|
||||||
|
if width == 4096 && height == 2160 {
|
||||||
|
vars.ImageHorizontalStandard4KHList = append(vars.ImageHorizontalStandard4KHList, currentImagePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 7680×4320—— 超高清,用于专业影视或高端设备
|
||||||
if width == 7680 && height == 4320 {
|
if width == 7680 && height == 4320 {
|
||||||
horizontalStandard8KImageList = append(horizontalStandard8KImageList, currentImagePath)
|
vars.ImageHorizontalStandard8KList = append(vars.ImageHorizontalStandard8KList, currentImagePath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 非标规格
|
// 非标规格
|
||||||
if width < 1000 {
|
if width < 1000 {
|
||||||
horizontalNormalImageList = append(horizontalNormalImageList, currentImagePath)
|
vars.ImageHorizontalNormalList = append(vars.ImageHorizontalNormalList, currentImagePath)
|
||||||
} else if width < 2000 {
|
} else if width < 2000 {
|
||||||
horizontal1KImageList = append(horizontal1KImageList, currentImagePath)
|
vars.ImageHorizontal1KList = append(vars.ImageHorizontal1KList, currentImagePath)
|
||||||
} else if width < 3000 {
|
} else if width < 3000 {
|
||||||
horizontal2KImageList = append(horizontal2KImageList, currentImagePath)
|
vars.ImageHorizontal2KList = append(vars.ImageHorizontal2KList, currentImagePath)
|
||||||
} else if width < 4000 {
|
} else if width < 4000 {
|
||||||
horizontal3KImageList = append(horizontal3KImageList, currentImagePath)
|
vars.ImageHorizontal3KList = append(vars.ImageHorizontal3KList, currentImagePath)
|
||||||
} else if width < 5000 {
|
} else if width < 5000 {
|
||||||
horizontal4KImageList = append(horizontal4KImageList, currentImagePath)
|
vars.ImageHorizontal4KList = append(vars.ImageHorizontal4KList, currentImagePath)
|
||||||
} else if width < 6000 {
|
} else if width < 6000 {
|
||||||
horizontal5KImageList = append(horizontal5KImageList, currentImagePath)
|
vars.ImageHorizontal5KList = append(vars.ImageHorizontal5KList, currentImagePath)
|
||||||
} else if width < 7000 {
|
} else if width < 7000 {
|
||||||
horizontal6KImageList = append(horizontal6KImageList, currentImagePath)
|
vars.ImageHorizontal6KList = append(vars.ImageHorizontal6KList, currentImagePath)
|
||||||
} else if width < 8000 {
|
} else if width < 8000 {
|
||||||
horizontal7KImageList = append(horizontal7KImageList, currentImagePath)
|
vars.ImageHorizontal7KList = append(vars.ImageHorizontal7KList, currentImagePath)
|
||||||
} else if width < 9000 {
|
} else if width < 9000 {
|
||||||
horizontal8KImageList = append(horizontal8KImageList, currentImagePath)
|
vars.ImageHorizontal8KList = append(vars.ImageHorizontal8KList, currentImagePath)
|
||||||
} else if width < 10000 {
|
} else if width < 10000 {
|
||||||
horizontal9KImageList = append(horizontal9KImageList, currentImagePath)
|
vars.ImageHorizontal9KList = append(vars.ImageHorizontal9KList, currentImagePath)
|
||||||
} else if width >= 10000 { // 提示请忽略
|
} else if width >= 10000 { // 提示请忽略
|
||||||
horizontalHKImageList = append(horizontalHKImageList, currentImagePath)
|
vars.ImageHorizontalHKList = append(vars.ImageHorizontalHKList, currentImagePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,27 +236,27 @@ func handleHorizontalImage(currentImagePath string, width int, height int) {
|
|||||||
func handleSquareImage(currentImagePath string, width int) {
|
func handleSquareImage(currentImagePath string, width int) {
|
||||||
// 非标规格
|
// 非标规格
|
||||||
if width < 1000 {
|
if width < 1000 {
|
||||||
squareNormalImageList = append(squareNormalImageList, currentImagePath)
|
vars.ImageSquareNormalList = append(vars.ImageSquareNormalList, currentImagePath)
|
||||||
} else if width < 2000 {
|
} else if width < 2000 {
|
||||||
square1KImageList = append(square1KImageList, currentImagePath)
|
vars.ImageSquare1KList = append(vars.ImageSquare1KList, currentImagePath)
|
||||||
} else if width < 3000 {
|
} else if width < 3000 {
|
||||||
square2KImageList = append(square2KImageList, currentImagePath)
|
vars.ImageSquare2KList = append(vars.ImageSquare2KList, currentImagePath)
|
||||||
} else if width < 4000 {
|
} else if width < 4000 {
|
||||||
square3KImageList = append(square3KImageList, currentImagePath)
|
vars.ImageSquare3KList = append(vars.ImageSquare3KList, currentImagePath)
|
||||||
} else if width < 5000 {
|
} else if width < 5000 {
|
||||||
square4KImageList = append(square4KImageList, currentImagePath)
|
vars.ImageSquare4KList = append(vars.ImageSquare4KList, currentImagePath)
|
||||||
} else if width < 6000 {
|
} else if width < 6000 {
|
||||||
square5KImageList = append(square5KImageList, currentImagePath)
|
vars.ImageSquare5KList = append(vars.ImageSquare5KList, currentImagePath)
|
||||||
} else if width < 7000 {
|
} else if width < 7000 {
|
||||||
square6KImageList = append(square6KImageList, currentImagePath)
|
vars.ImageSquare6KList = append(vars.ImageSquare6KList, currentImagePath)
|
||||||
} else if width < 8000 {
|
} else if width < 8000 {
|
||||||
square7KImageList = append(square7KImageList, currentImagePath)
|
vars.ImageSquare7KList = append(vars.ImageSquare7KList, currentImagePath)
|
||||||
} else if width < 9000 {
|
} else if width < 9000 {
|
||||||
square8KImageList = append(square8KImageList, currentImagePath)
|
vars.ImageSquare8KList = append(vars.ImageSquare8KList, currentImagePath)
|
||||||
} else if width < 10000 {
|
} else if width < 10000 {
|
||||||
square9KImageList = append(square9KImageList, currentImagePath)
|
vars.ImageSquare9KList = append(vars.ImageSquare9KList, currentImagePath)
|
||||||
} else if width > 10000 {
|
} else if width > 10000 {
|
||||||
squareHKImageList = append(squareHKImageList, currentImagePath)
|
vars.ImageSquareHKList = append(vars.ImageSquareHKList, currentImagePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,81 +264,116 @@ func handleSquareImage(currentImagePath string, width int) {
|
|||||||
func moveHorizontalImage(rootDir string, uid string) {
|
func moveHorizontalImage(rootDir string, uid string) {
|
||||||
pathSeparator := string(os.PathSeparator)
|
pathSeparator := string(os.PathSeparator)
|
||||||
// 标准
|
// 标准
|
||||||
if len(horizontalStandard720PImageList) > 0 {
|
if len(vars.ImageHorizontalStandard720PList) > 0 {
|
||||||
horizontalStandard720PImagePath := rootDir + pathSeparator + uid + "-图片_横屏_720P"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_720P"
|
||||||
util.CreateDir(horizontalStandard720PImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontalStandard720PImageList, horizontalStandard720PImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontalStandard720PList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(horizontalStandard1080PImageList) > 0 {
|
if len(vars.ImageHorizontalStandard1D5KList) > 0 {
|
||||||
horizontalStandard1080PImagePath := rootDir + pathSeparator + uid + "-图片_横屏_1080P"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_1D5KP"
|
||||||
util.CreateDir(horizontalStandard1080PImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontalStandard1080PImageList, horizontalStandard1080PImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontalStandard1D5KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(horizontalStandard4KImageList) > 0 {
|
if len(vars.ImageHorizontalStandard1080PList) > 0 {
|
||||||
horizontalStandard4KImagePath := rootDir + pathSeparator + uid + "-图片_横屏_4KP"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_1080P"
|
||||||
util.CreateDir(horizontalStandard4KImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontalStandard4KImageList, horizontalStandard4KImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontalStandard1080PList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(horizontalStandard8KImageList) > 0 {
|
if len(vars.ImageHorizontalStandard2DKList) > 0 {
|
||||||
horizontalStandard8KImagePath := rootDir + pathSeparator + uid + "-图片_横屏_8KP"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_2DKP"
|
||||||
util.CreateDir(horizontalStandard8KImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontalStandard8KImageList, horizontalStandard8KImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontalStandard2DKList, imageDirPath)
|
||||||
|
}
|
||||||
|
if len(vars.ImageHorizontalStandard2D5KList) > 0 {
|
||||||
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_2D5KP"
|
||||||
|
util.CreateDir(imageDirPath)
|
||||||
|
util.DoMoveFileToDir(vars.ImageHorizontalStandard2D5KList, imageDirPath)
|
||||||
|
}
|
||||||
|
if len(vars.ImageHorizontalStandardUltraWide2List) > 0 {
|
||||||
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_ultraWide2KP"
|
||||||
|
util.CreateDir(imageDirPath)
|
||||||
|
util.DoMoveFileToDir(vars.ImageHorizontalStandardUltraWide2List, imageDirPath)
|
||||||
|
}
|
||||||
|
if len(vars.ImageHorizontalStandardUltraWide3List) > 0 {
|
||||||
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_ultraWide3KP"
|
||||||
|
util.CreateDir(imageDirPath)
|
||||||
|
util.DoMoveFileToDir(vars.ImageHorizontalStandardUltraWide3List, imageDirPath)
|
||||||
|
}
|
||||||
|
if len(vars.ImageHorizontalStandardUltraWide4List) > 0 {
|
||||||
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_ultraWide4KP"
|
||||||
|
util.CreateDir(imageDirPath)
|
||||||
|
util.DoMoveFileToDir(vars.ImageHorizontalStandardUltraWide4List, imageDirPath)
|
||||||
|
}
|
||||||
|
if len(vars.ImageHorizontalStandard4KList) > 0 {
|
||||||
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_4KP"
|
||||||
|
util.CreateDir(imageDirPath)
|
||||||
|
util.DoMoveFileToDir(vars.ImageHorizontalStandard4KList, imageDirPath)
|
||||||
|
}
|
||||||
|
if len(vars.ImageHorizontalStandard4KHList) > 0 {
|
||||||
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_4KHP"
|
||||||
|
util.CreateDir(imageDirPath)
|
||||||
|
util.DoMoveFileToDir(vars.ImageHorizontalStandard4KHList, imageDirPath)
|
||||||
|
}
|
||||||
|
if len(vars.ImageHorizontalStandard8KList) > 0 {
|
||||||
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_8KP"
|
||||||
|
util.CreateDir(imageDirPath)
|
||||||
|
util.DoMoveFileToDir(vars.ImageHorizontalStandard8KList, imageDirPath)
|
||||||
}
|
}
|
||||||
// 非标准
|
// 非标准
|
||||||
if len(horizontalNormalImageList) > 0 {
|
if len(vars.ImageHorizontalNormalList) > 0 {
|
||||||
horizontalNormalImagePath := rootDir + pathSeparator + uid + "-图片_横屏_普通"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_普通"
|
||||||
util.CreateDir(horizontalNormalImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontalNormalImageList, horizontalNormalImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontalNormalList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(horizontal1KImageList) > 0 {
|
if len(vars.ImageHorizontal1KList) > 0 {
|
||||||
horizontal1kImagePath := rootDir + pathSeparator + uid + "-图片_横屏_1K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_1K"
|
||||||
util.CreateDir(horizontal1kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontal1KImageList, horizontal1kImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontal1KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(horizontal2KImageList) > 0 {
|
if len(vars.ImageHorizontal2KList) > 0 {
|
||||||
horizontal2kImagePath := rootDir + pathSeparator + uid + "-图片_横屏_2K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_2K"
|
||||||
util.CreateDir(horizontal2kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontal2KImageList, horizontal2kImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontal2KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(horizontal3KImageList) > 0 {
|
if len(vars.ImageHorizontal3KList) > 0 {
|
||||||
horizontal3kImagePath := rootDir + pathSeparator + uid + "-图片_横屏_3K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_3K"
|
||||||
util.CreateDir(horizontal3kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontal3KImageList, horizontal3kImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontal3KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(horizontal4KImageList) > 0 {
|
if len(vars.ImageHorizontal4KList) > 0 {
|
||||||
horizontal4kImagePath := rootDir + pathSeparator + uid + "-图片_横屏_4K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_4K"
|
||||||
util.CreateDir(horizontal4kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontal4KImageList, horizontal4kImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontal4KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(horizontal5KImageList) > 0 {
|
if len(vars.ImageHorizontal5KList) > 0 {
|
||||||
horizontal5kImagePath := rootDir + pathSeparator + uid + "-图片_横屏_5K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_5K"
|
||||||
util.CreateDir(horizontal5kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontal5KImageList, horizontal5kImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontal5KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(horizontal6KImageList) > 0 {
|
if len(vars.ImageHorizontal6KList) > 0 {
|
||||||
horizontal6kImagePath := rootDir + pathSeparator + uid + "-图片_横屏_6K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_6K"
|
||||||
util.CreateDir(horizontal6kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontal6KImageList, horizontal6kImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontal6KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(horizontal7KImageList) > 0 {
|
if len(vars.ImageHorizontal7KList) > 0 {
|
||||||
horizontal7KImagePath := rootDir + pathSeparator + uid + "-图片_横屏_7K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_7K"
|
||||||
util.CreateDir(horizontal7KImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontal7KImageList, horizontal7KImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontal7KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(horizontal8KImageList) > 0 {
|
if len(vars.ImageHorizontal8KList) > 0 {
|
||||||
horizontal8kImagePath := rootDir + pathSeparator + uid + "-图片_横屏_8K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_8K"
|
||||||
util.CreateDir(horizontal8kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontal8KImageList, horizontal8kImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontal8KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(horizontal9KImageList) > 0 {
|
if len(vars.ImageHorizontal9KList) > 0 {
|
||||||
horizontal9kImagePath := rootDir + pathSeparator + uid + "-图片_横屏_9K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_9K"
|
||||||
util.CreateDir(horizontal9kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontal9KImageList, horizontal9kImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontal9KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(horizontalHKImageList) > 0 {
|
if len(vars.ImageHorizontalHKList) > 0 {
|
||||||
horizontalHkImagePath := rootDir + pathSeparator + uid + "-图片_横屏_原图"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_横屏_原图"
|
||||||
util.CreateDir(horizontalHkImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(horizontalHKImageList, horizontalHkImagePath)
|
util.DoMoveFileToDir(vars.ImageHorizontalHKList, imageDirPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,60 +381,60 @@ func moveHorizontalImage(rootDir string, uid string) {
|
|||||||
func moveVerticalImage(rootDir string, uid string) {
|
func moveVerticalImage(rootDir string, uid string) {
|
||||||
pathSeparator := string(os.PathSeparator)
|
pathSeparator := string(os.PathSeparator)
|
||||||
// 非标准
|
// 非标准
|
||||||
if len(verticalNormalImageList) > 0 {
|
if len(vars.ImageVerticalNormalList) > 0 {
|
||||||
verticalNormalImagePath := rootDir + pathSeparator + uid + "-图片_竖屏_普通"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_竖屏_普通"
|
||||||
util.CreateDir(verticalNormalImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(verticalNormalImageList, verticalNormalImagePath)
|
util.DoMoveFileToDir(vars.ImageVerticalNormalList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(vertical1KImageList) > 0 {
|
if len(vars.ImageVertical1KList) > 0 {
|
||||||
vertical1kImagePath := rootDir + pathSeparator + uid + "-图片_竖屏_1K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_竖屏_1K"
|
||||||
util.CreateDir(vertical1kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(vertical1KImageList, vertical1kImagePath)
|
util.DoMoveFileToDir(vars.ImageVertical1KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(vertical2KImageList) > 0 {
|
if len(vars.ImageVertical2KList) > 0 {
|
||||||
vertical2kImagePath := rootDir + pathSeparator + uid + "-图片_竖屏_2K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_竖屏_2K"
|
||||||
util.CreateDir(vertical2kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(vertical2KImageList, vertical2kImagePath)
|
util.DoMoveFileToDir(vars.ImageVertical2KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(vertical3KImageList) > 0 {
|
if len(vars.ImageVertical3KList) > 0 {
|
||||||
vertical3kImagePath := rootDir + pathSeparator + uid + "-图片_竖屏_3K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_竖屏_3K"
|
||||||
util.CreateDir(vertical3kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(vertical3KImageList, vertical3kImagePath)
|
util.DoMoveFileToDir(vars.ImageVertical3KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(vertical4KImageList) > 0 {
|
if len(vars.ImageVertical4KList) > 0 {
|
||||||
vertical4kImagePath := rootDir + pathSeparator + uid + "-图片_竖屏_4K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_竖屏_4K"
|
||||||
util.CreateDir(vertical4kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(vertical4KImageList, vertical4kImagePath)
|
util.DoMoveFileToDir(vars.ImageVertical4KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(vertical5KImageList) > 0 {
|
if len(vars.ImageVertical5KList) > 0 {
|
||||||
vertical5kImagePath := rootDir + pathSeparator + uid + "-图片_竖屏_5K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_竖屏_5K"
|
||||||
util.CreateDir(vertical5kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(vertical5KImageList, vertical5kImagePath)
|
util.DoMoveFileToDir(vars.ImageVertical5KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(vertical6KImageList) > 0 {
|
if len(vars.ImageVertical6KList) > 0 {
|
||||||
vertical6kImagePath := rootDir + pathSeparator + uid + "-图片_竖屏_6K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_竖屏_6K"
|
||||||
util.CreateDir(vertical6kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(vertical6KImageList, vertical6kImagePath)
|
util.DoMoveFileToDir(vars.ImageVertical6KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(vertical7KImageList) > 0 {
|
if len(vars.ImageVertical7KList) > 0 {
|
||||||
vertical7KImagePath := rootDir + pathSeparator + uid + "-图片_竖屏_7K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_竖屏_7K"
|
||||||
util.CreateDir(vertical7KImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(vertical7KImageList, vertical7KImagePath)
|
util.DoMoveFileToDir(vars.ImageVertical7KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(vertical8KImageList) > 0 {
|
if len(vars.ImageVertical8KList) > 0 {
|
||||||
vertical8kImagePath := rootDir + pathSeparator + uid + "-图片_竖屏_8K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_竖屏_8K"
|
||||||
util.CreateDir(vertical8kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(vertical8KImageList, vertical8kImagePath)
|
util.DoMoveFileToDir(vars.ImageVertical8KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(vertical9KImageList) > 0 {
|
if len(vars.ImageVertical9KList) > 0 {
|
||||||
vertical9kImagePath := rootDir + pathSeparator + uid + "-图片_竖屏_9K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_竖屏_9K"
|
||||||
util.CreateDir(vertical9kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(vertical9KImageList, vertical9kImagePath)
|
util.DoMoveFileToDir(vars.ImageVertical9KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(verticalHKImageList) > 0 {
|
if len(vars.ImageVerticalHKList) > 0 {
|
||||||
verticalHkImagePath := rootDir + pathSeparator + uid + "-图片_竖屏_原图"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_竖屏_原图"
|
||||||
util.CreateDir(verticalHkImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(verticalHKImageList, verticalHkImagePath)
|
util.DoMoveFileToDir(vars.ImageVerticalHKList, imageDirPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,59 +442,59 @@ func moveVerticalImage(rootDir string, uid string) {
|
|||||||
func moveSquareImage(rootDir string, uid string) {
|
func moveSquareImage(rootDir string, uid string) {
|
||||||
pathSeparator := string(os.PathSeparator)
|
pathSeparator := string(os.PathSeparator)
|
||||||
// 非标准
|
// 非标准
|
||||||
if len(squareNormalImageList) > 0 {
|
if len(vars.ImageSquareNormalList) > 0 {
|
||||||
squareNormalImagePath := rootDir + pathSeparator + uid + "-图片_等比_普通"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_等比_普通"
|
||||||
util.CreateDir(squareNormalImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(squareNormalImageList, squareNormalImagePath)
|
util.DoMoveFileToDir(vars.ImageSquareNormalList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(square1KImageList) > 0 {
|
if len(vars.ImageSquare1KList) > 0 {
|
||||||
square1kImagePath := rootDir + pathSeparator + uid + "-图片_等比_1K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_等比_1K"
|
||||||
util.CreateDir(square1kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(square1KImageList, square1kImagePath)
|
util.DoMoveFileToDir(vars.ImageSquare1KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(square2KImageList) > 0 {
|
if len(vars.ImageSquare2KList) > 0 {
|
||||||
square2kImagePath := rootDir + pathSeparator + uid + "-图片_等比_2K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_等比_2K"
|
||||||
util.CreateDir(square2kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(square2KImageList, square2kImagePath)
|
util.DoMoveFileToDir(vars.ImageSquare2KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(square3KImageList) > 0 {
|
if len(vars.ImageSquare3KList) > 0 {
|
||||||
square3kImagePath := rootDir + pathSeparator + uid + "-图片_等比_3K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_等比_3K"
|
||||||
util.CreateDir(square3kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(square3KImageList, square3kImagePath)
|
util.DoMoveFileToDir(vars.ImageSquare3KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(square4KImageList) > 0 {
|
if len(vars.ImageSquare4KList) > 0 {
|
||||||
square4kImagePath := rootDir + pathSeparator + uid + "-图片_等比_4K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_等比_4K"
|
||||||
util.CreateDir(square4kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(square4KImageList, square4kImagePath)
|
util.DoMoveFileToDir(vars.ImageSquare4KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(square5KImageList) > 0 {
|
if len(vars.ImageSquare5KList) > 0 {
|
||||||
square5kImagePath := rootDir + pathSeparator + uid + "-图片_等比_5K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_等比_5K"
|
||||||
util.CreateDir(square5kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(square5KImageList, square5kImagePath)
|
util.DoMoveFileToDir(vars.ImageSquare5KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(square6KImageList) > 0 {
|
if len(vars.ImageSquare6KList) > 0 {
|
||||||
square6kImagePath := rootDir + pathSeparator + uid + "-图片_等比_6K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_等比_6K"
|
||||||
util.CreateDir(square6kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(square6KImageList, square6kImagePath)
|
util.DoMoveFileToDir(vars.ImageSquare6KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(square7KImageList) > 0 {
|
if len(vars.ImageSquare7KList) > 0 {
|
||||||
square7KImagePath := rootDir + pathSeparator + uid + "-图片_等比_7K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_等比_7K"
|
||||||
util.CreateDir(square7KImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(square7KImageList, square7KImagePath)
|
util.DoMoveFileToDir(vars.ImageSquare7KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(square8KImageList) > 0 {
|
if len(vars.ImageSquare8KList) > 0 {
|
||||||
square8kImagePath := rootDir + pathSeparator + uid + "-图片_等比_8K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_等比_8K"
|
||||||
util.CreateDir(square8kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(square8KImageList, square8kImagePath)
|
util.DoMoveFileToDir(vars.ImageSquare8KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(square9KImageList) > 0 {
|
if len(vars.ImageSquare9KList) > 0 {
|
||||||
square9kImagePath := rootDir + pathSeparator + uid + "-图片_等比_9K"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_等比_9K"
|
||||||
util.CreateDir(square9kImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(square9KImageList, square9kImagePath)
|
util.DoMoveFileToDir(vars.ImageSquare9KList, imageDirPath)
|
||||||
}
|
}
|
||||||
if len(squareHKImageList) > 0 {
|
if len(vars.ImageSquareHKList) > 0 {
|
||||||
squareHkImagePath := rootDir + pathSeparator + uid + "-图片_等比_原图"
|
imageDirPath := rootDir + pathSeparator + uid + "-图片_等比_原图"
|
||||||
util.CreateDir(squareHkImagePath)
|
util.CreateDir(imageDirPath)
|
||||||
doMoveFileToDir(squareHKImageList, squareHkImagePath)
|
util.DoMoveFileToDir(vars.ImageSquareHKList, imageDirPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+289
-546
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -6,8 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 读取webp格式的图片信息
|
// ReadWebpImage 读取webp格式的图片信息
|
||||||
func readWebpTypeImage(webpFilePath string) (err error, width int, height int) {
|
func ReadWebpImage(webpFilePath string) (err error, width int, height int) {
|
||||||
// 打开WebP文件
|
// 打开WebP文件
|
||||||
file, err := os.Open(webpFilePath)
|
file, err := os.Open(webpFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:6080e34165fcb0261f979bb1cef26c5fce616e2a416384b50bcce956aa265018
|
||||||
|
size 140416365
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:5f0458eb44ef2a9f8a3d02946e2d1382b1dac3e4a95d4dacf662ede567abfc59
|
||||||
|
size 612889
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
module OdMediaPicker
|
module ImageVideoResolutionPickerTool
|
||||||
|
|
||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"OdMediaPicker/core"
|
"ImageVideoResolutionPickerTool/core"
|
||||||
"OdMediaPicker/vars"
|
"ImageVideoResolutionPickerTool/vars"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "image/gif" // 导入gif支持
|
_ "image/gif" // 导入gif支持
|
||||||
@@ -13,11 +13,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
fmt.Println("=== 警告:该程序会改变目录结构,将在5秒后开始执行")
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
rootDir, err := os.Getwd()
|
rootDir, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("=== 获取当前路径异常", err)
|
fmt.Println("=== 获取当前路径异常", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
rootDir = "E:\\DGD\\d20250424\\video"
|
||||||
scanner := core.FileScanner{}
|
scanner := core.FileScanner{}
|
||||||
scanner.DoScan(rootDir)
|
scanner.DoScan(rootDir)
|
||||||
scanner.DoFilter()
|
scanner.DoFilter()
|
||||||
@@ -27,6 +30,4 @@ func main() {
|
|||||||
if len(vars.GlobalVideoPathList) > 0 {
|
if len(vars.GlobalVideoPathList) > 0 {
|
||||||
core.DoHandleVideo(rootDir)
|
core.DoHandleVideo(rootDir)
|
||||||
}
|
}
|
||||||
fmt.Println("=== 5s后自动退出")
|
|
||||||
time.Sleep(time.Second * 5)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// String2int 字符串转int
|
||||||
|
func String2int(str string) int {
|
||||||
|
intValue, err := strconv.Atoi(str)
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return intValue
|
||||||
|
}
|
||||||
|
|
||||||
|
// SecondsToHms 将秒数转换为小时、分钟、秒的格式
|
||||||
|
func SecondsToHms(seconds int) string {
|
||||||
|
t := time.Duration(seconds) * time.Second
|
||||||
|
h := t / time.Hour
|
||||||
|
t -= h * time.Hour
|
||||||
|
m := t / time.Minute
|
||||||
|
t -= m * time.Minute
|
||||||
|
s := t / time.Second
|
||||||
|
return fmt.Sprintf("%02d-%02d-%02d", h, m, s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CalcPercentage 计算percentage相对于total的百分比
|
||||||
|
func CalcPercentage(percentage int, total int) int {
|
||||||
|
return int(float64(percentage) / float64(total) * 100)
|
||||||
|
}
|
||||||
+111
@@ -0,0 +1,111 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gabriel-vasile/mimetype"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreateDir 创建目录
|
||||||
|
func CreateDir(dirPath string) bool {
|
||||||
|
err := os.Mkdir(dirPath, 0755)
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFileDirectory 获取文件所在文件夹
|
||||||
|
func GetFileDirectory(filePath string) string {
|
||||||
|
directoryPath, _ := filepath.Split(filePath)
|
||||||
|
return directoryPath
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadFileMimeInfo 获取文件mime信息
|
||||||
|
func ReadFileMimeInfo(filepath string) *mimetype.MIME {
|
||||||
|
mt, err := mimetype.DetectFile(filepath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return mt
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckFileIsExist 判断文件是否存在,存在返回 true,不存在返回false
|
||||||
|
func CheckFileIsExist(filename string) bool {
|
||||||
|
var exist = true
|
||||||
|
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||||
|
exist = false
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteByteArraysToFile 写字节数组到文件
|
||||||
|
func WriteByteArraysToFile(content []byte, filename string) error {
|
||||||
|
return ioutil.WriteFile(filename, content, 0777)
|
||||||
|
}
|
||||||
|
|
||||||
|
//// 移动文件到根目录
|
||||||
|
//func renameFile(rootDir string, modelType string, videoList []string, pathSeparator string) {
|
||||||
|
// total := len(videoList)
|
||||||
|
// var count = 0
|
||||||
|
// bar := goPrint.NewBar(100)
|
||||||
|
// bar.SetNotice("=== 重命名文件:")
|
||||||
|
// bar.SetGraph(">")
|
||||||
|
// for _, videoFilePath := range videoList {
|
||||||
|
// wh := videoPath2WidthHeightTagMap[videoFilePath]
|
||||||
|
// fileName := vars.GlobalFilePath2FileNameMap[videoFilePath]
|
||||||
|
// if strings.Contains(fileName, videoTag) { // 处理过了
|
||||||
|
// fileNames := strings.Split(fileName, videoTag)
|
||||||
|
// if len(fileNames) == 2 {
|
||||||
|
// fileName = fileNames[1]
|
||||||
|
// targetFilePath := rootDir + pathSeparator + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + fileName
|
||||||
|
// err := os.Rename(videoFilePath, targetFilePath)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// targetFilePath := rootDir + pathSeparator + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + " - " + fileName
|
||||||
|
// err := os.Rename(videoFilePath, targetFilePath)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// count = count + 1
|
||||||
|
// bar.PrintBar(util.CalcPercentage(count, total))
|
||||||
|
// }
|
||||||
|
// bar.PrintEnd("=== Finish")
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//// 移动文件到原目录
|
||||||
|
//func renameFileV2(modelType string, videoList []string) {
|
||||||
|
// total := len(videoList)
|
||||||
|
// var count = 0
|
||||||
|
// bar := goPrint.NewBar(100)
|
||||||
|
// bar.SetNotice("=== 重命名文件:")
|
||||||
|
// bar.SetGraph(">")
|
||||||
|
// for _, videoFilePath := range videoList {
|
||||||
|
// wh := videoPath2WidthHeightTagMap[videoFilePath]
|
||||||
|
// fileName := vars.GlobalFilePath2FileNameMap[videoFilePath]
|
||||||
|
// filePath := util.GetFileDirectory(videoFilePath)
|
||||||
|
// if strings.Contains(fileName, videoTag) { // 处理过了
|
||||||
|
// fileNames := strings.Split(fileName, videoTag)
|
||||||
|
// if len(fileNames) == 2 {
|
||||||
|
// fileName = fileNames[1]
|
||||||
|
// targetFilePath := filePath + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + fileName
|
||||||
|
// err := os.Rename(videoFilePath, targetFilePath)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// targetFilePath := filePath + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + " - " + fileName
|
||||||
|
// err := os.Rename(videoFilePath, targetFilePath)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// count = count + 1
|
||||||
|
// bar.PrintBar(util.CalcPercentage(count, total))
|
||||||
|
// }
|
||||||
|
// bar.PrintEnd("=== Finish")
|
||||||
|
//}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var supportImageTypes = []string{
|
||||||
|
".bmp",
|
||||||
|
".gif",
|
||||||
|
".jpg",
|
||||||
|
".jpeg",
|
||||||
|
".jpe",
|
||||||
|
".png",
|
||||||
|
".webp",
|
||||||
|
".psb",
|
||||||
|
".jfif",
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsSupportImage 判断是否属于支持的图片文件
|
||||||
|
func IsSupportImage(imageType string) bool {
|
||||||
|
for _, supportImageType := range supportImageTypes {
|
||||||
|
if strings.EqualFold(supportImageType, strings.ToLower(imageType)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadImageInfo 读取一般图片文件信息
|
||||||
|
func ReadImageInfo(filePath string) (err error, width int, height int) {
|
||||||
|
file, err := os.Open(filePath) // 图片文件路径
|
||||||
|
if err != nil {
|
||||||
|
return err, 0, 0
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
img, _, err := image.DecodeConfig(file)
|
||||||
|
if err != nil {
|
||||||
|
return err, 0, 0
|
||||||
|
}
|
||||||
|
return nil, img.Width, img.Height
|
||||||
|
}
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
package util
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/gabriel-vasile/mimetype"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// CheckFileIsExist 判断文件是否存在,存在返回 true,不存在返回false
|
|
||||||
func CheckFileIsExist(filename string) bool {
|
|
||||||
var exist = true
|
|
||||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
|
||||||
exist = false
|
|
||||||
}
|
|
||||||
return exist
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteByteArraysToFile 写字节数组到文件
|
|
||||||
func WriteByteArraysToFile(content []byte, filename string) error {
|
|
||||||
return ioutil.WriteFile(filename, content, 0777)
|
|
||||||
}
|
|
||||||
|
|
||||||
// String2int 字符串转int
|
|
||||||
func String2int(str string) int {
|
|
||||||
intValue, err := strconv.Atoi(str)
|
|
||||||
if err != nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return intValue
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateDir 创建目录
|
|
||||||
func CreateDir(dirPath string) bool {
|
|
||||||
err := os.Mkdir(dirPath, 0755)
|
|
||||||
return err == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadFileMimeInfo 获取文件mime信息
|
|
||||||
func ReadFileMimeInfo(filepath string) *mimetype.MIME {
|
|
||||||
mt, err := mimetype.DetectFile(filepath)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
return mt
|
|
||||||
}
|
|
||||||
|
|
||||||
// SecondsToHms 将秒数转换为小时、分钟、秒的格式
|
|
||||||
func SecondsToHms(seconds int) string {
|
|
||||||
t := time.Duration(seconds) * time.Second
|
|
||||||
h := t / time.Hour
|
|
||||||
t -= h * time.Hour
|
|
||||||
m := t / time.Minute
|
|
||||||
t -= m * time.Minute
|
|
||||||
s := t / time.Second
|
|
||||||
return fmt.Sprintf("%02d-%02d-%02d", h, m, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CalcPercentage 计算percentage相对于total的百分比
|
|
||||||
func CalcPercentage(percentage int, total int) int {
|
|
||||||
return int(float64(percentage) / float64(total) * 100)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取文件所在文件夹
|
|
||||||
func GetFileDirectory(filePath string) string {
|
|
||||||
directoryPath, _ := filepath.Split(filePath)
|
|
||||||
return directoryPath
|
|
||||||
}
|
|
||||||
+158
@@ -0,0 +1,158 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"github.com/redmask-hb/GoSimplePrint/goPrint"
|
||||||
|
"math"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var supportVideoTypes = []string{
|
||||||
|
".ts",
|
||||||
|
".flv",
|
||||||
|
".rm",
|
||||||
|
".avi",
|
||||||
|
".mp4",
|
||||||
|
".mov",
|
||||||
|
".mpg",
|
||||||
|
".mkv",
|
||||||
|
".m4v",
|
||||||
|
".rmvb",
|
||||||
|
".3gp",
|
||||||
|
".3g2",
|
||||||
|
".webm",
|
||||||
|
".wmv",
|
||||||
|
}
|
||||||
|
|
||||||
|
func getVideoDuration(ffmpegExecPath string, videoPath string) (float64, error) {
|
||||||
|
// ffprobe命令,-v error 用于减少输出信息,-show_entries format=duration -of compact=p=0,nk=1 用于只输出时长
|
||||||
|
cmd := exec.Command(ffmpegExecPath, "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", videoPath)
|
||||||
|
var stderr bytes.Buffer
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("ffprobe failed with error: %v, stderr: %q", err, stderr.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析输出的时长字符串为浮点数
|
||||||
|
durationStr := strings.TrimSpace(string(output))
|
||||||
|
duration, err := strconv.ParseFloat(durationStr, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("failed to parse duration: %q, error: %v", durationStr, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return duration, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getVideoResolution(ffmpegExecPath string, filePath string) (width int, height int, err error) {
|
||||||
|
// 构建ffprobe命令
|
||||||
|
cmd := exec.Command(ffmpegExecPath, "-v", "error", "-show_entries", "stream=width,height", "-of", "csv=p=0:s=x", filePath)
|
||||||
|
// 执行命令并捕获输出
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, fmt.Errorf("failed to run ffprobe: %w", err)
|
||||||
|
}
|
||||||
|
// 解析输出字符串,格式应为 "宽度,高度"
|
||||||
|
resolutionStr := strings.TrimSpace(string(output))
|
||||||
|
parts := strings.Split(resolutionStr, ",")
|
||||||
|
if len(parts) == 2 {
|
||||||
|
width = String2int(parts[0])
|
||||||
|
height = String2int(parts[1])
|
||||||
|
return width, height, nil
|
||||||
|
}
|
||||||
|
parts = strings.Split(resolutionStr, "x")
|
||||||
|
if len(parts) == 2 {
|
||||||
|
width = String2int(parts[0])
|
||||||
|
height = String2int(parts[1])
|
||||||
|
return width, height, nil
|
||||||
|
}
|
||||||
|
parts = strings.Split(resolutionStr, "\r\n\r\n\r\n\r\n")
|
||||||
|
if len(parts) == 2 {
|
||||||
|
tempHw := parts[0]
|
||||||
|
parts = strings.Split(tempHw, "x")
|
||||||
|
if len(parts) == 2 {
|
||||||
|
width = String2int(parts[0])
|
||||||
|
height = String2int(parts[1])
|
||||||
|
return width, height, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parts = strings.Split(resolutionStr, "x")
|
||||||
|
if len(parts) == 3 {
|
||||||
|
width = String2int(parts[0])
|
||||||
|
height = String2int(parts[1])
|
||||||
|
return width, height, nil
|
||||||
|
}
|
||||||
|
resolutionStr = strings.ReplaceAll(resolutionStr, "\r", "")
|
||||||
|
resolutionStr = strings.ReplaceAll(resolutionStr, "\n", "")
|
||||||
|
resolutionStr = strings.ReplaceAll(resolutionStr, "N/AxN/A", "")
|
||||||
|
parts = strings.Split(resolutionStr, "x")
|
||||||
|
if len(parts) == 2 {
|
||||||
|
width = String2int(parts[0])
|
||||||
|
height = String2int(parts[1])
|
||||||
|
return width, height, nil
|
||||||
|
}
|
||||||
|
return 0, 0, fmt.Errorf("invalid resolution format: %s", resolutionStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadVideoDuration 获取视频的时长,单位秒
|
||||||
|
func ReadVideoDuration(videoFilePath string) int {
|
||||||
|
duration, err := getVideoDuration("./ffprobe.exe", videoFilePath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("=== Error getting video duration:", err)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
//fmt.Printf("=== Video duration: %.2f seconds\n", duration)
|
||||||
|
return int(math.Floor(duration)) // 向下取整
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadVideoWidthHeight 获取视频的分辨率
|
||||||
|
func ReadVideoWidthHeight(videoFilePath string) (int, int, error) {
|
||||||
|
width, height, err := getVideoResolution("./ffprobe.exe", videoFilePath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("=== Error getting resolution: %v\n", err)
|
||||||
|
return 0, 0, err
|
||||||
|
}
|
||||||
|
//fmt.Printf("=== Video resolution: %dx%d\n", width, height)
|
||||||
|
return width, height, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsSupportVideo 判断是否属于支持的视频
|
||||||
|
func IsSupportVideo(videoType string) bool {
|
||||||
|
for _, supportVideoType := range supportVideoTypes {
|
||||||
|
if strings.EqualFold(videoType, supportVideoType) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoMoveFileToDir 批量移动文件到目录
|
||||||
|
func DoMoveFileToDir(filePathList []string, videoDirPath string) {
|
||||||
|
total := len(filePathList)
|
||||||
|
var count = 0
|
||||||
|
bar := goPrint.NewBar(100)
|
||||||
|
bar.SetNotice("=== 移动文件到目录:")
|
||||||
|
bar.SetGraph(">")
|
||||||
|
pathSeparator := string(os.PathSeparator)
|
||||||
|
for _, videoFilePath := range filePathList {
|
||||||
|
moveFileToDir(videoFilePath, videoDirPath+pathSeparator)
|
||||||
|
count = count + 1
|
||||||
|
bar.PrintBar(CalcPercentage(count, total))
|
||||||
|
}
|
||||||
|
bar.PrintEnd("=== Finish")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移动文件到目录
|
||||||
|
func moveFileToDir(sourceFilePath string, targetDirectory string) bool {
|
||||||
|
splits := strings.Split(sourceFilePath, string(os.PathSeparator))
|
||||||
|
fileName := splits[len(splits)-1]
|
||||||
|
targetFilePath := targetDirectory + fileName
|
||||||
|
err := os.Rename(sourceFilePath, targetFilePath)
|
||||||
|
//fmt.Printf("=== 移动文件, 源: %s, 目标: %s \n", sourceFilePath, targetFilePath)
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
LFS
BIN
Binary file not shown.
@@ -0,0 +1,51 @@
|
|||||||
|
package vars
|
||||||
|
|
||||||
|
var ImageIgnorePathList []string // 忽略的文件路径
|
||||||
|
var ImageReadErrorPathList []string // 读取信息异常的路径
|
||||||
|
var ImagePath2WidthHeightMap = make(map[string]string) // 图片路径和宽高比
|
||||||
|
var ImageGifList []string
|
||||||
|
var ImagePsdList []string
|
||||||
|
var ImageHorizontalNormalList []string
|
||||||
|
var ImageHorizontal1KList []string
|
||||||
|
var ImageHorizontal2KList []string
|
||||||
|
var ImageHorizontal3KList []string
|
||||||
|
var ImageHorizontal4KList []string
|
||||||
|
var ImageHorizontal5KList []string
|
||||||
|
var ImageHorizontal6KList []string
|
||||||
|
var ImageHorizontal7KList []string
|
||||||
|
var ImageHorizontal8KList []string
|
||||||
|
var ImageHorizontal9KList []string
|
||||||
|
var ImageHorizontalHKList []string
|
||||||
|
var ImageHorizontalStandard720PList []string
|
||||||
|
var ImageHorizontalStandard1D5KList []string
|
||||||
|
var ImageHorizontalStandard1080PList []string
|
||||||
|
var ImageHorizontalStandard2DKList []string
|
||||||
|
var ImageHorizontalStandard2D5KList []string
|
||||||
|
var ImageHorizontalStandardUltraWide2List []string
|
||||||
|
var ImageHorizontalStandardUltraWide3List []string
|
||||||
|
var ImageHorizontalStandardUltraWide4List []string
|
||||||
|
var ImageHorizontalStandard4KList []string
|
||||||
|
var ImageHorizontalStandard4KHList []string
|
||||||
|
var ImageHorizontalStandard8KList []string
|
||||||
|
var ImageVerticalNormalList []string
|
||||||
|
var ImageVertical1KList []string
|
||||||
|
var ImageVertical2KList []string
|
||||||
|
var ImageVertical3KList []string
|
||||||
|
var ImageVertical4KList []string
|
||||||
|
var ImageVertical5KList []string
|
||||||
|
var ImageVertical6KList []string
|
||||||
|
var ImageVertical7KList []string
|
||||||
|
var ImageVertical8KList []string
|
||||||
|
var ImageVertical9KList []string
|
||||||
|
var ImageVerticalHKList []string
|
||||||
|
var ImageSquareNormalList []string
|
||||||
|
var ImageSquare1KList []string
|
||||||
|
var ImageSquare2KList []string
|
||||||
|
var ImageSquare3KList []string
|
||||||
|
var ImageSquare4KList []string
|
||||||
|
var ImageSquare5KList []string
|
||||||
|
var ImageSquare6KList []string
|
||||||
|
var ImageSquare7KList []string
|
||||||
|
var ImageSquare8KList []string
|
||||||
|
var ImageSquare9KList []string
|
||||||
|
var ImageSquareHKList []string
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package vars
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "embed" // 内嵌文件支持
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed ffprobe.exe
|
||||||
|
var VideoDecodeToolWin64 []byte
|
||||||
|
var VideoIgnorePathList []string // 忽略的文件路径
|
||||||
|
var VideoReadErrorPathList []string // 读取信息异常的路径
|
||||||
|
var VideoPath2WidthHeightMap = make(map[string]string) // 视频路径和宽高比
|
||||||
|
var VideoPath2WidthHeightTagMap = make(map[string]string) // 视频路径和宽高比[640x480]
|
||||||
|
var VideoPath2DurationMap = make(map[string]string) // 视频路径和时长
|
||||||
|
var VideoHorizontalNormalList []string
|
||||||
|
var VideoHorizontalGifList []string
|
||||||
|
var VideoHorizontal1KList []string
|
||||||
|
var VideoHorizontal2KList []string
|
||||||
|
var VideoHorizontal3KList []string
|
||||||
|
var VideoHorizontal4KList []string
|
||||||
|
var VideoHorizontal5KList []string
|
||||||
|
var VideoHorizontal6KList []string
|
||||||
|
var VideoHorizontal7KList []string
|
||||||
|
var VideoHorizontal8KList []string
|
||||||
|
var VideoHorizontal9KList []string
|
||||||
|
var VideoHorizontalHKList []string
|
||||||
|
var VideoHorizontalStandard720PList []string
|
||||||
|
var VideoHorizontalStandard1D5PList []string
|
||||||
|
var VideoHorizontalStandard1080PList []string
|
||||||
|
var VideoHorizontalStandard2DKList []string
|
||||||
|
var VideoHorizontalStandard2D5KList []string
|
||||||
|
var VideoHorizontalStandardUltraWide2List []string
|
||||||
|
var VideoHorizontalStandardUltraWide3List []string
|
||||||
|
var VideoHorizontalStandardUltraWide4List []string
|
||||||
|
var VideoHorizontalStandard4KList []string
|
||||||
|
var VideoHorizontalStandard4KHList []string
|
||||||
|
var VideoHorizontalStandard8KList []string
|
||||||
|
var VideoVerticalNormalList []string
|
||||||
|
var VideoVerticalGifList []string
|
||||||
|
var VideoVertical1KList []string
|
||||||
|
var VideoVertical2KList []string
|
||||||
|
var VideoVertical3KList []string
|
||||||
|
var VideoVertical4KList []string
|
||||||
|
var VideoVertical5KList []string
|
||||||
|
var VideoVertical6KList []string
|
||||||
|
var VideoVertical7KList []string
|
||||||
|
var VideoVertical8KList []string
|
||||||
|
var VideoVertical9KList []string
|
||||||
|
var VideoVerticalHKList []string
|
||||||
|
var VideoSquareNormalList []string
|
||||||
|
var VideoSquareGifList []string
|
||||||
|
var VideoSquare1KList []string
|
||||||
|
var VideoSquare2KList []string
|
||||||
|
var VideoSquare3KList []string
|
||||||
|
var VideoSquare4KList []string
|
||||||
|
var VideoSquare5KList []string
|
||||||
|
var VideoSquare6KList []string
|
||||||
|
var VideoSquare7KList []string
|
||||||
|
var VideoSquare8KList []string
|
||||||
|
var VideoSquare9KList []string
|
||||||
|
var VideoSquareHKList []string
|
||||||
Reference in New Issue
Block a user