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() {
163163 anime.Ep.Started = false
164164 anime.Ep.IsCompleted = true
165165 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))
167167 // Send command to close MPV
168168 _, err := internal.MPVSendCommand(anime.Ep.Player.SocketPath, []interface{}{"quit"})
169169 if err != nil {
@@ -188,7 +188,7 @@ func main() {
188188 default:
189189 err = internal.DiscordPresence(discordClientId, anime)
190190 if err != nil {
191 internal.Log("Error setting Discord presence: "+err.Error(), logFile)
191 // internal.Log("Error setting Discord presence: "+err.Error(), logFile)
192192 }
193193 time.Sleep(1 * time.Second)
194194 }
@@ -204,9 +204,9 @@ func main() {
204204 internal.Log(anime.Ep.SkipTimes, logFile)
205205 }()
206206
207 // Get video duration
207208 go func() {
208209 for {
209
210210 if anime.Ep.Started {
211211 if anime.Ep.Duration == 0 {
212212 // Get video duration
@@ -224,6 +224,7 @@ func main() {
224224 break
225225 }
226226 }
227 time.Sleep(1 * time.Second)
227228 }
228229 }()
229230
@@ -295,7 +296,7 @@ func main() {
295296
296297 anime.Ep.Player.PlaybackTime = int(animePosition + 0.5) // Round to nearest integer
297298 // 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))
299300 if err != nil {
300301 internal.Log("Error updating local database: "+err.Error(), logFile)
301302 } else {
@@ -366,5 +367,11 @@ func main() {
366367 internal.ExitCurd()
367368 }
368369 }
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 }
369376 }
370377}
internal/curd.go +9
@@ -243,6 +243,15 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
243243 anime.Ep.Number = animePointer.Ep.Number
244244 }
245245
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
246255 if anime.TotalEpisodes == 0 {
247256 // Get updated anime data
248257 Log(selectedAllanimeAnime, logFile)
internal/discord.go +3 −3
@@ -17,9 +17,9 @@ func DiscordPresence(clientId string, anime Anime) error {
1717 LargeText: GetAnimeName(anime), // Would display while hovering over the large image
1818 State: fmt.Sprintf("\nEpisode %d - %d:%02d / %d:%02d",
1919 anime.Ep.Number,
20 convertSecondsToMinutes(anime.Ep.Player.PlaybackTime),
20 ConvertSecondsToMinutes(anime.Ep.Player.PlaybackTime),
2121 anime.Ep.Player.PlaybackTime % 60,
22 convertSecondsToMinutes(anime.Ep.Duration),
22 ConvertSecondsToMinutes(anime.Ep.Duration),
2323 anime.Ep.Duration % 60),
2424 // SmallImage: anime.CoverImage, // Image would appear in the bottom left corner
2525 // 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 {
4040 return nil
4141}
4242
43func convertSecondsToMinutes(seconds int) int {
43func ConvertSecondsToMinutes(seconds int) int {
4444 return seconds / 60
4545}
internal/localTracking.go +10 −2
@@ -9,7 +9,7 @@ import (
99)
1010
1111// 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) {
1313 file, err := os.OpenFile(databaseFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
1414 if err != nil {
1515 fmt.Println("Error opening file:", err)
@@ -25,6 +25,7 @@ func LocalAddAnime(databaseFile string, anilistID int, allanimeID string, watchi
2525 allanimeID,
2626 strconv.Itoa(watchingEpisode),
2727 strconv.Itoa(watchingTime),
28 strconv.Itoa(animeDuration),
2829 animeName,
2930 })
3031 if err != nil {
@@ -121,6 +122,7 @@ func LocalGetAllAnime(databaseFile string) []Anime {
121122
122123 return animeList
123124}
125
124126// Function to parse a single row of anime data
125127func parseAnimeRow(row []string) *Anime {
126128 if len(row) < 5 {
@@ -131,6 +133,7 @@ func parseAnimeRow(row []string) *Anime {
131133 anilistID, _ := strconv.Atoi(row[0])
132134 watchingEpisode, _ := strconv.Atoi(row[2])
133135 playbackTime, _ := strconv.Atoi(row[3])
136 animeDuration, _ := strconv.Atoi(row[4])
134137
135138 anime := &Anime{
136139 AnilistId: anilistID,
@@ -140,6 +143,7 @@ func parseAnimeRow(row []string) *Anime {
140143 Player: playingVideo{
141144 PlaybackTime: playbackTime,
142145 },
146 Duration: animeDuration,
143147 },
144148 }
145149
@@ -157,6 +161,7 @@ func parseAnimeRow(row []string) *Anime {
157161
158162 return anime
159163}
164
160165// Function to get the anime name (English or Romaji) from an Anime struct
161166func GetAnimeName(anime Anime) string {
162167 if anime.Title.English != "" {
@@ -166,7 +171,7 @@ func GetAnimeName(anime Anime) string {
166171}
167172
168173// 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 {
170175 // Read existing entries
171176 animeList := LocalGetAllAnime(databaseFile)
172177
@@ -176,6 +181,7 @@ func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, wat
176181 if anime.AnilistId == anilistID && anime.AllanimeId == allanimeID {
177182 animeList[i].Ep.Number = watchingEpisode
178183 animeList[i].Ep.Player.PlaybackTime = playbackTime
184 animeList[i].Ep.Duration = animeDuration
179185 animeList[i].Title.English = animeName
180186 animeList[i].Title.Romaji = animeName
181187 updated = true
@@ -192,6 +198,7 @@ func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, wat
192198 Player: playingVideo{
193199 PlaybackTime: playbackTime,
194200 },
201 Duration: animeDuration,
195202 },
196203 Title: AnimeTitle{
197204 English: animeName,
@@ -218,6 +225,7 @@ func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, wat
218225 anime.AllanimeId,
219226 strconv.Itoa(anime.Ep.Number),
220227 strconv.Itoa(anime.Ep.Player.PlaybackTime),
228 strconv.Itoa(anime.Ep.Duration),
221229 GetAnimeName(anime),
222230 }
223231 if err := writer.Write(record); err != nil {