From f8cc0d16255124975ef5e166e579db3f7a8ca583 Mon Sep 17 00:00:00 2001 From: mkelvers Date: Sat, 2 May 2026 17:01:52 +0200 Subject: [PATCH] feat: handle additional episode image placeholder --- integrations/jikan/episodes.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/integrations/jikan/episodes.go b/integrations/jikan/episodes.go index 4e5ec2b..0f24897 100644 --- a/integrations/jikan/episodes.go +++ b/integrations/jikan/episodes.go @@ -12,17 +12,33 @@ import ( ) const bannedImageURL = "https://myanimelist.net/images/icon-banned-youtube.png" +const placeholderImageURL = "https://myanimelist.net/images/episodes/videos/icon-thumbs-not-available.png" var httpClient = &http.Client{Timeout: 10 * time.Second} func (e *Episode) GetFallbackImage(animeID int) string { - if e.Images == nil || e.Images.Jpg.ImageURL != bannedImageURL { - return e.Images.Jpg.ImageURL + imageUrl := "" + if e.Images != nil { + imageUrl = e.Images.Jpg.ImageURL + } + + if imageUrl != bannedImageURL && imageUrl != placeholderImageURL && imageUrl != "" { + return imageUrl } episodeNum := 1 if e.Episode != "" { - episodeNum, _ = strconv.Atoi(e.Episode) + // e.Episode can be "Episode 1" or just "1" + re := regexp.MustCompile(`\d+`) + match := re.FindString(e.Episode) + if match != "" { + episodeNum, _ = strconv.Atoi(match) + } else { + episodeNum, _ = strconv.Atoi(e.Episode) + } + } + if episodeNum == 0 { + episodeNum = e.MalID } episodeURL := fmt.Sprintf("https://myanimelist.net/anime/%d/episode/%d", animeID, episodeNum)