Commit 34198c64ae

34198c64ae6f5dba70bbeb92681c898301c3a7f8

parent: f3820defe2

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-22 17:20 UTC

Checkpoint: I think its time

Layout: unified · split

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