chore: formatting
This commit is contained in:
@@ -488,23 +488,23 @@ func (h *Handler) HandleEpisodeThumbnails(w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
|
||||
results := make([]ThumbResult, len(unique))
|
||||
|
||||
|
||||
// Use a semaphore to limit concurrent scraping requests to avoid MAL bans
|
||||
sem := make(chan struct{}, 2)
|
||||
var wg sync.WaitGroup
|
||||
|
||||
|
||||
for i := range unique {
|
||||
wg.Add(1)
|
||||
go func(idx int) {
|
||||
defer wg.Done()
|
||||
|
||||
|
||||
sem <- struct{}{} // Acquire
|
||||
|
||||
|
||||
// Add a small jittered delay between requests to avoid 405/429
|
||||
time.Sleep(time.Duration(200+idx%300) * time.Millisecond)
|
||||
|
||||
|
||||
defer func() { <-sem }() // Release
|
||||
|
||||
|
||||
ep := unique[idx]
|
||||
imgURL := ep.GetFallbackImage(id)
|
||||
results[idx] = ThumbResult{
|
||||
|
||||
@@ -83,7 +83,7 @@ func scrapeAnimeImageFromEpisodePage(episodeURL string, episodeNum int) string {
|
||||
|
||||
// MAL sometimes redirects to a URL with a slug.
|
||||
// We look for the "thumbnail" field in the page source.
|
||||
|
||||
|
||||
// Pattern 1: Look for the specific episode object in the JSON data
|
||||
episodeStr := strconv.Itoa(episodeNum)
|
||||
objPattern := regexp.MustCompile(`\{[^{}]*"episode_number":\s*` + episodeStr + `[^{}]*\}`)
|
||||
@@ -101,7 +101,7 @@ func scrapeAnimeImageFromEpisodePage(episodeURL string, episodeNum int) string {
|
||||
return strings.ReplaceAll(thumbMatch[1], `\/`, `/`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pattern 2: Fallback to og:image if it's the specific episode page
|
||||
ogRe := regexp.MustCompile(`<meta\s+property="og:image"\s+content="([^"]+)"`)
|
||||
ogMatch := ogRe.FindStringSubmatch(html)
|
||||
@@ -174,7 +174,7 @@ func (c *Client) GetAllEpisodes(ctx context.Context, animeID int) ([]Episode, er
|
||||
pageSize := 100
|
||||
lastPage := (totalEpisodes + (pageSize - 1)) / pageSize
|
||||
var allEpisodes []Episode
|
||||
|
||||
|
||||
// Fetch last page first (to get most recent episodes immediately)
|
||||
lastResp, err := c.GetEpisodes(ctx, animeID, lastPage)
|
||||
if err == nil {
|
||||
@@ -190,7 +190,7 @@ func (c *Client) GetAllEpisodes(ctx context.Context, animeID int) ([]Episode, er
|
||||
// Start from lastPage - 1 and go down to 1
|
||||
for p := lastPage - 1; p >= 1; p-- {
|
||||
_, _ = c.GetEpisodes(bgCtx, animeID, p)
|
||||
|
||||
|
||||
// Also pre-fetch the video episodes metadata (39 per page)
|
||||
// to warm the cache for thumbnails
|
||||
videoPageSize := 39
|
||||
|
||||
Reference in New Issue
Block a user