From e87b311731d5d9d468d1678a5ffce83fd2749768 Mon Sep 17 00:00:00 2001 From: pops64 Date: Tue, 22 Oct 2024 11:05:31 -0400 Subject: [PATCH] fix: crash when fetching SLR cover images (#1841) * 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 --- pkg/scrape/slrstudios.go | 47 +++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/pkg/scrape/slrstudios.go b/pkg/scrape/slrstudios.go index d02eff5f2..14688e981 100644 --- a/pkg/scrape/slrstudios.go +++ b/pkg/scrape/slrstudios.go @@ -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) {