Commit e9d51690d8

e9d51690d8057cf61ffcdf013ebb6165c2ae139c

parent: c7cdf1c7d3

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-23 10:48 UTC

Minor changes

Layout: unified · split

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