Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions pkg/api/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,36 @@ type RequestSaveOptionsTaskSchedule struct {
LinkScenesHourStart int `json:"linkScenesHourStart"`
LinkScenesHourEnd int `json:"linkScenesHourEnd"`
LinkScenesStartDelay int `json:"linkScenesStartDelay"`

AutoTagScheduleEnabled bool `json:"autoTagScheduleEnabled"`
AutoTagScheduleHourInterval int `json:"autoTagScheduleHourInterval"`
AutoTagScheduleUseRange bool `json:"autoTagScheduleUseRange"`
AutoTagScheduleMinuteStart int `json:"autoTagScheduleMinuteStart"`
AutoTagScheduleHourStart int `json:"autoTagScheduleHourStart"`
AutoTagScheduleHourEnd int `json:"autoTagScheduleHourEnd"`
AutoTagScheduleStartDelay int `json:"autoTagScheduleStartDelay"`

AutoTagBreastType bool `json:"autoTagBreastType"`
AutoTagAge bool `json:"autoTagAge"`
AutoTagHeight bool `json:"autoTagHeight"`
AutoTagNationality bool `json:"autoTagNationality"`
AutoTagEthnicity bool `json:"autoTagEthnicity"`
AutoTagHairColor bool `json:"autoTagHairColor"`
AutoTagEyeColor bool `json:"autoTagEyeColor"`
AutoTagCupSize bool `json:"autoTagCupSize"`
AutoTagResolution bool `json:"autoTagResolution"`
AutoTagVideoFormat bool `json:"autoTagVideoFormat"`
AutoTagDuration bool `json:"autoTagDuration"`

AutoTagInterracial bool `json:"autoTagInterracial"`

AutoTagGenderFilter []string `json:"autoTagGenderFilter"`

AutoTagHeightShortMax int `json:"autoTagHeightShortMax"`
AutoTagHeightAverageMax int `json:"autoTagHeightAverageMax"`

AutoTagDurationShortMax int `json:"autoTagDurationShortMax"`
AutoTagDurationStandardMax int `json:"autoTagDurationStandardMax"`
}
type RequestSaveSiteMatchParams struct {
SiteId string `json:"site"`
Expand Down Expand Up @@ -989,6 +1019,9 @@ func (i ConfigResource) saveOptionsTaskSchedule(req *restful.Request, resp *rest
if r.PreviewHourEnd > 23 {
r.PreviewHourEnd -= 24
}
if r.AutoTagScheduleHourEnd > 23 {
r.AutoTagScheduleHourEnd -= 24
}

config.Config.Cron.RescrapeSchedule.Enabled = r.RescrapeEnabled
config.Config.Cron.RescrapeSchedule.HourInterval = r.RescrapeHourInterval
Expand Down Expand Up @@ -1038,6 +1071,35 @@ func (i ConfigResource) saveOptionsTaskSchedule(req *restful.Request, resp *rest
config.Config.Cron.LinkScenesSchedule.HourEnd = r.LinkScenesHourEnd
config.Config.Cron.LinkScenesSchedule.RunAtStartDelay = r.LinkScenesStartDelay

config.Config.Cron.AutoTagSchedule.Enabled = r.AutoTagScheduleEnabled
config.Config.Cron.AutoTagSchedule.HourInterval = r.AutoTagScheduleHourInterval
config.Config.Cron.AutoTagSchedule.UseRange = r.AutoTagScheduleUseRange
config.Config.Cron.AutoTagSchedule.MinuteStart = r.AutoTagScheduleMinuteStart
config.Config.Cron.AutoTagSchedule.HourStart = r.AutoTagScheduleHourStart
config.Config.Cron.AutoTagSchedule.HourEnd = r.AutoTagScheduleHourEnd
config.Config.Cron.AutoTagSchedule.RunAtStartDelay = r.AutoTagScheduleStartDelay

config.Config.AutoTag.BreastType = r.AutoTagBreastType
config.Config.AutoTag.Age = r.AutoTagAge
config.Config.AutoTag.Height = r.AutoTagHeight
config.Config.AutoTag.Nationality = r.AutoTagNationality
config.Config.AutoTag.Ethnicity = r.AutoTagEthnicity
config.Config.AutoTag.HairColor = r.AutoTagHairColor
config.Config.AutoTag.EyeColor = r.AutoTagEyeColor
config.Config.AutoTag.CupSize = r.AutoTagCupSize
config.Config.AutoTag.Resolution = r.AutoTagResolution
config.Config.AutoTag.VideoFormat = r.AutoTagVideoFormat
config.Config.AutoTag.Duration = r.AutoTagDuration

config.Config.AutoTag.Interracial = r.AutoTagInterracial
config.Config.AutoTag.GenderFilter = r.AutoTagGenderFilter

config.Config.AutoTag.HeightShortMax = r.AutoTagHeightShortMax
config.Config.AutoTag.HeightAverageMax = r.AutoTagHeightAverageMax

config.Config.AutoTag.DurationShortMax = r.AutoTagDurationShortMax
config.Config.AutoTag.DurationStandardMax = r.AutoTagDurationStandardMax

config.SaveConfig()

resp.WriteHeaderAndEntity(http.StatusOK, r)
Expand Down
40 changes: 40 additions & 0 deletions pkg/api/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ func (i TaskResource) WebService() *restful.WebService {
ws.Route(ws.GET("/rescan").To(i.rescan).
Metadata(restfulspec.KeyOpenAPITags, tags))

ws.Route(ws.GET("/auto-tag").To(i.autoTag).
Metadata(restfulspec.KeyOpenAPITags, tags))

ws.Route(ws.GET("/auto-tag-reset").To(i.autoTagReset).
Metadata(restfulspec.KeyOpenAPITags, tags))

ws.Route(ws.GET("/system-tags").To(i.getSystemTags).
Metadata(restfulspec.KeyOpenAPITags, tags))

ws.Route(ws.GET("/actor-genders").To(i.getActorGenders).
Metadata(restfulspec.KeyOpenAPITags, tags))

ws.Route(ws.GET("/rescan/{storage-id}").To(i.rescan).
Metadata(restfulspec.KeyOpenAPITags, tags))

Expand Down Expand Up @@ -117,6 +129,34 @@ func (i TaskResource) rescan(req *restful.Request, resp *restful.Response) {
}
}

func (i TaskResource) autoTag(req *restful.Request, resp *restful.Response) {
go tasks.GenerateAutoTags()
}

func (i TaskResource) autoTagReset(req *restful.Request, resp *restful.Response) {
go tasks.ResetAutoTags()
}

func (i TaskResource) getSystemTags(req *restful.Request, resp *restful.Response) {
db, _ := models.GetDB()
defer db.Close()

var tags []models.Tag
db.Where("is_system = ?", true).Order("name asc").Find(&tags)

resp.WriteHeaderAndEntity(http.StatusOK, tags)
}

func (i TaskResource) getActorGenders(req *restful.Request, resp *restful.Response) {
db, _ := models.GetDB()
defer db.Close()

var genders []string
db.Model(&models.Actor{}).Where("gender != ''").Pluck("DISTINCT gender", &genders)

resp.WriteHeaderAndEntity(http.StatusOK, genders)
}

func (i TaskResource) sceneRrefresh(req *restful.Request, resp *restful.Response) {
go tasks.RefreshSceneStatuses()
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,40 @@ type ObjectConfig struct {
HourEnd int `default:"23" json:"hourEnd"`
RunAtStartDelay int `default:"0" json:"runAtStartDelay"`
} `json:"linkScenesSchedule"`
AutoTagSchedule struct {
Enabled bool `default:"false" json:"enabled"`
HourInterval int `default:"12" json:"hourInterval"`
UseRange bool `default:"false" json:"useRange"`
MinuteStart int `default:"0" json:"minuteStart"`
HourStart int `default:"0" json:"hourStart"`
HourEnd int `default:"23" json:"hourEnd"`
RunAtStartDelay int `default:"0" json:"runAtStartDelay"`
} `json:"autoTagSchedule"`
} `json:"cron"`
AutoTag struct {
BreastType bool `default:"false" json:"breastType"`
Age bool `default:"false" json:"age"`
Height bool `default:"false" json:"height"`
Nationality bool `default:"false" json:"nationality"`
Ethnicity bool `default:"false" json:"ethnicity"`
HairColor bool `default:"false" json:"hairColor"`
EyeColor bool `default:"false" json:"eyeColor"`
CupSize bool `default:"false" json:"cupSize"`
Resolution bool `default:"false" json:"resolution"`
VideoFormat bool `default:"false" json:"videoFormat"`
Duration bool `default:"false" json:"duration"`

Interracial bool `default:"false" json:"interracial"`
BMI bool `default:"false" json:"bmi"`

GenderFilter []string `default:"[]" json:"genderFilter"`

HeightShortMax int `default:"160" json:"heightShortMax"`
HeightAverageMax int `default:"175" json:"heightAverageMax"`

DurationShortMax int `default:"15" json:"durationShortMax"`
DurationStandardMax int `default:"40" json:"durationStandardMax"`
} `json:"autoTag"`
Storage struct {
MatchOhash bool `default:"false" json:"match_ohash"`
VideoExt []string `json:"video_ext"`
Expand Down
6 changes: 6 additions & 0 deletions pkg/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,12 @@ func Migrate(migrateTo string) {
return tx.Table("scenes").AddIndex("idx_scenes_scraper_id", "scraper_id").Error
},
},
{
ID: "0088-add-is_system-to-tags",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Tag{}).Error
},
},
}

// Wrap migrations to automatically track progress
Expand Down
11 changes: 6 additions & 5 deletions pkg/models/model_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
)

type Tag struct {
ID uint `gorm:"primary_key" json:"id" xbvrbackup:"-"`
Scenes []Scene `gorm:"many2many:scene_tags;" json:"scenes" xbvrbackup:"-"`
Name string `gorm:"index" json:"name" xbvrbackup:"name"`
Clean string `gorm:"index" json:"clean" xbvrbackup:"-"`
Count int `json:"count" xbvrbackup:"-"`
ID uint `gorm:"primary_key" json:"id" xbvrbackup:"-"`
Scenes []Scene `gorm:"many2many:scene_tags;" json:"scenes" xbvrbackup:"-"`
Name string `gorm:"index" json:"name" xbvrbackup:"name"`
Clean string `gorm:"index" json:"clean" xbvrbackup:"-"`
Count int `json:"count" xbvrbackup:"-"`
IsSystem bool `json:"is_system" gorm:"default:false" xbvrbackup:"-"`
}

func (t *Tag) Save() error {
Expand Down
16 changes: 16 additions & 0 deletions pkg/server/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var previewTask cron.EntryID
var actorScrapeTask cron.EntryID
var stashdbScrapeTask cron.EntryID
var linkScenesTask cron.EntryID
var autoTagTask cron.EntryID

func SetupCron() {
cronInstance = cron.New()
Expand Down Expand Up @@ -48,6 +49,10 @@ func SetupCron() {
log.Println(fmt.Sprintf("Setup Link Scenes Task %v", formatCronSchedule(config.CronSchedule(config.Config.Cron.LinkScenesSchedule))))
linkScenesTask, _ = cronInstance.AddFunc(formatCronSchedule(config.CronSchedule(config.Config.Cron.LinkScenesSchedule)), linkScenesCron)
}
if config.Config.Cron.AutoTagSchedule.Enabled {
log.Println(fmt.Sprintf("Setup AutoTag Task %v", formatCronSchedule(config.CronSchedule(config.Config.Cron.AutoTagSchedule))))
autoTagTask, _ = cronInstance.AddFunc(formatCronSchedule(config.CronSchedule(config.Config.Cron.AutoTagSchedule)), autoTagCron)
}
cronInstance.Start()

go tasks.CalculateCacheSizes()
Expand All @@ -70,13 +75,17 @@ func SetupCron() {
if config.Config.Cron.LinkScenesSchedule.RunAtStartDelay > 0 {
time.AfterFunc(time.Duration(config.Config.Cron.LinkScenesSchedule.RunAtStartDelay)*time.Minute, linkScenesCron)
}
if config.Config.Cron.AutoTagSchedule.RunAtStartDelay > 0 {
time.AfterFunc(time.Duration(config.Config.Cron.AutoTagSchedule.RunAtStartDelay)*time.Minute, autoTagCron)
}

log.Println(fmt.Sprintf("Next Rescrape Task at %v", cronInstance.Entry(rescrapTask).Next))
log.Println(fmt.Sprintf("Next Rescan Task at %v", cronInstance.Entry(rescanTask).Next))
log.Println(fmt.Sprintf("Next Preview Generation Task at %v", cronInstance.Entry(previewTask).Next))
log.Println(fmt.Sprintf("Next Actor Rescripe Task at %v", cronInstance.Entry(actorScrapeTask).Next))
log.Println(fmt.Sprintf("Next Stashdb Rescrape Task at %v", cronInstance.Entry(stashdbScrapeTask).Next))
log.Println(fmt.Sprintf("Next Link Scenes Task at %v", cronInstance.Entry(linkScenesTask).Next))
log.Println(fmt.Sprintf("Next AutoTag Task at %v", cronInstance.Entry(autoTagTask).Next))
}

func scrapeCron() {
Expand Down Expand Up @@ -112,6 +121,13 @@ func linkScenesCron() {
log.Println(fmt.Sprintf("Next Link Scenes Task at %v", cronInstance.Entry(rescrapTask).Next))
}

func autoTagCron() {
if !session.HasActiveSession() {
tasks.GenerateAutoTags()
}
log.Println(fmt.Sprintf("Next AutoTag Task at %v", cronInstance.Entry(autoTagTask).Next))
}

var previewGenerateInProgress = false

func generatePreviewCron() {
Expand Down
Loading