Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc7fe17f

Browse files
toshskicrwxaj
andauthored
feat: Additional stash match rules (#1886)
* Allow Stash matching on Title/ReleaseDate/StudioCode* Fix comparing titles with and/&* Add migration to update actor config json file* Handle Studio not found* Update migrations.go---------Co-authored-by: crwxaj <52156245+crwxaj@users.noreply.github.com>
1 parent8d99987 commitc7fe17f

File tree

4 files changed

+261
-127
lines changed

4 files changed

+261
-127
lines changed

‎pkg/externalreference/stashdb.go

Lines changed: 114 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ func ApplySceneRules() {
5252
config:=models.BuildActorScraperRules()
5353

5454
forsitename,configSite:=rangeconfig.StashSceneMatching {
55-
iflen(configSite.Rules)>0 {
56-
ifconfigSite.StashId=="" {
57-
varext models.ExternalReference
58-
ext.FindExternalId("stashdb studio",sitename)
59-
configSite.StashId=ext.ExternalId
55+
for_,stashRules:=rangeconfigSite {
56+
iflen(stashRules.Rules)>0 {
57+
ifstashRules.StashId=="" {
58+
varext models.ExternalReference
59+
ext.FindExternalId("stashdb studio",sitename)
60+
stashRules.StashId=ext.ExternalId
61+
}
62+
matchSceneOnRules(sitename,stashRules)
6063
}
61-
matchSceneOnRules(sitename,config)
6264
}
6365
}
6466

@@ -136,22 +138,22 @@ func simplifyUrl(url string) string {
136138
}
137139

138140
// if an unmatched scene has a trailing number try to match on the xbvr scene_id for that studio
139-
funcmatchSceneOnRules(sitenamestring,config models.ActorScraperConfig) {
141+
funcmatchSceneOnRules(sitenamestring,config models.StashSiteConfig) {
140142

141143
db,_:=models.GetDB()
142144
deferdb.Close()
143145

144-
ifconfig.StashSceneMatching[sitename].StashId=="" {
146+
ifconfig.StashId=="" {
145147
varext models.ExternalReference
146148
ext.FindExternalId("stashdb studios",sitename)
147-
site:=config.StashSceneMatching[sitename]
149+
site:=config
148150
site.StashId=ext.ExternalId
149-
config.StashSceneMatching[sitename]=site
151+
config=site
150152
}
151153

152-
log.Infof("Matching on rules for %s Stashdb Id: %s",sitename,config.StashSceneMatching[sitename].StashId)
154+
log.Infof("Matching on rules for %s Stashdb Id: %s",sitename,config.StashId)
153155
varstashScenes []models.ExternalReference
154-
stashId:=config.StashSceneMatching[sitename].StashId
156+
stashId:=config.StashId
155157
ifstashId=="" {
156158
return
157159
}
@@ -167,50 +169,117 @@ func matchSceneOnRules(sitename string, config models.ActorScraperConfig) {
167169
vardata models.StashScene
168170
json.Unmarshal([]byte(stashScene.ExternalData),&data)
169171
urlLoop:
170-
for_,url:=rangedata.URLs {
171-
ifurl.Type=="STUDIO" {
172-
for_,rule:=rangeconfig.StashSceneMatching[sitename].Rules {// for each rule on this site
173-
re:=regexp.MustCompile(rule.StashRule)
174-
match:=re.FindStringSubmatch(url.URL)
175-
ifmatch!=nil {
176-
varextrefSite models.ExternalReference
177-
db.Where("external_source = ? and external_id = ?","stashdb studio",data.Studio.ID).Find(&extrefSite)
178-
ifextrefSite.ID!=0 {
179-
varxbvrScene models.Scene
180-
switchrule.XbvrField {
181-
case"scene_id":
182-
for_,scene:=rangexbrScenes {
183-
ifstrings.HasSuffix(scene.SceneID,match[rule.StashMatchResultPosition]) {
184-
xbvrScene=scene
185-
break
172+
for_,rule:=rangeconfig.Rules {// for each rule on this site
173+
varxbvrScene models.Scene
174+
switchrule.StashRule {
175+
case"","url":
176+
for_,url:=rangedata.URLs {
177+
ifurl.Type=="STUDIO" {
178+
re:=regexp.MustCompile(rule.StashRule)
179+
match:=re.FindStringSubmatch(url.URL)
180+
ifmatch!=nil {
181+
varextrefSite models.ExternalReference
182+
db.Where("external_source = ? and external_id = ?","stashdb studio",data.Studio.ID).Find(&extrefSite)
183+
ifextrefSite.ID!=0 {
184+
switchrule.XbvrField {
185+
case"scene_id":
186+
for_,scene:=rangexbrScenes {
187+
ifstrings.HasSuffix(scene.SceneID,match[rule.StashMatchResultPosition]) {
188+
xbvrScene=scene
189+
break
190+
}
186191
}
187-
}
188-
case"scene_url":
189-
for_,scene:=rangexbrScenes {
190-
ifstrings.Contains(strings.ReplaceAll(strings.ReplaceAll(strings.ToLower(scene.SceneURL),"-"," "),"_"," "),strings.ReplaceAll(strings.ReplaceAll(strings.ToLower(match[rule.StashMatchResultPosition]),"-"," "),"_"," ")) {
191-
xbvrScene=scene
192-
break
192+
case"scene_url":
193+
for_,scene:=rangexbrScenes {
194+
ifstrings.Contains(strings.ReplaceAll(strings.ReplaceAll(strings.ToLower(scene.SceneURL),"-"," "),"_"," "),strings.ReplaceAll(strings.ReplaceAll(strings.ToLower(match[rule.StashMatchResultPosition]),"-"," "),"_"," ")) {
195+
xbvrScene=scene
196+
break
197+
}
193198
}
199+
default:
200+
log.Errorf("Unkown xbvr field %s",rule.XbvrField)
194201
}
195-
default:
196-
log.Errorf("Unkown xbvr field %s",rule.XbvrField)
197-
}
198-
199-
ifxbvrScene.ID!=0 {
200-
xbvrLink:= models.ExternalReferenceLink{InternalTable:"scenes",InternalDbId:xbvrScene.ID,InternalNameId:xbvrScene.SceneID,
201-
ExternalReferenceID:stashScene.ID,ExternalSource:stashScene.ExternalSource,ExternalId:stashScene.ExternalId,MatchType:20}
202-
stashScene.XbvrLinks=append(stashScene.XbvrLinks,xbvrLink)
203-
stashScene.Save()
204-
matchPerformerName(data,xbvrScene,20)
205-
break urlLoop
206202
}
207203
}
208204
}
209205
}
206+
case"title/date":
207+
for_,scene:=rangexbrScenes {
208+
ifsimplystring(data.Title)==simplystring(scene.Title)&&data.Date==scene.ReleaseDateText {
209+
xbvrLink:= models.ExternalReferenceLink{InternalTable:"scenes",InternalDbId:scene.ID,InternalNameId:scene.SceneID,
210+
ExternalReferenceID:stashScene.ID,ExternalSource:stashScene.ExternalSource,ExternalId:stashScene.ExternalId,MatchType:20}
211+
stashScene.XbvrLinks=append(stashScene.XbvrLinks,xbvrLink)
212+
stashScene.Save()
213+
matchPerformerName(data,scene,20)
214+
break urlLoop
215+
}
216+
}
217+
case"title":
218+
varmatch models.Scene
219+
matchCnt:=0
220+
for_,scene:=rangexbrScenes {
221+
ifsimplystring(data.Title)==simplystring(scene.Title) {
222+
match=scene
223+
matchCnt+=1
224+
}
225+
}
226+
//check only one match
227+
ifmatchCnt==1 {
228+
xbvrScene=match
229+
break
230+
}
231+
case"studio_code":
232+
matchCnt:=0
233+
for_,scene:=rangexbrScenes {
234+
ifdata.Code!=""&&strings.Contains(scene.SceneID,data.Code) {
235+
xbvrScene=scene
236+
matchCnt+=1
237+
}
238+
}
210239
}
240+
241+
ifxbvrScene.ID!=0 {
242+
xbvrLink:= models.ExternalReferenceLink{InternalTable:"scenes",InternalDbId:xbvrScene.ID,InternalNameId:xbvrScene.SceneID,
243+
ExternalReferenceID:stashScene.ID,ExternalSource:stashScene.ExternalSource,ExternalId:stashScene.ExternalId,MatchType:20}
244+
stashScene.XbvrLinks=append(stashScene.XbvrLinks,xbvrLink)
245+
stashScene.Save()
246+
matchPerformerName(data,xbvrScene,20)
247+
break urlLoop
248+
}
249+
211250
}
212251
}
252+
}
213253

254+
funcsimplystring(strstring)string {
255+
str=strings.TrimSpace(str)
256+
str=strings.ReplaceAll(str," and ","&")
257+
str=strings.ReplaceAll(str," ","")
258+
str=strings.ReplaceAll(str,".","")
259+
str=strings.ReplaceAll(str,":","")
260+
str=strings.ReplaceAll(str,"!","")
261+
str=strings.ReplaceAll(str,"?","")
262+
str=strings.ReplaceAll(str,";","")
263+
str=strings.ReplaceAll(str,",","")
264+
str=strings.ReplaceAll(str,"#","")
265+
str=strings.ReplaceAll(str,"@","")
266+
str=strings.ReplaceAll(str,"$","")
267+
str=strings.ReplaceAll(str,"%","")
268+
str=strings.ReplaceAll(str,"*","")
269+
str=strings.ReplaceAll(str,"(","")
270+
str=strings.ReplaceAll(str,")","")
271+
str=strings.ReplaceAll(str,"[","")
272+
str=strings.ReplaceAll(str,"]","")
273+
str=strings.ReplaceAll(str,"{","")
274+
str=strings.ReplaceAll(str,"}","")
275+
str=strings.ReplaceAll(str,"-","")
276+
str=strings.ReplaceAll(str,"_","")
277+
str=strings.ReplaceAll(str,"+","")
278+
str=strings.ReplaceAll(str,"=","")
279+
str=strings.ReplaceAll(str,"'","")
280+
str=strings.ReplaceAll(str,`""`,"")
281+
str=strings.ReplaceAll(str,"`","")
282+
returnstrings.ToLower(str)
214283
}
215284

216285
// checks if scenes that have a match, can match the scenes performers

‎pkg/migrations/migrations.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,7 +2081,60 @@ func Migrate() {
20812081
err=config.MigrateFromOfficalToCustom("vrphub-vrhush","https://vrphub.com/category/vr-hush","VRHush","VRHush","https://cdn-nexpectation.secure.yourpornpartner.com/sites/vrh/favicon/apple-touch-icon-180x180.png","vrphub","(VRP Hub)")
20822082
err=config.MigrateFromOfficalToCustom("vrphub-stripzvr","https://vrphub.com/category/stripzvr/","StripzVR - VRP Hub","StripzVR","https://www.stripzvr.com/wp-content/uploads/2018/09/cropped-favicon-192x192.jpg","vrphub","(VRP Hub)")
20832083
returnerr
2084+
},
2085+
},
2086+
{
2087+
ID:"0082-upgrade_actor_scraper_config",
2088+
Migrate:func(tx*gorm.DB)error {
2089+
typeactorScraperConfigstruct {
2090+
StashSceneMatchingmap[string]models.StashSiteConfig
2091+
GenericActorScrapingConfigmap[string]models.GenericScraperRuleSet
2092+
}
20842093

2094+
fName:=filepath.Join(common.AppDir,"actor_scraper_custom_config.json")
2095+
if_,err:=os.Stat(fName);os.IsNotExist(err) {
2096+
returnnil
2097+
}
2098+
2099+
varnewCustomScrapeRules models.ActorScraperConfig
2100+
b,err:=os.ReadFile(fName)
2101+
iferr!=nil {
2102+
returnerr
2103+
}
2104+
// make a backup, just in case, but don't fail the upgrade if a copy cannot be made
2105+
bakName:=filepath.Join(common.AppDir,"actor_scraper_custom_config.pre_0433.json")
2106+
if_,err:=os.Stat(bakName);os.IsNotExist(err) {
2107+
err:=os.WriteFile(bakName,b,0644)
2108+
iferr!=nil {
2109+
common.Log.Warnf("Warning: unable to create backup copy of actor_scraper_custom_config.json %s, proceeding",err)
2110+
}
2111+
}
2112+
2113+
e:=json.Unmarshal(b,&newCustomScrapeRules)
2114+
ife==nil {
2115+
// if we can read the file with the new model, it has already been converted
2116+
common.Log.Info("Ignoring migration of actor_scraper_custom_config.json, already appears to have been done")
2117+
returnnil
2118+
}
2119+
2120+
varoldCustomScrapeRulesactorScraperConfig
2121+
e=json.Unmarshal(b,&oldCustomScrapeRules)
2122+
ife!=nil {
2123+
// can't read the old layout either ?
2124+
returne
2125+
}
2126+
2127+
newCustomScrapeRules= models.ActorScraperConfig{}
2128+
newCustomScrapeRules.GenericActorScrapingConfig=oldCustomScrapeRules.GenericActorScrapingConfig
2129+
newCustomScrapeRules.StashSceneMatching=map[string][]models.StashSiteConfig{}
2130+
forkey,_:=rangeoldCustomScrapeRules.StashSceneMatching {
2131+
newScraperCofig:=oldCustomScrapeRules.StashSceneMatching[key]
2132+
newCustomScrapeRules.StashSceneMatching[key]= []models.StashSiteConfig{}
2133+
newCustomScrapeRules.StashSceneMatching[key]=append(newCustomScrapeRules.StashSceneMatching[key],newScraperCofig)
2134+
}
2135+
out,_:=json.MarshalIndent(newCustomScrapeRules,""," ")
2136+
e=os.WriteFile(fName,out,0644)
2137+
returne
20852138
},
20862139
},
20872140
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp