Commit 9054037964

9054037964f4c88288ebfe2c1c259d0926009517

parent: e0ad0d4644

Unsigned

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

TEMP CHANGE: need to do this for backwards compatibility

Layout: unified · split

internal/localTracking.go +45 −22
@@ -93,33 +93,54 @@ func LocalGetAllAnime(databaseFile string) []Anime {
9393 }
9494
9595 for _, row := range records {
96 if len(row) != 5 {
97 fmt.Printf("Invalid row format: %v\n", row)
98 continue
96 anime := parseAnimeRow(row)
97 if anime != nil {
98 animeList = append(animeList, *anime)
9999 }
100 }
100101
101 anilistID, _ := strconv.Atoi(row[0])
102 watchingEpisode, _ := strconv.Atoi(row[2])
103 playbackTime, _ := strconv.Atoi(row[3])
102 return animeList
103}
104104
105 anime := Anime{
106 AnilistId: anilistID,
107 AllanimeId: row[1],
108 Ep: Episode{
109 Number: watchingEpisode,
110 Player: playingVideo{
111 PlaybackTime: playbackTime,
112 },
113 },
114 Title: AnimeTitle{
115 English: row[4],
116 Romaji: row[4],
105// Function to parse a single row of anime data
106func parseAnimeRow(row []string) *Anime {
107 if len(row) < 5 {
108 fmt.Printf("Invalid row format: %v\n", row)
109 return nil
110 }
111
112 anilistID, _ := strconv.Atoi(row[0])
113 watchingEpisode, _ := strconv.Atoi(row[2])
114 playbackTime, _ := strconv.Atoi(row[3])
115
116 anime := &Anime{
117 AnilistId: anilistID,
118 AllanimeId: row[1],
119 Ep: Episode{
120 Number: watchingEpisode,
121 Player: playingVideo{
122 PlaybackTime: playbackTime,
117123 },
124 },
125 Title: AnimeTitle{
126 English: row[4],
127 Romaji: row[4],
128 },
129 }
130
131 // Check if there's an extra field for total episodes
132 if len(row) == 6 {
133 totalEpisodes, _ := strconv.Atoi(row[5])
134 if watchingEpisode == totalEpisodes {
135 // If watching episode equals total episodes, don't include the total episodes field
136 return anime
118137 }
119 animeList = append(animeList, anime)
138 // If not equal, you might want to store this information somewhere
139 // For now, we'll just print it
140 // fmt.Printf("Anime %s has %d total episodes\n", anime.Title.English, totalEpisodes)
120141 }
121142
122 return animeList
143 return anime
123144}
124145
125146// Function to get the anime name (English or Romaji) from an Anime struct
@@ -131,7 +152,7 @@ func getAnimeName(anime Anime) string {
131152}
132153
133154// Function to update or add a new anime entry
134func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, watchingEpisode int, playbackTime int, animeName string) {
155func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, watchingEpisode int, playbackTime int, animeName string) error {
135156 // Read existing entries
136157 animeList := LocalGetAllAnime(databaseFile)
137158
@@ -170,7 +191,7 @@ func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, wat
170191 file, err := os.Create(databaseFile)
171192 if err != nil {
172193 fmt.Println("Error creating file:", err)
173 return
194 return err
174195 }
175196 defer file.Close()
176197
@@ -189,6 +210,8 @@ func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, wat
189210 fmt.Println("Error writing record:", err)
190211 }
191212 }
213
214 return nil
192215}
193216
194217// Function to find an anime by either Anilist ID or Allanime ID