chore: formatting

This commit is contained in:
2026-05-03 00:10:49 +02:00
parent 1eec0b2d5b
commit 4ba4e51d95
2 changed files with 10 additions and 10 deletions

View File

@@ -488,23 +488,23 @@ func (h *Handler) HandleEpisodeThumbnails(w http.ResponseWriter, r *http.Request
} }
results := make([]ThumbResult, len(unique)) results := make([]ThumbResult, len(unique))
// Use a semaphore to limit concurrent scraping requests to avoid MAL bans // Use a semaphore to limit concurrent scraping requests to avoid MAL bans
sem := make(chan struct{}, 2) sem := make(chan struct{}, 2)
var wg sync.WaitGroup var wg sync.WaitGroup
for i := range unique { for i := range unique {
wg.Add(1) wg.Add(1)
go func(idx int) { go func(idx int) {
defer wg.Done() defer wg.Done()
sem <- struct{}{} // Acquire sem <- struct{}{} // Acquire
// Add a small jittered delay between requests to avoid 405/429 // Add a small jittered delay between requests to avoid 405/429
time.Sleep(time.Duration(200+idx%300) * time.Millisecond) time.Sleep(time.Duration(200+idx%300) * time.Millisecond)
defer func() { <-sem }() // Release defer func() { <-sem }() // Release
ep := unique[idx] ep := unique[idx]
imgURL := ep.GetFallbackImage(id) imgURL := ep.GetFallbackImage(id)
results[idx] = ThumbResult{ results[idx] = ThumbResult{

View File

@@ -83,7 +83,7 @@ func scrapeAnimeImageFromEpisodePage(episodeURL string, episodeNum int) string {
// MAL sometimes redirects to a URL with a slug. // MAL sometimes redirects to a URL with a slug.
// We look for the "thumbnail" field in the page source. // We look for the "thumbnail" field in the page source.
// Pattern 1: Look for the specific episode object in the JSON data // Pattern 1: Look for the specific episode object in the JSON data
episodeStr := strconv.Itoa(episodeNum) episodeStr := strconv.Itoa(episodeNum)
objPattern := regexp.MustCompile(`\{[^{}]*"episode_number":\s*` + episodeStr + `[^{}]*\}`) objPattern := regexp.MustCompile(`\{[^{}]*"episode_number":\s*` + episodeStr + `[^{}]*\}`)
@@ -101,7 +101,7 @@ func scrapeAnimeImageFromEpisodePage(episodeURL string, episodeNum int) string {
return strings.ReplaceAll(thumbMatch[1], `\/`, `/`) return strings.ReplaceAll(thumbMatch[1], `\/`, `/`)
} }
} }
// Pattern 2: Fallback to og:image if it's the specific episode page // Pattern 2: Fallback to og:image if it's the specific episode page
ogRe := regexp.MustCompile(`<meta\s+property="og:image"\s+content="([^"]+)"`) ogRe := regexp.MustCompile(`<meta\s+property="og:image"\s+content="([^"]+)"`)
ogMatch := ogRe.FindStringSubmatch(html) ogMatch := ogRe.FindStringSubmatch(html)
@@ -174,7 +174,7 @@ func (c *Client) GetAllEpisodes(ctx context.Context, animeID int) ([]Episode, er
pageSize := 100 pageSize := 100
lastPage := (totalEpisodes + (pageSize - 1)) / pageSize lastPage := (totalEpisodes + (pageSize - 1)) / pageSize
var allEpisodes []Episode var allEpisodes []Episode
// Fetch last page first (to get most recent episodes immediately) // Fetch last page first (to get most recent episodes immediately)
lastResp, err := c.GetEpisodes(ctx, animeID, lastPage) lastResp, err := c.GetEpisodes(ctx, animeID, lastPage)
if err == nil { 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 // Start from lastPage - 1 and go down to 1
for p := lastPage - 1; p >= 1; p-- { for p := lastPage - 1; p >= 1; p-- {
_, _ = c.GetEpisodes(bgCtx, animeID, p) _, _ = c.GetEpisodes(bgCtx, animeID, p)
// Also pre-fetch the video episodes metadata (39 per page) // Also pre-fetch the video episodes metadata (39 per page)
// to warm the cache for thumbnails // to warm the cache for thumbnails
videoPageSize := 39 videoPageSize := 39