Skip to content

Commit

Permalink
API: Use filter instead of maybemap
Browse files Browse the repository at this point in the history
  • Loading branch information
Fesaa committed Oct 18, 2024
1 parent aa6e927 commit 9142641
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions webtoon/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func constructSeriesInfo(id string) (*Series, error) {
series.Completed = strings.Contains(detail.Find(".day_info").Text(), "COMPLETED")
series.Chapters = append(series.Chapters, extractChapters(doc)...)

pages := utils.MaybeMap(goquery.Map(doc.Find(".paginate a"), href), notEmpty)
pages := utils.Filter(goquery.Map(doc.Find(".paginate a"), href), notEmpty)
for index := 1; len(pages) > index; index++ {
doc, err = wrapInDoc(DOMAIN + pages[index])
if err != nil {
Expand All @@ -38,7 +38,7 @@ func constructSeriesInfo(id string) (*Series, error) {
}

series.Chapters = append(series.Chapters, extractChapters(doc)...)
pages = utils.MaybeMap(goquery.Map(doc.Find(".paginate a"), href), notEmpty)
pages = utils.Filter(goquery.Map(doc.Find(".paginate a"), href), notEmpty)
// Sleep a bit between these requests, to not spam them if the pages are a too high amount
// The time is small enough to not matter, downloading the images will always take longer.
time.Sleep(500 * time.Millisecond)
Expand All @@ -64,8 +64,8 @@ func extractChapters(doc *goquery.Document) (chapters []Chapter) {
})
}

func notEmpty(s string) (string, bool) {
return s, s != ""
func notEmpty(s string) bool {
return s != ""
}

func href(_ int, selection *goquery.Selection) string {
Expand Down

0 comments on commit 9142641

Please sign in to comment.