Skip to content

Commit

Permalink
Merge pull request #14 from xxxsen/xxxsen/feature/add_option_to_contr…
Browse files Browse the repository at this point in the history
…ol_face_rec

Xxxsen/feature/add option to control face rec
  • Loading branch information
xxxsen authored Jan 23, 2025
2 parents 02e9c16 + 34ba081 commit f183292
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -a -tags netgo -ldflags '-w' -o yam
|data_dir|数据目录, 存储中间文件或者模型文件的|
|naming|命名规则, 可用的命名标签如下:{DATE}, {YEAR}, {MONTH}, {NUMBER}, {ACTOR}|

工具并不会对番号进行清洗(各种奇奇怪怪的下载站都有自己的命名方式, 无脑清洗可能会导致得到预期外的番号), 用户自己需要对文件进行重命名。

当前支持给番号添加特定来后缀来实现`添加额外分类`, `添加特定水印`等能力。

支持的后缀列表及说明(不同的后缀没有顺序限制, 可以同时存在多种后缀):

|后缀|举例|说明|
|---|---|---|
|-CD{Number}|-CD1|多CD场景下, 指定当前影片对应的CD ID, 起始CD为1|
|-C|-|添加`字幕`到分类中并为封面添加水印|
|-4K|-|添加`4K`到分类中并为封面添加水印|
|-LEAK|-|为封面添加特定水印|

## 其他

Expand Down Expand Up @@ -126,3 +138,4 @@ version: "3.1"
...
}
```

5 changes: 0 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ type Config struct {
Handlers []string `json:"handlers"`
ExtraMediaExts []string `json:"extra_media_exts"`
LogConfig logger.LogConfig `json:"log_config"`
SwitchConfig SwitchConfig `json:"switch_config"`
Dependencies []Dependency `json:"dependencies"`
}

type SwitchConfig struct {
EnableLinkMode bool `json:"enable_link_mode"`
}

func defaultConfig() *Config {
return &Config{
Plugins: []string{
Expand Down
14 changes: 12 additions & 2 deletions envflag/envflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
var defaultInst = &EnvFlag{}

type EnvFlag struct {
EnableSearchMetaCache bool `envconfig:"enable_search_meta_cache" default:"true"`
EnableLinkMode bool `envconfig:"enable_link_mode"`
EnableSearchMetaCache bool `envconfig:"enable_search_meta_cache" default:"true"`
EnableLinkMode bool `envconfig:"enable_link_mode"`
EnableGoFaceRecognizer bool `envconfig:"enable_go_face_recognizer" default:"true"`
EnablePigoFaceRecognizer bool `envconfig:"enable_pigo_face_recognizer" default:"true"`
}

func GetFlag() *EnvFlag {
Expand All @@ -31,3 +33,11 @@ func IsEnableSearchMetaCache() bool {
func IsEnableLinkMode() bool {
return GetFlag().EnableLinkMode
}

func IsEnableGoFaceRecognizer() bool {
return GetFlag().EnableGoFaceRecognizer
}

func IsEnablePigoFaceRecognizer() bool {
return GetFlag().EnablePigoFaceRecognizer
}
16 changes: 10 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func main() {
logkit.Info("scrape from dir", zap.String("dir", c.ScanDir))
logkit.Info("save to dir", zap.String("dir", c.SaveDir))
logkit.Info("use data dir", zap.String("dir", c.DataDir))
logkit.Info("current switch options", zap.Any("options", c.SwitchConfig))
logkit.Info("current switch options", zap.Any("options", envflag.GetFlag()))
logkit.Info("check current feature list")
logkit.Info("-- ffmpeg", zap.Bool("enable", ffmpeg.IsFFMpegEnabled()))
logkit.Info("-- ffprobe", zap.Bool("enable", ffmpeg.IsFFProbeEnabled()))
Expand Down Expand Up @@ -193,20 +193,24 @@ func ensureDependencies(datadir string, cdeps []config.Dependency) error {

func initFace(models string) error {
impls := make([]face.IFaceRec, 0, 2)
faceRecCreator := []func() (face.IFaceRec, error){
func() (face.IFaceRec, error) {
var faceRecCreator = make([]func() (face.IFaceRec, error), 0, 2)
if envflag.IsEnableGoFaceRecognizer() {
faceRecCreator = append(faceRecCreator, func() (face.IFaceRec, error) {
return goface.NewGoFace(models)
},
func() (face.IFaceRec, error) {
})
}
if envflag.IsEnablePigoFaceRecognizer() {
faceRecCreator = append(faceRecCreator, func() (face.IFaceRec, error) {
return pigo.NewPigo(models)
},
})
}
for index, creator := range faceRecCreator {
impl, err := creator()
if err != nil {
logutil.GetLogger(context.Background()).Error("create face rec impl failed", zap.Int("index", index), zap.Error(err))
continue
}
logutil.GetLogger(context.Background()).Info("use face recognizer", zap.String("name", impl.Name()))
impls = append(impls, impl)
}
if len(impls) == 0 {
Expand Down

0 comments on commit f183292

Please sign in to comment.