From 4ba4e51d95d3b5cd3497fa6ae676cfaf05da2bcc Mon Sep 17 00:00:00 2001 From: mkelvers Date: Sun, 3 May 2026 00:10:49 +0200 Subject: [PATCH] chore: formatting --- api/playback/handler.go | 12 ++++++------ integrations/jikan/episodes.go | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/playback/handler.go b/api/playback/handler.go index a4c78a2..3edea41 100644 --- a/api/playback/handler.go +++ b/api/playback/handler.go @@ -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{ diff --git a/integrations/jikan/episodes.go b/integrations/jikan/episodes.go index dbc1d73..dd3f4e4 100644 --- a/integrations/jikan/episodes.go +++ b/integrations/jikan/episodes.go @@ -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(`= 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