refactor: 移除 nsfw.python 配置项,自动在 PATH 中查找 python
This commit is contained in:
@@ -19,23 +19,15 @@ import (
|
||||
// - FFmpegPath:ffmpeg 程序路径(用于把带 EXIF 旋转标记的图片转正);留空自动在 PATH 里找
|
||||
// - RotateImages:是否处理图片 EXIF 旋转(默认 true);false 则完全不处理,按存储方向/尺寸归类
|
||||
// - Workers:探测/MIME/移动阶段的并发 worker 数(默认 4;设 0 表示用满全部 CPU 核数)
|
||||
// - NSFWEnabled:是否开启色情图片识别(本地 python + NudeNet,默认 false)
|
||||
// - NSFWPython:python 可执行文件路径;留空自动在 PATH 里找
|
||||
// - NSFWThreshold:判定阈值 0~1(默认 0.5)
|
||||
// - AnimeNSFWEnabled:是否开启动漫色情图片识别(本地 python + WD Tagger v3,默认 false)
|
||||
// - AnimeNSFWThreshold:动漫判定阈值 0~1(默认 0.5)
|
||||
//
|
||||
// 注意:NSFW 检测相关配置已改为从数据库读取(通过网页「系统配置」设置)
|
||||
type Config struct {
|
||||
Port int
|
||||
Dsn string
|
||||
AutoOpen bool
|
||||
FFmpegPath string
|
||||
RotateImages bool
|
||||
Workers int
|
||||
NSFWEnabled bool
|
||||
NSFWPython string
|
||||
NSFWThreshold float64
|
||||
AnimeNSFWEnabled bool
|
||||
AnimeNSFWThreshold float64
|
||||
Port int
|
||||
Dsn string
|
||||
AutoOpen bool
|
||||
FFmpegPath string
|
||||
RotateImages bool
|
||||
Workers int
|
||||
}
|
||||
|
||||
// appConfig 当前生效的配置(程序运行期间一直不变)。
|
||||
@@ -49,7 +41,7 @@ func GetAppConfig() Config {
|
||||
// LoadAppConfig 从 application.properties 读配置;文件不存在就用默认值。
|
||||
func LoadAppConfig() {
|
||||
// 先给一套默认值
|
||||
appConfig = Config{Port: 8080, Dsn: "media-info.db", AutoOpen: true, RotateImages: true, Workers: 4, NSFWThreshold: 0.5, AnimeNSFWThreshold: 0.5}
|
||||
appConfig = Config{Port: 8080, Dsn: "media-info.db", AutoOpen: true, RotateImages: true, Workers: 4}
|
||||
|
||||
p, err := properties.LoadFile("application.properties", properties.UTF8)
|
||||
if err != nil {
|
||||
@@ -74,23 +66,6 @@ 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
|
||||
}
|
||||
}
|
||||
// 动漫色情识别:默认关;阈值只认 0~1 之间的小数
|
||||
appConfig.AnimeNSFWEnabled = p.GetBool("anime_nsfw.enabled", false)
|
||||
if v, ok := p.Get("anime_nsfw.threshold"); ok && strings.TrimSpace(v) != "" {
|
||||
if t, err := strconv.ParseFloat(strings.TrimSpace(v), 64); err == nil && t > 0 && t < 1 {
|
||||
appConfig.AnimeNSFWThreshold = t
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WorkerCount 返回探测/MIME/移动阶段使用的并发 worker 数:
|
||||
|
||||
@@ -674,7 +674,6 @@ func (s *ScanService) runScan(ctx context.Context, rootDir, destDir string) erro
|
||||
// ---------- 第五步(可选):色情识别 ----------
|
||||
// 从数据库读取 NSFW 配置(支持运行时修改,立即生效)
|
||||
nsfwType := s.store.GetConfig("nsfw.type") // "" / "human" / "anime"
|
||||
pythonPath := config.GetAppConfig().NSFWPython
|
||||
|
||||
nsfwDet := (*nsfw.Detector)(nil)
|
||||
s.setNsfwDetectorReady(false)
|
||||
@@ -685,7 +684,7 @@ func (s *ScanService) runScan(ctx context.Context, rootDir, destDir string) erro
|
||||
threshold = t
|
||||
}
|
||||
}
|
||||
if d, err := nsfw.Start(pythonPath, threshold); err != nil {
|
||||
if d, err := nsfw.Start("", threshold); err != nil {
|
||||
fmt.Printf("=== 色情识别未启用(图片照常处理): %v\n", err)
|
||||
} else {
|
||||
nsfwDet = d
|
||||
@@ -704,7 +703,7 @@ func (s *ScanService) runScan(ctx context.Context, rootDir, destDir string) erro
|
||||
threshold = t
|
||||
}
|
||||
}
|
||||
if d, err := anime_nsfw.Start(pythonPath, threshold); err != nil {
|
||||
if d, err := anime_nsfw.Start("", threshold); err != nil {
|
||||
fmt.Printf("=== 动漫色情识别未启用(图片照常处理): %v\n", err)
|
||||
} else {
|
||||
animeNsfwDet = d
|
||||
|
||||
Reference in New Issue
Block a user