Skip to content

Commit

Permalink
Update slrstudios.go
Browse files Browse the repository at this point in the history
* Incorporates the changes from xbapps#1624 as new fallback for failure to retrieve cover image using API
* Fixes trans covers, they are broken at the moment for the same reason that necessitated xbapps#1624 but required a different fix
  • Loading branch information
vt-idiot authored Feb 14, 2024
1 parent 75c91cd commit 436abb0
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions pkg/scrape/slrstudios.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func SexLikeReal(wg *sync.WaitGroup, updateSite bool, knownScenes []string, out
commonDb, _ := models.GetCommonDB()

// RegEx Patterns
coverRegEx := regexp.MustCompile(`background(?:-image)?\s*?:\s*?url\s*?\(\s*?(.*?)\s*?\)`)
durationRegExForSceneCard := regexp.MustCompile(`^(?:(\d{2}):)?(\d{2}):(\d{2})$`)
durationRegExForScenePage := regexp.MustCompile(`^T(\d{0,2})H?(\d{2})M(\d{2})S$`)
filenameRegEx := regexp.MustCompile(`[:?]|( & )|( \\u0026 )`)
Expand All @@ -48,7 +47,7 @@ func SexLikeReal(wg *sync.WaitGroup, updateSite bool, knownScenes []string, out
sc.Site = siteID
sc.MasterSiteId = masterSiteId
if scraperID == "" {
// there maybe no site/studio if user is jusy scraping a scene url
// there maybe no site/studio if user is just scraping a scene url
e.ForEach(`div[data-qa="page-scene-studio-name"]`, func(id int, e *colly.HTMLElement) {
sc.Studio = strings.TrimSpace(e.Text)
sc.Site = strings.TrimSpace(e.Text)
Expand Down Expand Up @@ -153,26 +152,28 @@ func SexLikeReal(wg *sync.WaitGroup, updateSite bool, knownScenes []string, out
if len(coverURL) > 0 {
sc.Covers = append(sc.Covers, coverURL)
} else {
coverURL := e.ChildAttr(`.splash-screen > img`, "src")
if len(coverURL) > 0 {
sc.Covers = append(sc.Covers, coverURL)
} else {
m := coverRegEx.FindStringSubmatch(strings.TrimSpace(e.ChildAttr(`.c-webxr-splash-screen`, "style")))
if len(m) > 0 && len(m[1]) > 0 {
sc.Covers = append(sc.Covers, m[1])
}
}
e.ForEach(`link[as="image"]`, func(id int, e *colly.HTMLElement) {
sc.Covers = append(sc.Covers, e.Request.AbsoluteURL(e.Attr("href")))
})
}
} else {
tcoverURL := e.ChildAttr(`.splash-screen > img`, "src")
if len(tcoverURL) > 0 {
sc.Covers = append(sc.Covers, tcoverURL)
} else {
m := coverRegEx.FindStringSubmatch(strings.TrimSpace(e.ChildAttr(`.c-webxr-splash-screen`, "style")))
if len(m) > 0 && len(m[1]) > 0 {
sc.Covers = append(sc.Covers, m[1])
posterURLFound := false
e.ForEach(`script[type="text/javascript"]`, func(id int, e *colly.HTMLElement) {
if posterURLFound {
return
}
}
scriptContent := e.Text
if strings.Contains(scriptContent, "posterURL") {
startIndex := strings.Index(scriptContent, `"posterURL":"`) + len(`"posterURL":"`)
endIndex := strings.Index(scriptContent[startIndex:], `"`)
if startIndex >= 0 && endIndex >= 0 {
posterURL := scriptContent[startIndex : startIndex+endIndex]
unescapedURL, err := url.QueryUnescape(posterURL)
sc.Covers = append(sc.Covers, unescapedURL)
posterURLFound = true
}
}
})
}

// straight and trans videos use a different page structure
Expand Down

0 comments on commit 436abb0

Please sign in to comment.