refactor: 按模块重构项目结构
- 删除 vars 全局状态,按职责拆分 internal/ 包:scanner/probe/classify/organize/mover/store/digest - 数据驱动归类规则替代图片/视频重复分支,store 改为结构体实例 - build.sh 按系统类型编译:Windows 用 upx 压缩,macOS/Linux 不压缩 - 忽略目录拆分:图片_已忽略 / 视频_已忽略 - 输出构建产物加入 .gitignore
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
// Package classify 提供纯函数的分辨率归类规则,不依赖任何状态。
|
||||
package classify
|
||||
|
||||
import "strings"
|
||||
|
||||
// Orientation 画面方向
|
||||
type Orientation int
|
||||
|
||||
const (
|
||||
OrientationSquare Orientation = iota
|
||||
OrientationHorizontal
|
||||
OrientationVertical
|
||||
)
|
||||
|
||||
// OrientationOf 由宽高判定画面方向
|
||||
func OrientationOf(width, height int) Orientation {
|
||||
switch {
|
||||
case width > height:
|
||||
return OrientationHorizontal
|
||||
case width < height:
|
||||
return OrientationVertical
|
||||
default:
|
||||
return OrientationSquare
|
||||
}
|
||||
}
|
||||
|
||||
func (o Orientation) String() string {
|
||||
switch o {
|
||||
case OrientationHorizontal:
|
||||
return "横屏"
|
||||
case OrientationVertical:
|
||||
return "竖屏"
|
||||
default:
|
||||
return "等比"
|
||||
}
|
||||
}
|
||||
|
||||
// ImageDir 返回图片归类子目录名,如 "图片_横屏_1080P" / "图片_GIF"
|
||||
func ImageDir(ext string, width, height int) string {
|
||||
if strings.EqualFold(ext, ".gif") {
|
||||
return "图片_GIF"
|
||||
}
|
||||
return resolutionDir("图片", ext, width, height)
|
||||
}
|
||||
|
||||
// VideoDir 返回视频归类子目录名,如 "视频_竖屏_4k" / "视频_横屏_GIF"
|
||||
func VideoDir(ext string, width, height int) string {
|
||||
return resolutionDir("视频", ext, width, height)
|
||||
}
|
||||
|
||||
func resolutionDir(kind, ext string, width, height int) string {
|
||||
ori := OrientationOf(width, height).String()
|
||||
if strings.EqualFold(ext, ".gif") {
|
||||
return kind + "_" + ori + "_GIF"
|
||||
}
|
||||
if suffix := matchStandard(width, height); suffix != "" {
|
||||
return kind + "_" + ori + "_" + suffix
|
||||
}
|
||||
overflow := "原图"
|
||||
if kind == "视频" {
|
||||
overflow = "原画质"
|
||||
}
|
||||
return kind + "_" + ori + "_" + levelName(longEdge(width, height), overflow)
|
||||
}
|
||||
|
||||
// longEdge 返回长边像素
|
||||
func longEdge(w, h int) int {
|
||||
if w > h {
|
||||
return w
|
||||
}
|
||||
return h
|
||||
}
|
||||
Reference in New Issue
Block a user