feat: 色情图片识别(NudeNet);明暗档位改为5档(20%~100%)

This commit is contained in:
2025-06-02 21:04:38 +08:00
parent ea88f3e766
commit a914b4be74
13 changed files with 450 additions and 25 deletions
+23 -7
View File
@@ -19,13 +19,19 @@ import (
// - FFmpegPath:ffmpeg 程序路径(用于把带 EXIF 旋转标记的图片转正);留空自动在 PATH 里找
// - RotateImages:整理时是否自动转正带 EXIF 旋转标记的图片(默认 true)
// - Workers:探测/MIME/移动阶段的并发 worker 数(默认 4;设 0 表示用满全部 CPU 核数)
// - NSFWEnabled:是否开启色情图片识别(本地 python + NudeNet,默认 false)
// - NSFWPython:python 可执行文件路径;留空自动在 PATH 里找
// - NSFWThreshold:判定阈值 0~1(默认 0.5)
type Config struct {
Port int
Dsn string
AutoOpen bool
FFmpegPath string
RotateImages bool
Workers int
Port int
Dsn string
AutoOpen bool
FFmpegPath string
RotateImages bool
Workers int
NSFWEnabled bool
NSFWPython string
NSFWThreshold float64
}
// appConfig 当前生效的配置(程序运行期间一直不变)。
@@ -39,7 +45,7 @@ func GetAppConfig() Config {
// LoadAppConfig 从 application.properties 读配置;文件不存在就用默认值。
func LoadAppConfig() {
// 先给一套默认值
appConfig = Config{Port: 8080, Dsn: "media-info.db", AutoOpen: true, RotateImages: true, Workers: 4}
appConfig = Config{Port: 8080, Dsn: "media-info.db", AutoOpen: true, RotateImages: true, Workers: 4, NSFWThreshold: 0.5}
p, err := properties.LoadFile("application.properties", properties.UTF8)
if err != nil {
@@ -64,6 +70,16 @@ func LoadAppConfig() {
appConfig.Workers = n
}
}
// 色情识别:默认关;python 路径留空自动在 PATH 找;阈值只认 0~1 之间的小数
appConfig.NSFWEnabled = p.GetBool("nsfw.enabled", false)
if v, ok := p.Get("nsfw.python"); ok && v != "" {
appConfig.NSFWPython = v
}
if v, ok := p.Get("nsfw.threshold"); ok && strings.TrimSpace(v) != "" {
if t, err := strconv.ParseFloat(strings.TrimSpace(v), 64); err == nil && t > 0 && t < 1 {
appConfig.NSFWThreshold = t
}
}
}
// WorkerCount 返回探测/MIME/移动阶段使用的并发 worker 数: