From 3957bf0a4174d04bba56332d63de7f4cf17922a3 Mon Sep 17 00:00:00 2001 From: Wraient Date: Wed, 18 Dec 2024 22:33:51 +0530 Subject: [PATCH] fix: Filler skip works are a block of filler episodes --- cmd/curd/main.go | 40 +++++++++++++++++++++++++++++++++------- internal/jikan.go | 12 ++++++++++-- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/cmd/curd/main.go b/cmd/curd/main.go index f088cfd..8be812d 100644 --- a/cmd/curd/main.go +++ b/cmd/curd/main.go @@ -212,16 +212,42 @@ func main() { } // Start curd - if !((anime.Ep.IsFiller && userCurdConfig.SkipFiller) || (anime.Ep.IsRecap && userCurdConfig.SkipRecap)) { - // fmt.Println("Not a filler episode, Starting: ", anime.Ep.Number) - anime.Ep.Player.SocketPath = internal.StartCurd(&userCurdConfig, &anime, logFile) + for { + // Check if current episode is filler/recap + err = internal.GetEpisodeData(anime.MalId, anime.Ep.Number, &anime) + if err != nil { + internal.Log("Error getting episode data, assuming non-filler: "+err.Error(), logFile) + break // Break the loop and continue with playback + } - internal.Log(fmt.Sprint("Playback starting time: ", anime.Ep.Player.PlaybackTime), logFile) - internal.Log(anime.Ep.Player.SocketPath, logFile) - } else { - internal.CurdOut(fmt.Sprint("Filler episode, skipping: ", anime.Ep.Number)) + // If not filler/recap (or skip is disabled), break and continue with playback + if !((anime.Ep.IsFiller && userCurdConfig.SkipFiller) || (anime.Ep.IsRecap && userCurdConfig.SkipRecap)) { + break + } + + // If it is filler/recap, log it and move to next episode + if anime.Ep.IsFiller { + internal.CurdOut(fmt.Sprint("Filler episode, skipping: ", anime.Ep.Number)) + } else { + internal.CurdOut(fmt.Sprint("Recap episode, skipping: ", anime.Ep.Number)) + } + + anime.Ep.Number++ + anime.Ep.Started = false + internal.LocalUpdateAnime(databaseFile, anime.AnilistId, anime.AllanimeId, anime.Ep.Number, 0, 0, internal.GetAnimeName(anime)) + + // Check if we've reached the end of the series + if anime.Ep.Number > anime.TotalEpisodes { + internal.CurdOut("Reached end of series") + internal.ExitCurd(nil) + } } + // Now start playback for the non-filler episode + anime.Ep.Player.SocketPath = internal.StartCurd(&userCurdConfig, &anime, logFile) + internal.Log(fmt.Sprint("Playback starting time: ", anime.Ep.Player.PlaybackTime), logFile) + internal.Log(anime.Ep.Player.SocketPath, logFile) + wg.Add(1) // Get episode data go func() { diff --git a/internal/jikan.go b/internal/jikan.go index 2e22e7d..068898f 100644 --- a/internal/jikan.go +++ b/internal/jikan.go @@ -14,7 +14,11 @@ func GetEpisodeData(animeID int, episodeNo int, anime *Anime) error { // Use the helper function for making the GET request response, err := makeGetRequest(url, nil) if err != nil { - return fmt.Errorf("error fetching data from Jikan (MyAnimeList) API: %w", err) + Log(fmt.Sprintf("Warning: Jikan API error: %v - continuing without filler data", err), logFile) + // Set default values when API fails + anime.Ep.IsFiller = false + anime.Ep.IsRecap = false + return nil // Return nil to allow the application to continue } Log(response, logFile) @@ -22,7 +26,11 @@ func GetEpisodeData(animeID int, episodeNo int, anime *Anime) error { // Check if the 'data' field exists and is valid data, ok := response["data"].(map[string]interface{}) if !ok { - return fmt.Errorf("invalid response structure: missing or invalid 'data' field") + Log("Warning: Invalid Jikan API response - continuing without filler data", logFile) + // Set default values when response is invalid + anime.Ep.IsFiller = false + anime.Ep.IsRecap = false + return nil // Return nil to allow the application to continue } // Helper function to safely get string value getStringValue := func(field string) string {