Commit 22c5b81107
Unsigned
Layout: unified · split
cmd/curd/main.go +11 −7
| @@ -154,31 +154,29 @@ func main() { | |||
| 154 | time.Sleep(1 * time.Second) | 154 | time.Sleep(1 * time.Second) |
| 155 | 155 | ||
| 156 | // Get current playback time | 156 | // 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) |
| 158 | timePos, err := internal.MPVSendCommand(anime.Ep.Player.SocketPath, []interface{}{"get_property", "time-pos"}) | 158 | timePos, err := internal.MPVSendCommand(anime.Ep.Player.SocketPath, []interface{}{"get_property", "time-pos"}) |
| 159 | if err != nil { | 159 | if err != nil { |
| 160 | internal.Log("Error getting playback time: "+err.Error(), logFile) | 160 | internal.Log("Error getting playback time: "+err.Error(), logFile) |
| 161 | 161 | ||
| 162 | // User closed the video | 162 | // User closed the video |
| 163 | if anime.Ep.Started { | 163 | if anime.Ep.Started { |
| 164 | |||
| 165 | if int(*internal.PercentageWatched(anime.Ep.Player.PlaybackTime, anime.Ep.Duration)) >= userCurdConfig.PercentageToMarkComplete { | 164 | if int(*internal.PercentageWatched(anime.Ep.Player.PlaybackTime, anime.Ep.Duration)) >= userCurdConfig.PercentageToMarkComplete { |
| 166 | anime.Ep.Number++ | 165 | anime.Ep.Number++ |
| 167 | anime.Ep.Started = false | 166 | anime.Ep.Started = false |
| 168 | internal.Log("Completed episode, starting next.", logFile) | 167 | internal.Log("Completed episode, starting next.", logFile) |
| 169 | // Exit the skip loop | 168 | // Exit the skip loop |
| 170 | close(skipLoopDone) | 169 | close(skipLoopDone) |
| 171 | // continue | 170 | } else { |
| 172 | } else{ | ||
| 173 | fmt.Println("Have a great day!") | 171 | fmt.Println("Have a great day!") |
| 174 | os.Exit(0) | 172 | os.Exit(0) |
| 175 | } | 173 | } |
| 176 | |||
| 177 | } | 174 | } |
| 175 | continue | ||
| 178 | } | 176 | } |
| 179 | 177 | ||
| 180 | // Convert timePos to integer | 178 | // Convert timePos to integer |
| 181 | if timePos != nil && err == nil { | 179 | if timePos != nil { |
| 182 | if !anime.Ep.Started { | 180 | if !anime.Ep.Started { |
| 183 | anime.Ep.Started = true | 181 | anime.Ep.Started = true |
| 184 | } | 182 | } |
| @@ -197,7 +195,13 @@ func main() { | |||
| 197 | 195 | ||
| 198 | anime.Ep.Player.PlaybackTime = int(animePosition + 0.5) // Round to nearest integer | 196 | anime.Ep.Player.PlaybackTime = int(animePosition + 0.5) // Round to nearest integer |
| 199 | // Update Local Database | 197 | // 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 | } | ||
| 201 | } | 205 | } |
| 202 | } | 206 | } |
| 203 | } | 207 | } |