Commit e9d51690d8
Unsigned
Layout: unified · split
cmd/curd/main.go +11 −4
| @@ -163,7 +163,7 @@ func main() { | ||
| 163 | 163 | anime.Ep.Started = false |
| 164 | 164 | anime.Ep.IsCompleted = true |
| 165 | 165 | internal.Log("Skipping filler episode, starting next.", logFile) |
| 166 | internal.LocalUpdateAnime(databaseFile, anime.AnilistId, anime.AllanimeId, anime.Ep.Number, anime.Ep.Player.PlaybackTime, internal.GetAnimeName(anime)) | |
| 166 | internal.LocalUpdateAnime(databaseFile, anime.AnilistId, anime.AllanimeId, anime.Ep.Number, anime.Ep.Player.PlaybackTime, internal.ConvertSecondsToMinutes(anime.Ep.Duration), internal.GetAnimeName(anime)) | |
| 167 | 167 | // Send command to close MPV |
| 168 | 168 | _, err := internal.MPVSendCommand(anime.Ep.Player.SocketPath, []interface{}{"quit"}) |
| 169 | 169 | if err != nil { |
| @@ -188,7 +188,7 @@ func main() { | ||
| 188 | 188 | default: |
| 189 | 189 | err = internal.DiscordPresence(discordClientId, anime) |
| 190 | 190 | if err != nil { |
| 191 | internal.Log("Error setting Discord presence: "+err.Error(), logFile) | |
| 191 | // internal.Log("Error setting Discord presence: "+err.Error(), logFile) | |
| 192 | 192 | } |
| 193 | 193 | time.Sleep(1 * time.Second) |
| 194 | 194 | } |
| @@ -204,9 +204,9 @@ func main() { | ||
| 204 | 204 | internal.Log(anime.Ep.SkipTimes, logFile) |
| 205 | 205 | }() |
| 206 | 206 | |
| 207 | // Get video duration | |
| 207 | 208 | go func() { |
| 208 | 209 | for { |
| 209 | ||
| 210 | 210 | if anime.Ep.Started { |
| 211 | 211 | if anime.Ep.Duration == 0 { |
| 212 | 212 | // Get video duration |
| @@ -224,6 +224,7 @@ func main() { | ||
| 224 | 224 | break |
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | time.Sleep(1 * time.Second) | |
| 227 | 228 | } |
| 228 | 229 | }() |
| 229 | 230 | |
| @@ -295,7 +296,7 @@ func main() { | ||
| 295 | 296 | |
| 296 | 297 | anime.Ep.Player.PlaybackTime = int(animePosition + 0.5) // Round to nearest integer |
| 297 | 298 | // Update Local Database |
| 298 | err = internal.LocalUpdateAnime(databaseFile, anime.AnilistId, anime.AllanimeId, anime.Ep.Number, anime.Ep.Player.PlaybackTime, internal.GetAnimeName(anime)) | |
| 299 | err = internal.LocalUpdateAnime(databaseFile, anime.AnilistId, anime.AllanimeId, anime.Ep.Number, anime.Ep.Player.PlaybackTime, internal.ConvertSecondsToMinutes(anime.Ep.Duration), internal.GetAnimeName(anime)) | |
| 299 | 300 | if err != nil { |
| 300 | 301 | internal.Log("Error updating local database: "+err.Error(), logFile) |
| 301 | 302 | } else { |
| @@ -366,5 +367,11 @@ func main() { | ||
| 366 | 367 | internal.ExitCurd() |
| 367 | 368 | } |
| 368 | 369 | } |
| 370 | if anime.Rewatching && anime.Ep.IsCompleted && anime.Ep.Number-1 == anime.TotalEpisodes { | |
| 371 | anime.Ep.Number = anime.Ep.Number - 1 | |
| 372 | fmt.Println("Completed anime. (Rewatching so no scoring)") | |
| 373 | internal.LocalDeleteAnime(databaseFile, anime.AnilistId, anime.AllanimeId) | |
| 374 | internal.ExitCurd() | |
| 375 | } | |
| 369 | 376 | } |
| 370 | 377 | } |
internal/curd.go +9
| @@ -243,6 +243,15 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni | ||
| 243 | 243 | anime.Ep.Number = animePointer.Ep.Number |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | // If upstream is ahead, update the episode number | |
| 247 | if temp_anime, err := FindAnimeByAnilistID(user.AnimeList, strconv.Itoa(anime.AnilistId)); err == nil { | |
| 248 | if temp_anime.Progress > anime.Ep.Number { | |
| 249 | anime.Ep.Number = temp_anime.Progress | |
| 250 | anime.Ep.Player.PlaybackTime = 0 | |
| 251 | anime.Ep.Resume = false | |
| 252 | } | |
| 253 | } | |
| 254 | ||
| 246 | 255 | if anime.TotalEpisodes == 0 { |
| 247 | 256 | // Get updated anime data |
| 248 | 257 | Log(selectedAllanimeAnime, logFile) |
internal/discord.go +3 −3
| @@ -17,9 +17,9 @@ func DiscordPresence(clientId string, anime Anime) error { | ||
| 17 | 17 | LargeText: GetAnimeName(anime), // Would display while hovering over the large image |
| 18 | 18 | State: fmt.Sprintf("\nEpisode %d - %d:%02d / %d:%02d", |
| 19 | 19 | anime.Ep.Number, |
| 20 | convertSecondsToMinutes(anime.Ep.Player.PlaybackTime), | |
| 20 | ConvertSecondsToMinutes(anime.Ep.Player.PlaybackTime), | |
| 21 | 21 | anime.Ep.Player.PlaybackTime % 60, |
| 22 | convertSecondsToMinutes(anime.Ep.Duration), | |
| 22 | ConvertSecondsToMinutes(anime.Ep.Duration), | |
| 23 | 23 | anime.Ep.Duration % 60), |
| 24 | 24 | // SmallImage: anime.CoverImage, // Image would appear in the bottom left corner |
| 25 | 25 | // SmallText: fmt.Sprintf("%s", anime.Ep.Title.English), // Would display while hovering over the small image |
| @@ -40,6 +40,6 @@ func DiscordPresence(clientId string, anime Anime) error { | ||
| 40 | 40 | return nil |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | func convertSecondsToMinutes(seconds int) int { | |
| 43 | func ConvertSecondsToMinutes(seconds int) int { | |
| 44 | 44 | return seconds / 60 |
| 45 | 45 | } |
internal/localTracking.go +10 −2
| @@ -9,7 +9,7 @@ import ( | ||
| 9 | 9 | ) |
| 10 | 10 | |
| 11 | 11 | // Function to add an anime entry |
| 12 | func LocalAddAnime(databaseFile string, anilistID int, allanimeID string, watchingEpisode int, watchingTime int, animeName string) { | |
| 12 | func LocalAddAnime(databaseFile string, anilistID int, allanimeID string, watchingEpisode int, watchingTime int, animeDuration int, animeName string) { | |
| 13 | 13 | file, err := os.OpenFile(databaseFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644) |
| 14 | 14 | if err != nil { |
| 15 | 15 | fmt.Println("Error opening file:", err) |
| @@ -25,6 +25,7 @@ func LocalAddAnime(databaseFile string, anilistID int, allanimeID string, watchi | ||
| 25 | 25 | allanimeID, |
| 26 | 26 | strconv.Itoa(watchingEpisode), |
| 27 | 27 | strconv.Itoa(watchingTime), |
| 28 | strconv.Itoa(animeDuration), | |
| 28 | 29 | animeName, |
| 29 | 30 | }) |
| 30 | 31 | if err != nil { |
| @@ -121,6 +122,7 @@ func LocalGetAllAnime(databaseFile string) []Anime { | ||
| 121 | 122 | |
| 122 | 123 | return animeList |
| 123 | 124 | } |
| 125 | ||
| 124 | 126 | // Function to parse a single row of anime data |
| 125 | 127 | func parseAnimeRow(row []string) *Anime { |
| 126 | 128 | if len(row) < 5 { |
| @@ -131,6 +133,7 @@ func parseAnimeRow(row []string) *Anime { | ||
| 131 | 133 | anilistID, _ := strconv.Atoi(row[0]) |
| 132 | 134 | watchingEpisode, _ := strconv.Atoi(row[2]) |
| 133 | 135 | playbackTime, _ := strconv.Atoi(row[3]) |
| 136 | animeDuration, _ := strconv.Atoi(row[4]) | |
| 134 | 137 | |
| 135 | 138 | anime := &Anime{ |
| 136 | 139 | AnilistId: anilistID, |
| @@ -140,6 +143,7 @@ func parseAnimeRow(row []string) *Anime { | ||
| 140 | 143 | Player: playingVideo{ |
| 141 | 144 | PlaybackTime: playbackTime, |
| 142 | 145 | }, |
| 146 | Duration: animeDuration, | |
| 143 | 147 | }, |
| 144 | 148 | } |
| 145 | 149 | |
| @@ -157,6 +161,7 @@ func parseAnimeRow(row []string) *Anime { | ||
| 157 | 161 | |
| 158 | 162 | return anime |
| 159 | 163 | } |
| 164 | ||
| 160 | 165 | // Function to get the anime name (English or Romaji) from an Anime struct |
| 161 | 166 | func GetAnimeName(anime Anime) string { |
| 162 | 167 | if anime.Title.English != "" { |
| @@ -166,7 +171,7 @@ func GetAnimeName(anime Anime) string { | ||
| 166 | 171 | } |
| 167 | 172 | |
| 168 | 173 | // Function to update or add a new anime entry |
| 169 | func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, watchingEpisode int, playbackTime int, animeName string) error { | |
| 174 | func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, watchingEpisode int, playbackTime int, animeDuration int, animeName string) error { | |
| 170 | 175 | // Read existing entries |
| 171 | 176 | animeList := LocalGetAllAnime(databaseFile) |
| 172 | 177 | |
| @@ -176,6 +181,7 @@ func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, wat | ||
| 176 | 181 | if anime.AnilistId == anilistID && anime.AllanimeId == allanimeID { |
| 177 | 182 | animeList[i].Ep.Number = watchingEpisode |
| 178 | 183 | animeList[i].Ep.Player.PlaybackTime = playbackTime |
| 184 | animeList[i].Ep.Duration = animeDuration | |
| 179 | 185 | animeList[i].Title.English = animeName |
| 180 | 186 | animeList[i].Title.Romaji = animeName |
| 181 | 187 | updated = true |
| @@ -192,6 +198,7 @@ func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, wat | ||
| 192 | 198 | Player: playingVideo{ |
| 193 | 199 | PlaybackTime: playbackTime, |
| 194 | 200 | }, |
| 201 | Duration: animeDuration, | |
| 195 | 202 | }, |
| 196 | 203 | Title: AnimeTitle{ |
| 197 | 204 | English: animeName, |
| @@ -218,6 +225,7 @@ func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, wat | ||
| 218 | 225 | anime.AllanimeId, |
| 219 | 226 | strconv.Itoa(anime.Ep.Number), |
| 220 | 227 | strconv.Itoa(anime.Ep.Player.PlaybackTime), |
| 228 | strconv.Itoa(anime.Ep.Duration), | |
| 221 | 229 | GetAnimeName(anime), |
| 222 | 230 | } |
| 223 | 231 | if err := writer.Write(record); err != nil { |