Skip to content

Commit

Permalink
fix: crash when fetching SLR cover images (xbapps#1841)
Browse files Browse the repository at this point in the history
* Attempted Fix

* Should Fix Nil Pointer Error

Nested the body close function inside the if else statement for the error. Also moved nested all logic inside this so the body close is still acted upon logic completion.

* go fmt
  • Loading branch information
pops64 authored Oct 22, 2024
1 parent 3864480 commit e87b311
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions pkg/scrape/slrstudios.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,28 +149,39 @@ func SexLikeReal(wg *models.ScrapeWG, updateSite bool, knownScenes []string, out
// Cover
if !isTransScene {
appCover := gjson.Get(JsonMetadataA, "thumbnailUrl").String()
desktopCover := strings.Replace(gjson.Get(JsonMetadataA, "thumbnailUrl").String(), "app", "desktop", -1)
desktopCresp, err := http.Head(desktopCover)
if err != nil {
log.Errorf("Method Head Failed on desktopCover %s with error %s", desktopCover, err)
} else if desktopCresp.StatusCode == 200 {
coverURL := desktopCover
sc.Covers = append(sc.Covers, coverURL)
} else {
appCresp, err := http.Head(appCover)

if appCover != "" {

desktopCover := strings.Replace(appCover, "app", "desktop", -1)
desktopCresp, err := http.Head(desktopCover)

if err != nil {
log.Errorf("Method Head Failed on appCover %s with error %s", appCover, err)
} else if appCresp.StatusCode == 200 {
coverURL := appCover
sc.Covers = append(sc.Covers, coverURL)
log.Errorln("Method Head Failed on desktopCover", desktopCover, "with error", err)
} else {
e.ForEach(`link[as="image"]`, func(id int, e *colly.HTMLElement) {
sc.Covers = append(sc.Covers, e.Request.AbsoluteURL(e.Attr("href")))
})
if desktopCresp.StatusCode == 200 {
coverURL := desktopCover
sc.Covers = append(sc.Covers, coverURL)
} else {
appCresp, err := http.Head(appCover)
if err != nil {
log.Errorln("Method Head Failed on appCover", appCover, "with error", err)
} else {
if appCresp.StatusCode == 200 {
coverURL := appCover
sc.Covers = append(sc.Covers, coverURL)
} else {
e.ForEach(`link[as="image"]`, func(id int, e *colly.HTMLElement) {
sc.Covers = append(sc.Covers, e.Request.AbsoluteURL(e.Attr("href")))
})
}
defer appCresp.Body.Close()
}
}
defer desktopCresp.Body.Close()
}
defer appCresp.Body.Close()
} else {
log.Errorln("No thumnailURL available")
}
defer desktopCresp.Body.Close()
} else {
posterURLFound := false
e.ForEach(`script[type="text/javascript"]`, func(id int, e *colly.HTMLElement) {
Expand Down

0 comments on commit e87b311

Please sign in to comment.