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 {
93 } 93 }
94 94
95 for _, row := range records { 95 for _, row := range records {
96 if len(row) != 5 { 96 anime := parseAnimeRow(row)
97 fmt.Printf("Invalid row format: %v\n", row) 97 if anime != nil {
98 continue 98 animeList = append(animeList, *anime)
99 } 99 }
100 }
100 101
101 anilistID, _ := strconv.Atoi(row[0]) 102 return animeList
102 watchingEpisode, _ := strconv.Atoi(row[2]) 103}
103 playbackTime, _ := strconv.Atoi(row[3])
104 104
105 anime := Anime{ 105// Function to parse a single row of anime data
106 AnilistId: anilistID, 106func parseAnimeRow(row []string) *Anime {
107 AllanimeId: row[1], 107 if len(row) < 5 {
108 Ep: Episode{ 108 fmt.Printf("Invalid row format: %v\n", row)
109 Number: watchingEpisode, 109 return nil
110 Player: playingVideo{ 110 }
111 PlaybackTime: playbackTime, 111
112 }, 112 anilistID, _ := strconv.Atoi(row[0])
113 }, 113 watchingEpisode, _ := strconv.Atoi(row[2])
114 Title: AnimeTitle{ 114 playbackTime, _ := strconv.Atoi(row[3])
115 English: row[4], 115
116 Romaji: row[4], 116 anime := &Anime{
117 AnilistId: anilistID,
118 AllanimeId: row[1],
119 Ep: Episode{
120 Number: watchingEpisode,
121 Player: playingVideo{
122 PlaybackTime: playbackTime,
117 }, 123 },
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
118 } 137 }
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)
120 } 141 }
121 142
122 return animeList 143 return anime
123} 144}
124 145
125// Function to get the anime name (English or Romaji) from an Anime struct 146// Function to get the anime name (English or Romaji) from an Anime struct
@@ -131,7 +152,7 @@ func getAnimeName(anime Anime) string {
131} 152}
132 153
133// Function to update or add a new anime entry 154// 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 {
135 // Read existing entries 156 // Read existing entries
136 animeList := LocalGetAllAnime(databaseFile) 157 animeList := LocalGetAllAnime(databaseFile)
137 158
@@ -170,7 +191,7 @@ func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, wat
170 file, err := os.Create(databaseFile) 191 file, err := os.Create(databaseFile)
171 if err != nil { 192 if err != nil {
172 fmt.Println("Error creating file:", err) 193 fmt.Println("Error creating file:", err)
173 return 194 return err
174 } 195 }
175 defer file.Close() 196 defer file.Close()
176 197
@@ -189,6 +210,8 @@ func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, wat
189 fmt.Println("Error writing record:", err) 210 fmt.Println("Error writing record:", err)
190 } 211 }
191 } 212 }
213
214 return nil
192} 215}
193 216
194// Function to find an anime by either Anilist ID or Allanime ID 217// Function to find an anime by either Anilist ID or Allanime ID