Compare commits

..

3 Commits

4 changed files with 187 additions and 299 deletions

86
LICENSE
View File

@ -1,73 +1,21 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
MIT License
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
Copyright (c) 2024 Odboy
1. Definitions.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
Copyright 2024 odboy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Binary file not shown.

View File

@ -28,7 +28,6 @@ var supportImageTypes = []string{
// 水平图片
var normalImageList []string
var horizontalUnHandleImageList []string
var horizontalGifImageList []string
var horizontal2KImageList []string
var horizontal1KImageList []string
@ -44,14 +43,11 @@ var horizontalHKImageList []string
// 标准横向图片
var horizontalStandard720PImageList []string
var horizontalStandard1080PImageList []string
var horizontalStandard2KImageList []string
var horizontalStandard4KImageList []string
var horizontalStandard5KImageList []string
var horizontalStandard8KImageList []string
// 垂直图片
var verticalGifImageList []string
var verticalUnHandleImageList []string
var vertical1KImageList []string
var vertical2KImageList []string
var vertical3KImageList []string
@ -64,7 +60,6 @@ var vertical9KImageList []string
var verticalHKImageList []string
// 等比图片
var squareUnHandleImageList []string
var squareGifImageList []string
var square1KImageList []string
var square2KImageList []string
@ -76,6 +71,13 @@ var square7KImageList []string
var square8KImageList []string
var square9KImageList []string
var squareHKImageList []string
// 标准等比图片
var squareStandard720PImageList []string
var squareStandard1080PImageList []string
var squareStandard4KImageList []string
var squareStandard8KImageList []string
var psdImageList []string
func DoHandleImage(rootDir string) {
@ -171,7 +173,7 @@ func doPickImageFile(uid string, rootDir string, imagePath2WidthHeightMap map[st
handleVerticalImage(currentImagePath, height, suffix)
continue
}
handleSquareImage(currentImagePath, width, suffix)
handleSquareImage(currentImagePath, width, height, suffix)
}
moveNormalImage(rootDir, uid)
moveHorizontalImage(rootDir, uid)
@ -181,7 +183,6 @@ func doPickImageFile(uid string, rootDir string, imagePath2WidthHeightMap map[st
func moveSquareImage(rootDir string, uid string) {
pathSeparator := string(os.PathSeparator)
squareUnHandleImagePath := rootDir + pathSeparator + uid + "_图片_等比_未处理"
squareGifImagePath := rootDir + pathSeparator + uid + "_图片_等比_GIF"
square1KImagePath := rootDir + pathSeparator + uid + "_图片_等比_1k"
square2KImagePath := rootDir + pathSeparator + uid + "_图片_等比_2k"
@ -193,10 +194,6 @@ func moveSquareImage(rootDir string, uid string) {
square8KImagePath := rootDir + pathSeparator + uid + "_图片_等比_8k"
square9KImagePath := rootDir + pathSeparator + uid + "_图片_等比_9k"
squareHKImagePath := rootDir + pathSeparator + uid + "_图片_等比_原图"
if len(squareUnHandleImageList) > 0 {
util.CreateDir(squareUnHandleImagePath)
doMoveFileToDir(squareUnHandleImageList, squareUnHandleImagePath)
}
if len(squareGifImageList) > 0 {
util.CreateDir(squareGifImagePath)
doMoveFileToDir(squareGifImageList, squareGifImagePath)
@ -243,36 +240,53 @@ func moveSquareImage(rootDir string, uid string) {
}
}
func handleSquareImage(currentImagePath string, width int, suffix string) {
func handleSquareImage(currentImagePath string, width int, height int, suffix string) {
if strings.EqualFold(suffix, ".gif") {
squareGifImageList = append(squareGifImageList, currentImagePath)
return
}
if width < caleHorizontalPix(1) {
if width < 1000 {
normalImageList = append(normalImageList, currentImagePath)
} else if width >= caleHorizontalPix(1) && width < caleHorizontalPix(2) {
} else if width >= 1000 && width < 2000 {
// 1280 x 720 -> 720p
if width == 1280 && height == 720 {
squareStandard720PImageList = append(squareStandard720PImageList, currentImagePath)
return
}
// 1920 x 1080 -> 1080p
if width == 1920 && height == 1080 {
squareStandard1080PImageList = append(squareStandard1080PImageList, currentImagePath)
return
}
square1KImageList = append(square1KImageList, currentImagePath)
} else if width >= caleHorizontalPix(2) && width < caleHorizontalPix(3) {
} else if width >= 2000 && width < 3000 {
square2KImageList = append(square2KImageList, currentImagePath)
} else if width >= caleHorizontalPix(3) && width < caleHorizontalPix(4) {
} else if width >= 3000 && width < 4000 {
// 3840 x 2160 -> 4k
if width == 3840 && height == 2160 {
squareStandard4KImageList = append(squareStandard4KImageList, currentImagePath)
return
}
square3KImageList = append(square3KImageList, currentImagePath)
} else if width >= caleHorizontalPix(4) && width < caleHorizontalPix(5) {
} else if width >= 4000 && width < 5000 {
square4KImageList = append(square4KImageList, currentImagePath)
} else if width >= caleHorizontalPix(5) && width < caleHorizontalPix(6) {
} else if width >= 5000 && width < 6000 {
square5KImageList = append(square5KImageList, currentImagePath)
} else if width >= caleHorizontalPix(6) && width < caleHorizontalPix(7) {
} else if width >= 6000 && width < 7000 {
square6KImageList = append(square6KImageList, currentImagePath)
} else if width >= caleHorizontalPix(7) && width < caleHorizontalPix(8) {
} else if width >= 7000 && width < 8000 {
// 7680 x 4320 -> 8k
if width == 7680 && height == 4320 {
squareStandard8KImageList = append(squareStandard8KImageList, currentImagePath)
return
}
square7KImageList = append(square7KImageList, currentImagePath)
} else if width >= caleHorizontalPix(8) && width < caleHorizontalPix(9) {
} else if width >= 8000 && width < 9000 {
square8KImageList = append(square8KImageList, currentImagePath)
} else if width >= caleHorizontalPix(9) && width < caleHorizontalPix(10) {
} else if width >= 9000 && width < 10000 {
square9KImageList = append(square9KImageList, currentImagePath)
} else if width >= caleHorizontalPix(10) {
} else if width >= 10000 {
squareHKImageList = append(squareHKImageList, currentImagePath)
} else {
// 未处理的等比图片
squareUnHandleImageList = append(squareUnHandleImageList, currentImagePath)
}
}
@ -280,7 +294,6 @@ func handleSquareImage(currentImagePath string, width int, suffix string) {
func moveVerticalImage(rootDir string, uid string) {
pathSeparator := string(os.PathSeparator)
verticalGifImagePath := rootDir + pathSeparator + uid + "_图片_竖屏_GIF"
verticalUnHandleImagePath := rootDir + pathSeparator + uid + "_图片_竖屏_未处理"
vertical1KImagePath := rootDir + pathSeparator + uid + "_图片_竖屏_1k"
vertical2KImagePath := rootDir + pathSeparator + uid + "_图片_竖屏_2k"
vertical3KImagePath := rootDir + pathSeparator + uid + "_图片_竖屏_3k"
@ -295,10 +308,6 @@ func moveVerticalImage(rootDir string, uid string) {
util.CreateDir(verticalGifImagePath)
doMoveFileToDir(verticalGifImageList, verticalGifImagePath)
}
if len(verticalUnHandleImageList) > 0 {
util.CreateDir(verticalUnHandleImagePath)
doMoveFileToDir(verticalUnHandleImageList, verticalUnHandleImagePath)
}
if len(vertical1KImageList) > 0 {
util.CreateDir(vertical1KImagePath)
doMoveFileToDir(vertical1KImageList, vertical1KImagePath)
@ -344,7 +353,6 @@ func moveVerticalImage(rootDir string, uid string) {
// 移动水平图片
func moveHorizontalImage(rootDir string, uid string) {
pathSeparator := string(os.PathSeparator)
horizontalUnHandleImagePath := rootDir + pathSeparator + uid + "_图片_横屏_未处理"
horizontalGifImagePath := rootDir + pathSeparator + uid + "_图片_横屏_GIF"
horizontal1KImagePath := rootDir + pathSeparator + uid + "_图片_横屏_1k"
horizontal2KImagePath := rootDir + pathSeparator + uid + "_图片_横屏_2k"
@ -358,14 +366,8 @@ func moveHorizontalImage(rootDir string, uid string) {
horizontalHKImagePath := rootDir + pathSeparator + uid + "_图片_横屏_原图"
horizontalStandard720PImagePath := rootDir + pathSeparator + uid + "_图片_横屏_720P"
horizontalStandard1080PImagePath := rootDir + pathSeparator + uid + "_图片_横屏_1080P"
horizontalStandard2KImagePath := rootDir + pathSeparator + uid + "_图片_横屏_2KP"
horizontalStandard4KImagePath := rootDir + pathSeparator + uid + "_图片_横屏_4KP"
horizontalStandard5KImagePath := rootDir + pathSeparator + uid + "_图片_横屏_5KP"
horizontalStandard8KImagePath := rootDir + pathSeparator + uid + "_图片_横屏_8KP"
if len(horizontalUnHandleImageList) > 0 {
util.CreateDir(horizontalUnHandleImagePath)
doMoveFileToDir(horizontalUnHandleImageList, horizontalUnHandleImagePath)
}
if len(horizontalGifImageList) > 0 {
util.CreateDir(horizontalGifImagePath)
doMoveFileToDir(horizontalGifImageList, horizontalGifImagePath)
@ -418,18 +420,10 @@ func moveHorizontalImage(rootDir string, uid string) {
util.CreateDir(horizontalStandard1080PImagePath)
doMoveFileToDir(horizontalStandard1080PImageList, horizontalStandard1080PImagePath)
}
if len(horizontalStandard2KImageList) > 0 {
util.CreateDir(horizontalStandard2KImagePath)
doMoveFileToDir(horizontalStandard2KImageList, horizontalStandard2KImagePath)
}
if len(horizontalStandard4KImageList) > 0 {
util.CreateDir(horizontalStandard4KImagePath)
doMoveFileToDir(horizontalStandard4KImageList, horizontalStandard4KImagePath)
}
if len(horizontalStandard5KImageList) > 0 {
util.CreateDir(horizontalStandard5KImagePath)
doMoveFileToDir(horizontalStandard5KImageList, horizontalStandard5KImagePath)
}
if len(horizontalStandard8KImageList) > 0 {
util.CreateDir(horizontalStandard8KImagePath)
doMoveFileToDir(horizontalStandard8KImageList, horizontalStandard8KImagePath)
@ -452,31 +446,28 @@ func handleVerticalImage(currentImagePath string, height int, suffix string) {
verticalGifImageList = append(verticalGifImageList, currentImagePath)
return
}
if height < caleVerticalPix(1) {
if height < 1000 {
normalImageList = append(normalImageList, currentImagePath)
} else if height >= caleVerticalPix(1) && height < caleVerticalPix(2) {
} else if height >= 1000 && height < 2000 {
vertical1KImageList = append(vertical1KImageList, currentImagePath)
} else if height >= caleVerticalPix(2) && height < caleVerticalPix(3) {
} else if height >= 2000 && height < 3000 {
vertical2KImageList = append(vertical2KImageList, currentImagePath)
} else if height >= caleVerticalPix(3) && height < caleVerticalPix(4) {
} else if height >= 3000 && height < 4000 {
vertical3KImageList = append(vertical3KImageList, currentImagePath)
} else if height >= caleVerticalPix(4) && height < caleVerticalPix(5) {
} else if height >= 4000 && height < 5000 {
vertical4KImageList = append(vertical4KImageList, currentImagePath)
} else if height >= caleVerticalPix(5) && height < caleVerticalPix(6) {
} else if height >= 5000 && height < 6000 {
vertical5KImageList = append(vertical5KImageList, currentImagePath)
} else if height >= caleVerticalPix(6) && height < caleVerticalPix(7) {
} else if height >= 6000 && height < 7000 {
vertical6KImageList = append(vertical6KImageList, currentImagePath)
} else if height >= caleVerticalPix(7) && height < caleVerticalPix(8) {
} else if height >= 7000 && height < 8000 {
vertical7KImageList = append(vertical7KImageList, currentImagePath)
} else if height >= caleVerticalPix(8) && height < caleVerticalPix(9) {
} else if height >= 8000 && height < 9000 {
vertical8KImageList = append(vertical8KImageList, currentImagePath)
} else if height >= caleVerticalPix(9) && height < caleVerticalPix(10) {
} else if height >= 9000 && height < 10000 {
vertical9KImageList = append(vertical9KImageList, currentImagePath)
} else if height >= caleVerticalPix(10) {
} else if height >= 10000 {
verticalHKImageList = append(verticalHKImageList, currentImagePath)
} else {
// 未处理的垂直图片
verticalUnHandleImageList = append(verticalUnHandleImageList, currentImagePath)
}
}
@ -486,9 +477,9 @@ func handleHorizontalImage(currentImagePath string, width int, height int, suffi
horizontalGifImageList = append(horizontalGifImageList, currentImagePath)
return
}
if width < caleHorizontalPix(1) {
if width < 1000 {
normalImageList = append(normalImageList, currentImagePath)
} else if width >= caleHorizontalPix(1) && width < caleHorizontalPix(2) {
} else if width >= 1000 && width < 2000 {
// 1280 x 720 -> 720p
if width == 1280 && height == 720 {
horizontalStandard720PImageList = append(horizontalStandard720PImageList, currentImagePath)
@ -500,47 +491,34 @@ func handleHorizontalImage(currentImagePath string, width int, height int, suffi
return
}
horizontal1KImageList = append(horizontal1KImageList, currentImagePath)
} else if width >= caleHorizontalPix(2) && width < caleHorizontalPix(3) {
// 2560 x 1440 -> 2k
if width == 2560 && height == 1440 {
horizontalStandard2KImageList = append(horizontalStandard2KImageList, currentImagePath)
return
}
} else if width >= 2000 && width < 3000 {
horizontal2KImageList = append(horizontal2KImageList, currentImagePath)
} else if width >= caleHorizontalPix(3) && width < caleHorizontalPix(4) {
} else if width >= 3000 && width < 4000 {
// 3840 x 2160 -> 4k
if width == 3840 && height == 2160 {
horizontalStandard4KImageList = append(horizontalStandard4KImageList, currentImagePath)
return
}
horizontal3KImageList = append(horizontal3KImageList, currentImagePath)
} else if width >= caleHorizontalPix(4) && width < caleHorizontalPix(5) {
} else if width >= 4000 && width < 5000 {
horizontal4KImageList = append(horizontal4KImageList, currentImagePath)
} else if width >= caleHorizontalPix(5) && width < caleHorizontalPix(6) {
// 5120 x 2880 -> 5k
if width == 5120 && height == 2880 {
horizontalStandard5KImageList = append(horizontalStandard5KImageList, currentImagePath)
return
}
} else if width >= 5000 && width < 6000 {
horizontal5KImageList = append(horizontal5KImageList, currentImagePath)
} else if width >= caleHorizontalPix(6) && width < caleHorizontalPix(7) {
} else if width >= 6000 && width < 7000 {
horizontal6KImageList = append(horizontal6KImageList, currentImagePath)
} else if width >= caleHorizontalPix(7) && width < caleHorizontalPix(8) {
} else if width >= 7000 && width < 8000 {
// 7680 x 4320 -> 8k
if width == 7680 && height == 4320 {
horizontalStandard8KImageList = append(horizontalStandard8KImageList, currentImagePath)
return
}
horizontal7KImageList = append(horizontal7KImageList, currentImagePath)
} else if width >= caleHorizontalPix(8) && width < caleHorizontalPix(9) {
} else if width >= 8000 && width < 9000 {
horizontal8KImageList = append(horizontal8KImageList, currentImagePath)
} else if width >= caleHorizontalPix(9) && width < caleHorizontalPix(10) {
} else if width >= 9000 && width < 10000 {
horizontal9KImageList = append(horizontal9KImageList, currentImagePath)
} else if width >= caleHorizontalPix(10) {
} else if width >= 10000 {
horizontalHKImageList = append(horizontalHKImageList, currentImagePath)
} else {
// 未分类的横向图片
horizontalUnHandleImageList = append(horizontalUnHandleImageList, currentImagePath)
}
}

View File

@ -10,7 +10,6 @@ import (
"math"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"time"
@ -19,7 +18,7 @@ import (
//go:embed files/ffprobe.exe
var ffprobeWin64 []byte
var videoTag = "_[PickVideo]" // 标记文件已经被整理过
var videoTag = "[PickVideo]" // 标记文件已经被整理过
var ignoreVideoPathList []string // 忽略的文件路径
var readErrorVideoPathList []string // 读取信息异常的路径
var videoPath2WidthHeightMap = make(map[string]string) // 视频路径和宽高比
@ -45,9 +44,7 @@ var supportVideoTypes = []string{
// 水平视频
var horizontalNormalVideoList []string
var horizontalUnHandleVideoList []string
var horizontalGifVideoList []string
var horizontal1KVideoList []string
var horizontal2KVideoList []string
var horizontal3KVideoList []string
@ -62,9 +59,7 @@ var horizontalHKVideoList []string
// 标准横向视频
var horizontalStandard720PVideoList []string
var horizontalStandard1080PVideoList []string
var horizontalStandard2KVideoList []string
var horizontalStandard4KVideoList []string
var horizontalStandard5KVideoList []string
var horizontalStandard8KVideoList []string
// 垂直视频
@ -80,7 +75,6 @@ var vertical7KVideoList []string
var vertical8KVideoList []string
var vertical9KVideoList []string
var verticalHKVideoList []string
var verticalUnHandleVideoList []string
// 等比视频
var squareNormalVideoList []string
@ -95,7 +89,10 @@ var square7KVideoList []string
var square8KVideoList []string
var square9KVideoList []string
var squareHKVideoList []string
var squareUnHandleVideoList []string
var squareStandard720PVideoList []string
var squareStandard1080PVideoList []string
var squareStandard4KVideoList []string
var squareStandard8KVideoList []string
func DoHandleVideo(rootDir string) {
// 释放ffprobe
@ -124,7 +121,7 @@ func DoHandleVideo(rootDir string) {
fmt.Printf("=== Video总数: %d, 已读取Info: %d, 成功数: %d, 失败数: %d \n", total, successCount+errorCount+ignoreCount, successCount, errorCount)
duration := readVideoDuration(videoFilePath)
if duration == 0 {
videoPath2DurationMap[videoFilePath] = "00-00-00"
videoPath2DurationMap[videoFilePath] = "0H0M0S"
} else {
videoPath2DurationMap[videoFilePath] = util.SecondsToHms(duration)
}
@ -307,49 +304,40 @@ func moveVerticalVideo(rootDir string) {
if len(verticalHKVideoList) > 0 {
renameFileV2("[V][原]", verticalHKVideoList)
}
if len(verticalUnHandleVideoList) > 0 {
renameFileV2("[V][UnHandle]", verticalUnHandleVideoList)
}
}
// 移动文件到根目录
//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[0]
// split := strings.Split(fileName, pathSeparator)
// if len(split) > 0 {
// realFileName := split[len(split)-1]
// //targetFilePath := rootDir + pathSeparator + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + fileName
// targetFilePath := rootDir + pathSeparator + realFileName + videoTag + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh
// err := os.Rename(videoFilePath, targetFilePath)
// if err != nil {
// fmt.Printf("=== 重命名异常: %s \n", videoFilePath)
// }
// }
// }
// } else {
// //targetFilePath := rootDir + pathSeparator + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + " - " + fileName
// targetFilePath := rootDir + pathSeparator + fileName + videoTag + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh
// 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 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) {
@ -362,41 +350,18 @@ func renameFileV2(modelType string, videoList []string) {
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[0]
// split := strings.Split(fileName, string(os.PathSeparator))
// if len(split) > 0 {
// realFileName := split[len(split)-1]
// //targetFilePath := filePath + "[" + videoPath2DurationMap[videoFilePath] + "]" + modelType + wh + videoTag + fileName
// ext := filepath.Ext(fileNames[1])
// lowExt := strings.ToLower(ext)
// header := strings.ReplaceAll(realFileName, ext, "")
// 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
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)
@ -446,21 +411,12 @@ func moveHorizontalVideo(rootDir string) {
if len(horizontalStandard1080PVideoList) > 0 {
renameFileV2("[H][1080P]", horizontalStandard1080PVideoList)
}
if len(horizontalStandard2KVideoList) > 0 {
renameFileV2("[H][2KP]", horizontalStandard2KVideoList)
}
if len(horizontalStandard4KVideoList) > 0 {
renameFileV2("[H][4KP]", horizontalStandard4KVideoList)
}
if len(horizontalStandard5KVideoList) > 0 {
renameFileV2("[H][5KP]", horizontalStandard5KVideoList)
}
if len(horizontalStandard8KVideoList) > 0 {
renameFileV2("[H][8KP]", horizontalStandard8KVideoList)
}
if len(horizontalUnHandleVideoList) > 0 {
renameFileV2("[H][UnHandle]", horizontalUnHandleVideoList)
}
}
// 移动等比视频
@ -495,8 +451,17 @@ func moveSquareVideo(rootDir string) {
if len(squareHKVideoList) > 0 {
renameFileV2("[M][原]", squareHKVideoList)
}
if len(squareUnHandleVideoList) > 0 {
renameFileV2("[M][UnHandle]", squareUnHandleVideoList)
if len(squareStandard720PVideoList) > 0 {
renameFileV2("[M][720P]", squareStandard720PVideoList)
}
if len(squareStandard1080PVideoList) > 0 {
renameFileV2("[M][1080P]", squareStandard1080PVideoList)
}
if len(squareStandard4KVideoList) > 0 {
renameFileV2("[M][4KP]", squareStandard4KVideoList)
}
if len(squareStandard8KVideoList) > 0 {
renameFileV2("[M][8KP]", squareStandard8KVideoList)
}
}
@ -504,6 +469,7 @@ func moveSquareVideo(rootDir string) {
func moveNormalVideo(rootDir string) {
//pathSeparator := string(os.PathSeparator)
if len(horizontalNormalVideoList) > 0 {
//renameFile(rootDir, "[L]", horizontalNormalVideoList, pathSeparator)
renameFileV2("[L]", horizontalNormalVideoList)
}
if len(verticalNormalVideoList) > 0 {
@ -542,31 +508,23 @@ func handleVerticalVideo(currentVideoPath string, height int, suffix string) {
vertical9KVideoList = append(vertical9KVideoList, currentVideoPath)
} else if height >= 10000 {
verticalHKVideoList = append(verticalHKVideoList, currentVideoPath)
} else {
// 未分类的垂直视频
verticalUnHandleVideoList = append(verticalUnHandleVideoList, currentVideoPath)
}
}
// 计算水平分辨率
func caleHorizontalPix(level int) int {
return 1024 * level
}
// 计算垂直分辨率
func caleVerticalPix(level int) int {
return 768 * level
}
// 处理横向视频
func handleHorizontalVideo(currentVideoPath string, width int, height int, suffix string) {
if strings.EqualFold(suffix, ".gif") {
horizontalGifVideoList = append(horizontalGifVideoList, currentVideoPath)
return
}
if width < caleHorizontalPix(1) {
if width < 1000 {
// 160 × 120
// 320 × 180
// 320 × 240
// 640 × 360
// 640 × 480
horizontalNormalVideoList = append(horizontalNormalVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(1) && width < caleHorizontalPix(2) {
} else if width >= 1000 && width < 2000 {
// 1280 x 720 -> 720p
if width == 1280 && height == 720 {
horizontalStandard720PVideoList = append(horizontalStandard720PVideoList, currentVideoPath)
@ -578,47 +536,34 @@ func handleHorizontalVideo(currentVideoPath string, width int, height int, suffi
return
}
horizontal1KVideoList = append(horizontal1KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(2) && width < caleHorizontalPix(3) {
// 2560 x 1440 -> 2k
if width == 2560 && height == 1440 {
horizontalStandard2KVideoList = append(horizontalStandard2KVideoList, currentVideoPath)
return
}
} else if width >= 2000 && width < 3000 {
horizontal2KVideoList = append(horizontal2KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(3) && width < caleHorizontalPix(4) {
} else if width >= 3000 && width < 4000 {
// 3840 x 2160 -> 4k
if width == 3840 && height == 2160 {
horizontalStandard4KVideoList = append(horizontalStandard4KVideoList, currentVideoPath)
return
}
horizontal3KVideoList = append(horizontal3KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(4) && width < caleHorizontalPix(5) {
} else if width >= 4000 && width < 5000 {
horizontal4KVideoList = append(horizontal4KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(5) && width < caleHorizontalPix(6) {
// 5120 x 2880 -> 5k
if width == 5120 && height == 2880 {
horizontalStandard5KVideoList = append(horizontalStandard5KVideoList, currentVideoPath)
return
}
} else if width >= 5000 && width < 6000 {
horizontal5KVideoList = append(horizontal5KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(6) && width < caleHorizontalPix(7) {
} else if width >= 6000 && width < 7000 {
horizontal6KVideoList = append(horizontal6KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(7) && width < caleHorizontalPix(8) {
} else if width >= 7000 && width < 8000 {
// 7680 x 4320 -> 8k
if width == 7680 && height == 4320 {
horizontalStandard8KVideoList = append(horizontalStandard8KVideoList, currentVideoPath)
return
}
horizontal7KVideoList = append(horizontal7KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(8) && width < caleHorizontalPix(9) {
} else if width >= 8000 && width < 9000 {
horizontal8KVideoList = append(horizontal8KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(9) && width < caleHorizontalPix(10) {
} else if width >= 9000 && width < 10000 {
horizontal9KVideoList = append(horizontal9KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(10) {
} else if width >= 10000 {
horizontalHKVideoList = append(horizontalHKVideoList, currentVideoPath)
} else {
// 未分类的视频
horizontalUnHandleVideoList = append(horizontalUnHandleVideoList, currentVideoPath)
}
}
@ -628,31 +573,48 @@ func handleSquareVideo(currentVideoPath string, width int, height int, suffix st
squareGifVideoList = append(squareGifVideoList, currentVideoPath)
return
}
if width < caleHorizontalPix(1) {
if width < 1000 {
squareNormalVideoList = append(squareNormalVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(1) && width < caleHorizontalPix(2) {
} else if width >= 1000 && width < 2000 {
// 1280 x 720 -> 720p
if width == 1280 && height == 720 {
squareStandard720PVideoList = append(squareStandard720PVideoList, currentVideoPath)
return
}
// 1920 x 1080 -> 1080p
if width == 1920 && height == 1080 {
squareStandard1080PVideoList = append(squareStandard1080PVideoList, currentVideoPath)
return
}
square1KVideoList = append(square1KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(2) && width < caleHorizontalPix(3) {
} else if width >= 2000 && width < 3000 {
square2KVideoList = append(square2KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(3) && width < caleHorizontalPix(4) {
} else if width >= 3000 && width < 4000 {
// 3840 x 2160 -> 4k
if width == 3840 && height == 2160 {
squareStandard4KVideoList = append(squareStandard4KVideoList, currentVideoPath)
return
}
square3KVideoList = append(square3KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(4) && width < caleHorizontalPix(5) {
} else if width >= 4000 && width < 5000 {
square4KVideoList = append(square4KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(5) && width < caleHorizontalPix(6) {
} else if width >= 5000 && width < 6000 {
square5KVideoList = append(square5KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(6) && width < caleHorizontalPix(7) {
} else if width >= 6000 && width < 7000 {
square6KVideoList = append(square6KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(7) && width < caleHorizontalPix(8) {
} else if width >= 7000 && width < 8000 {
// 7680 x 4320 -> 8k
if width == 7680 && height == 4320 {
squareStandard8KVideoList = append(squareStandard8KVideoList, currentVideoPath)
return
}
square7KVideoList = append(square7KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(8) && width < caleHorizontalPix(9) {
} else if width >= 8000 && width < 9000 {
square8KVideoList = append(square8KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(9) && width < caleHorizontalPix(10) {
} else if width >= 9000 && width < 10000 {
square9KVideoList = append(square9KVideoList, currentVideoPath)
} else if width >= caleHorizontalPix(10) {
} else if width >= 10000 {
squareHKVideoList = append(squareHKVideoList, currentVideoPath)
} else {
// 未处理的等比视频
squareUnHandleVideoList = append(squareUnHandleVideoList, currentVideoPath)
}
}