Commit 34198c64ae
Unsigned
Layout: unified · split
cmd/curd/main.go +17 −5
| @@ -70,16 +70,15 @@ func main() { | ||
| 70 | 70 | userCurdConfig.SubOrDub = "dub" |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | ||
| 74 | 73 | // Get the token from the token file |
| 75 | user.Token, err = internal.GetTokenFromFile(os.ExpandEnv("$HOME/.local/share/curd/token")) | |
| 74 | user.Token, err = internal.GetTokenFromFile(os.ExpandEnv("$HOME/Projects/curd/.local/share/curd/token")) | |
| 76 | 75 | if err != nil { |
| 77 | 76 | internal.Log("Error reading token", logFile) |
| 78 | 77 | } |
| 79 | 78 | if user.Token == "" { |
| 80 | 79 | fmt.Println("No token found, please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token") |
| 81 | 80 | fmt.Scanln(&user.Token) |
| 82 | internal.WriteTokenToFile(user.Token, os.ExpandEnv("$HOME/.local/share/curd/token")) | |
| 81 | internal.WriteTokenToFile(user.Token, os.ExpandEnv("$HOME/Projects/curd/.local/share/curd/token")) | |
| 83 | 82 | } |
| 84 | 83 | |
| 85 | 84 | // Load anime in database |
| @@ -139,6 +138,7 @@ func main() { | ||
| 139 | 138 | internal.Log("Filler episode detected", logFile) |
| 140 | 139 | anime.Ep.Number++ |
| 141 | 140 | anime.Ep.Started = false |
| 141 | anime.Ep.IsCompleted = true | |
| 142 | 142 | internal.Log("Skipping filler episode, starting next.", logFile) |
| 143 | 143 | internal.LocalUpdateAnime(databaseFile, anime.AnilistId, anime.AllanimeId, anime.Ep.Number, anime.Ep.Player.PlaybackTime, internal.GetAnimeName(anime)) |
| 144 | 144 | // Send command to close MPV |
| @@ -198,18 +198,23 @@ func main() { | ||
| 198 | 198 | if err != nil { |
| 199 | 199 | internal.Log("Error getting playback time: "+err.Error(), logFile) |
| 200 | 200 | |
| 201 | // Check if the error is due to invalid JSON | |
| 201 | 202 | // User closed the video |
| 202 | 203 | if anime.Ep.Started { |
| 203 | 204 | percentageWatched := internal.PercentageWatched(anime.Ep.Player.PlaybackTime, anime.Ep.Duration) |
| 205 | // Episode is completed | |
| 204 | 206 | if int(percentageWatched) >= userCurdConfig.PercentageToMarkComplete { |
| 205 | 207 | anime.Ep.Number++ |
| 206 | 208 | anime.Ep.Started = false |
| 207 | 209 | internal.Log("Completed episode, starting next.", logFile) |
| 210 | anime.Ep.IsCompleted = true | |
| 208 | 211 | // Exit the skip loop |
| 209 | 212 | close(skipLoopDone) |
| 210 | } else { | |
| 213 | } else if fmt.Sprintf("%v", err) != "invalid character '{' after top-level value" { // Episode is not completed | |
| 211 | 214 | fmt.Println("Have a great day!") |
| 212 | 215 | internal.ExitCurd() |
| 216 | } else { | |
| 217 | internal.Log("Received invalid JSON response, continuing...", logFile) | |
| 213 | 218 | } |
| 214 | 219 | } |
| 215 | 220 | continue |
| @@ -248,7 +253,7 @@ func main() { | ||
| 248 | 253 | }() |
| 249 | 254 | |
| 250 | 255 | // Skip OP and ED |
| 251 | skipLoop: | |
| 256 | skipLoop: | |
| 252 | 257 | for { |
| 253 | 258 | select { |
| 254 | 259 | case <-skipLoopDone: |
| @@ -276,6 +281,13 @@ func main() { | ||
| 276 | 281 | // Reset the WaitGroup for the next loop |
| 277 | 282 | wg = sync.WaitGroup{} |
| 278 | 283 | |
| 284 | // Update Anilist progress | |
| 285 | fmt.Println("Starting next episode: "+fmt.Sprint(anime.Ep.Number)) | |
| 286 | if anime.Ep.IsCompleted { | |
| 287 | go internal.UpdateAnimeProgress(user.Token, anime.AnilistId, anime.Ep.Number) | |
| 288 | anime.Ep.IsCompleted = false | |
| 289 | } | |
| 290 | ||
| 279 | 291 | continue |
| 280 | 292 | } |
| 281 | 293 | } |