Skip to content

Commit

Permalink
fix: Filler skip works are a block of filler episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraient committed Dec 18, 2024
1 parent c71c910 commit 3957bf0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
40 changes: 33 additions & 7 deletions cmd/curd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 10 additions & 2 deletions internal/jikan.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,23 @@ 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)

// 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 {
Expand Down

0 comments on commit 3957bf0

Please sign in to comment.