@@ -52,13 +52,15 @@ func ApplySceneRules() {
52
52
config := models .BuildActorScraperRules ()
53
53
54
54
for sitename ,configSite := range config .StashSceneMatching {
55
- if len (configSite .Rules )> 0 {
56
- if configSite .StashId == "" {
57
- var ext models.ExternalReference
58
- ext .FindExternalId ("stashdb studio" ,sitename )
59
- configSite .StashId = ext .ExternalId
55
+ for _ ,stashRules := range configSite {
56
+ if len (stashRules .Rules )> 0 {
57
+ if stashRules .StashId == "" {
58
+ var ext models.ExternalReference
59
+ ext .FindExternalId ("stashdb studio" ,sitename )
60
+ stashRules .StashId = ext .ExternalId
61
+ }
62
+ matchSceneOnRules (sitename ,stashRules )
60
63
}
61
- matchSceneOnRules (sitename ,config )
62
64
}
63
65
}
64
66
@@ -136,22 +138,22 @@ func simplifyUrl(url string) string {
136
138
}
137
139
138
140
// if an unmatched scene has a trailing number try to match on the xbvr scene_id for that studio
139
- func matchSceneOnRules (sitename string ,config models.ActorScraperConfig ) {
141
+ func matchSceneOnRules (sitename string ,config models.StashSiteConfig ) {
140
142
141
143
db ,_ := models .GetDB ()
142
144
defer db .Close ()
143
145
144
- if config .StashSceneMatching [ sitename ]. StashId == "" {
146
+ if config .StashId == "" {
145
147
var ext models.ExternalReference
146
148
ext .FindExternalId ("stashdb studios" ,sitename )
147
- site := config . StashSceneMatching [ sitename ]
149
+ site := config
148
150
site .StashId = ext .ExternalId
149
- config . StashSceneMatching [ sitename ] = site
151
+ config = site
150
152
}
151
153
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 )
153
155
var stashScenes []models.ExternalReference
154
- stashId := config .StashSceneMatching [ sitename ]. StashId
156
+ stashId := config .StashId
155
157
if stashId == "" {
156
158
return
157
159
}
@@ -167,50 +169,117 @@ func matchSceneOnRules(sitename string, config models.ActorScraperConfig) {
167
169
var data models.StashScene
168
170
json .Unmarshal ([]byte (stashScene .ExternalData ),& data )
169
171
urlLoop:
170
- for _ ,url := range data .URLs {
171
- if url .Type == "STUDIO" {
172
- for _ ,rule := range config .StashSceneMatching [sitename ].Rules {// for each rule on this site
173
- re := regexp .MustCompile (rule .StashRule )
174
- match := re .FindStringSubmatch (url .URL )
175
- if match != nil {
176
- var extrefSite models.ExternalReference
177
- db .Where ("external_source = ? and external_id = ?" ,"stashdb studio" ,data .Studio .ID ).Find (& extrefSite )
178
- if extrefSite .ID != 0 {
179
- var xbvrScene models.Scene
180
- switch rule .XbvrField {
181
- case "scene_id" :
182
- for _ ,scene := range xbrScenes {
183
- if strings .HasSuffix (scene .SceneID ,match [rule .StashMatchResultPosition ]) {
184
- xbvrScene = scene
185
- break
172
+ for _ ,rule := range config .Rules {// for each rule on this site
173
+ var xbvrScene models.Scene
174
+ switch rule .StashRule {
175
+ case "" ,"url" :
176
+ for _ ,url := range data .URLs {
177
+ if url .Type == "STUDIO" {
178
+ re := regexp .MustCompile (rule .StashRule )
179
+ match := re .FindStringSubmatch (url .URL )
180
+ if match != nil {
181
+ var extrefSite models.ExternalReference
182
+ db .Where ("external_source = ? and external_id = ?" ,"stashdb studio" ,data .Studio .ID ).Find (& extrefSite )
183
+ if extrefSite .ID != 0 {
184
+ switch rule .XbvrField {
185
+ case "scene_id" :
186
+ for _ ,scene := range xbrScenes {
187
+ if strings .HasSuffix (scene .SceneID ,match [rule .StashMatchResultPosition ]) {
188
+ xbvrScene = scene
189
+ break
190
+ }
186
191
}
187
- }
188
- case "scene_url" :
189
- for _ , scene := range xbrScenes {
190
- if strings . 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 := range xbrScenes {
194
+ if strings . Contains ( strings . ReplaceAll ( strings . ReplaceAll ( strings . ToLower ( scene . SceneURL ), "-" , " " ), "_" , " " ), strings . ReplaceAll ( strings . ReplaceAll ( strings . ToLower ( match [ rule . StashMatchResultPosition ]), "-" , " " ), "_" , " " )) {
195
+ xbvrScene = scene
196
+ break
197
+ }
193
198
}
199
+ default :
200
+ log .Errorf ("Unkown xbvr field %s" ,rule .XbvrField )
194
201
}
195
- default :
196
- log .Errorf ("Unkown xbvr field %s" ,rule .XbvrField )
197
- }
198
-
199
- if xbvrScene .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
206
202
}
207
203
}
208
204
}
209
205
}
206
+ case "title/date" :
207
+ for _ ,scene := range xbrScenes {
208
+ if simplystring (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
+ var match models.Scene
219
+ matchCnt := 0
220
+ for _ ,scene := range xbrScenes {
221
+ if simplystring (data .Title )== simplystring (scene .Title ) {
222
+ match = scene
223
+ matchCnt += 1
224
+ }
225
+ }
226
+ //check only one match
227
+ if matchCnt == 1 {
228
+ xbvrScene = match
229
+ break
230
+ }
231
+ case "studio_code" :
232
+ matchCnt := 0
233
+ for _ ,scene := range xbrScenes {
234
+ if data .Code != "" && strings .Contains (scene .SceneID ,data .Code ) {
235
+ xbvrScene = scene
236
+ matchCnt += 1
237
+ }
238
+ }
210
239
}
240
+
241
+ if xbvrScene .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
+
211
250
}
212
251
}
252
+ }
213
253
254
+ func simplystring (str string )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
+ return strings .ToLower (str )
214
283
}
215
284
216
285
// checks if scenes that have a match, can match the scenes performers