Commit 78aefd71b1
Unsigned
Layout: unified · split
cmd/curd/main.go +29 −2
| @@ -185,6 +185,28 @@ func main() { | ||
| 185 | 185 | |
| 186 | 186 | anime.Ep.Player.Speed = 1.0 |
| 187 | 187 | |
| 188 | // Get filler list concurrently | |
| 189 | go func() { | |
| 190 | // Get MAL ID first if not already set | |
| 191 | if anime.MalId == 0 { | |
| 192 | malID, err := internal.GetAnimeMalID(anime.AnilistId) | |
| 193 | if err != nil { | |
| 194 | internal.Log("Error getting MAL ID: "+err.Error(), logFile) | |
| 195 | return | |
| 196 | } | |
| 197 | anime.MalId = malID | |
| 198 | } | |
| 199 | ||
| 200 | fillerList, err := internal.FetchFillerEpisodes(anime.MalId) | |
| 201 | if err != nil { | |
| 202 | internal.Log("Error getting filler list: "+err.Error(), logFile) | |
| 203 | } else { | |
| 204 | anime.FillerEpisodes = fillerList | |
| 205 | internal.Log("Filler list fetched successfully", logFile) | |
| 206 | fmt.Println("Filler episodes: ", anime.FillerEpisodes) | |
| 207 | } | |
| 208 | }() | |
| 209 | ||
| 188 | 210 | // Main loop (loop to keep starting new episodes) |
| 189 | 211 | for { |
| 190 | 212 | |
| @@ -204,7 +226,7 @@ func main() { | ||
| 204 | 226 | if err != nil { |
| 205 | 227 | internal.Log("Error setting Discord presence: "+err.Error(), logFile) |
| 206 | 228 | } |
| 207 | } else { | |
| 229 | } else if anime.MalId == 0 { | |
| 208 | 230 | anime.MalId, err = internal.GetAnimeMalID(anime.AnilistId) |
| 209 | 231 | if err != nil { |
| 210 | 232 | internal.Log("Error getting anime MAL ID: "+err.Error(), logFile) |
| @@ -220,6 +242,9 @@ func main() { | ||
| 220 | 242 | break // Break the loop and continue with playback |
| 221 | 243 | } |
| 222 | 244 | |
| 245 | // Check if episode is filler | |
| 246 | anime.Ep.IsFiller = internal.IsEpisodeFiller(anime.FillerEpisodes, anime.Ep.Number) | |
| 247 | ||
| 223 | 248 | // If not filler/recap (or skip is disabled), break and continue with playback |
| 224 | 249 | if !((anime.Ep.IsFiller && userCurdConfig.SkipFiller) || (anime.Ep.IsRecap && userCurdConfig.SkipRecap)) { |
| 225 | 250 | if anime.Ep.LastWasSkipped { |
| @@ -231,11 +256,13 @@ func main() { | ||
| 231 | 256 | // If it is filler/recap, log it and move to next episode |
| 232 | 257 | if anime.Ep.IsFiller { |
| 233 | 258 | internal.CurdOut(fmt.Sprint("Filler episode, skipping: ", anime.Ep.Number)) |
| 259 | // Get next canon episode | |
| 260 | anime.Ep.Number = internal.GetNextCanonEpisode(anime.FillerEpisodes, anime.Ep.Number) | |
| 234 | 261 | } else { |
| 235 | 262 | internal.CurdOut(fmt.Sprint("Recap episode, skipping: ", anime.Ep.Number)) |
| 263 | anime.Ep.Number++ | |
| 236 | 264 | } |
| 237 | 265 | |
| 238 | anime.Ep.Number++ | |
| 239 | 266 | anime.Ep.LastWasSkipped = true |
| 240 | 267 | anime.Ep.Started = false |
| 241 | 268 | internal.LocalUpdateAnime(databaseFile, anime.AnilistId, anime.AllanimeId, anime.Ep.Number, 0, 0, internal.GetAnimeName(anime)) |
internal/filler_list.go added +90
| @@ -0,0 +1,90 @@ | ||
| 1 | package internal | |
| 2 | ||
| 3 | import ( | |
| 4 | "encoding/json" | |
| 5 | "fmt" | |
| 6 | "net/http" | |
| 7 | "time" | |
| 8 | ) | |
| 9 | ||
| 10 | type AnimeFillerListEpisode struct { | |
| 11 | EpisodeID int `json:"mal_id"` | |
| 12 | IsFiller bool `json:"filler"` | |
| 13 | } | |
| 14 | ||
| 15 | type EpisodesResponse struct { | |
| 16 | Data []AnimeFillerListEpisode `json:"data"` | |
| 17 | Pagination struct { | |
| 18 | HasNextPage bool `json:"has_next_page"` | |
| 19 | } `json:"pagination"` | |
| 20 | } | |
| 21 | ||
| 22 | func FetchFillerEpisodes(malID int) ([]int, error) { | |
| 23 | baseURL := fmt.Sprintf("https://api.jikan.moe/v4/anime/%d/episodes", malID) | |
| 24 | var fillerEpisodes []int | |
| 25 | page := 1 | |
| 26 | rateLimiter := time.NewTicker(334 * time.Millisecond) // ~3 requests per second | |
| 27 | defer rateLimiter.Stop() | |
| 28 | ||
| 29 | for { | |
| 30 | <-rateLimiter.C // Wait for rate limit | |
| 31 | url := fmt.Sprintf("%s?page=%d", baseURL, page) | |
| 32 | resp, err := http.Get(url) | |
| 33 | if err != nil { | |
| 34 | return nil, fmt.Errorf("error fetching episodes: %v", err) | |
| 35 | } | |
| 36 | ||
| 37 | if resp.StatusCode == http.StatusTooManyRequests { | |
| 38 | // Wait for 2 seconds and retry | |
| 39 | time.Sleep(2 * time.Second) | |
| 40 | continue | |
| 41 | } | |
| 42 | ||
| 43 | if resp.StatusCode != http.StatusOK { | |
| 44 | resp.Body.Close() | |
| 45 | return nil, fmt.Errorf("received non-200 response: %d", resp.StatusCode) | |
| 46 | } | |
| 47 | ||
| 48 | var episodesResp EpisodesResponse | |
| 49 | if err := json.NewDecoder(resp.Body).Decode(&episodesResp); err != nil { | |
| 50 | resp.Body.Close() | |
| 51 | return nil, fmt.Errorf("error decoding response: %v", err) | |
| 52 | } | |
| 53 | resp.Body.Close() | |
| 54 | ||
| 55 | for _, episode := range episodesResp.Data { | |
| 56 | if episode.IsFiller { | |
| 57 | fillerEpisodes = append(fillerEpisodes, episode.EpisodeID) | |
| 58 | } | |
| 59 | } | |
| 60 | ||
| 61 | if !episodesResp.Pagination.HasNextPage { | |
| 62 | break | |
| 63 | } | |
| 64 | page++ | |
| 65 | } | |
| 66 | ||
| 67 | return fillerEpisodes, nil | |
| 68 | } | |
| 69 | ||
| 70 | // IsEpisodeFiller checks if a given episode number is in the filler episodes list | |
| 71 | func IsEpisodeFiller(fillerEpisodes []int, episodeNumber int) bool { | |
| 72 | for _, fillerEp := range fillerEpisodes { | |
| 73 | if fillerEp == episodeNumber { | |
| 74 | return true | |
| 75 | } | |
| 76 | } | |
| 77 | return false | |
| 78 | } | |
| 79 | ||
| 80 | // GetNextCanonEpisode returns the next non-filler episode number after the current episode | |
| 81 | func GetNextCanonEpisode(fillerEpisodes []int, currentEpisode int) int { | |
| 82 | nextEpisode := currentEpisode + 1 | |
| 83 | ||
| 84 | // Keep incrementing episode number until we find a non-filler episode | |
| 85 | for IsEpisodeFiller(fillerEpisodes, nextEpisode) { | |
| 86 | nextEpisode++ | |
| 87 | } | |
| 88 | ||
| 89 | return nextEpisode | |
| 90 | } | |
internal/structs.go +1
| @@ -15,6 +15,7 @@ type Anime struct { | ||
| 15 | 15 | AnilistId int `json:"anilist_id"` // Assuming you have an Anilist ID in your struct |
| 16 | 16 | Rewatching bool |
| 17 | 17 | AllanimeId string // Can be populated as necessary |
| 18 | FillerEpisodes []int | |
| 18 | 19 | } |
| 19 | 20 | |
| 20 | 21 | type Skip struct { |