Commit 22c5b81107

22c5b81107d67a47bbdd18bdf46b98bc7e73c4f5

parent: 9054037964

Unsigned

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

Add: Error logging

Layout: unified · split

cmd/curd/main.go +11 −7
@@ -154,31 +154,29 @@ func main() {
154154 time.Sleep(1 * time.Second)
155155
156156 // Get current playback time
157 internal.Log("Getting playback time"+anime.Ep.Player.SocketPath, logFile)
157 internal.Log("Getting playback time "+anime.Ep.Player.SocketPath, logFile)
158158 timePos, err := internal.MPVSendCommand(anime.Ep.Player.SocketPath, []interface{}{"get_property", "time-pos"})
159159 if err != nil {
160160 internal.Log("Error getting playback time: "+err.Error(), logFile)
161161
162162 // User closed the video
163163 if anime.Ep.Started {
164
165164 if int(*internal.PercentageWatched(anime.Ep.Player.PlaybackTime, anime.Ep.Duration)) >= userCurdConfig.PercentageToMarkComplete {
166165 anime.Ep.Number++
167166 anime.Ep.Started = false
168167 internal.Log("Completed episode, starting next.", logFile)
169168 // Exit the skip loop
170169 close(skipLoopDone)
171 // continue
172 } else{
170 } else {
173171 fmt.Println("Have a great day!")
174172 os.Exit(0)
175173 }
176
177174 }
175 continue
178176 }
179177
180178 // Convert timePos to integer
181 if timePos != nil && err == nil {
179 if timePos != nil {
182180 if !anime.Ep.Started {
183181 anime.Ep.Started = true
184182 }
@@ -197,7 +195,13 @@ func main() {
197195
198196 anime.Ep.Player.PlaybackTime = int(animePosition + 0.5) // Round to nearest integer
199197 // Update Local Database
200 internal.LocalUpdateAnime(databaseFile, anime.AnilistId, anime.AllanimeId, anime.Ep.Number, anime.Ep.Player.PlaybackTime, anime.Title.English)
198 err = internal.LocalUpdateAnime(databaseFile, anime.AnilistId, anime.AllanimeId, anime.Ep.Number, anime.Ep.Player.PlaybackTime, anime.Title.English)
199 if err != nil {
200 internal.Log("Error updating local database: "+err.Error(), logFile)
201 } else {
202 internal.Log(fmt.Sprintf("Updated database: AnilistId=%d, AllanimeId=%s, EpNumber=%d, PlaybackTime=%d",
203 anime.AnilistId, anime.AllanimeId, anime.Ep.Number, anime.Ep.Player.PlaybackTime), logFile)
204 }
201205 }
202206 }
203207 }