Commit 47ca99d8d3

47ca99d8d33fd89f370de98b1bb6dcc92cc23a62

parent: 40d49e5135

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-21 20:01 UTC

Fix: Local database takes priority

Layout: unified · split

curd added

Binary file not shown.

internal/curd.go +27 −24
@@ -96,33 +96,46 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
9696 fmt.Println("Error converting Anilist ID:", err)
9797 }
9898
99 // Get Anime list (All anime)
100 animeList, err := SearchAnime(string(userQuery), userCurdConfig.SubOrDub)
101 if err != nil {
102 fmt.Println("Failed to select anime", logFile)
103 os.Exit(1)
104 }
105 if len(animeList) == 0 {
106 fmt.Println("No results found.")
107 os.Exit(0)
108 }
109
99 // Find anime in Local history
100 animePointer := LocalFindAnime(*databaseAnimes, anime.AnilistId, "")
101
110102 // Get anime entry
111103 selectedAnilistAnime, err := FindAnimeByAnilistID(user.AnimeList, anilistSelectedOption.Key)
112104 if err != nil {
113105 fmt.Println("Can not find the anime in anilist animelist")
114106 }
115107
108 // Set anime entry
116109 anime.Title = selectedAnilistAnime.Media.Title
117110 anime.TotalEpisodes = selectedAnilistAnime.Media.Episodes
118111 anime.Ep.Number = selectedAnilistAnime.Progress+1
119 // Find anime in Local history
120 animePointer := LocalFindAnime(*databaseAnimes, anime.AnilistId, "")
121112
122113 // if anime not found in database, find it in animeList
123114 if animePointer == nil {
115 // Get Anime list (All anime)
116 animeList, err := SearchAnime(string(userQuery), userCurdConfig.SubOrDub)
117 if err != nil {
118 fmt.Println("Failed to select anime", logFile)
119 os.Exit(1)
120 }
121 if len(animeList) == 0 {
122 fmt.Println("No results found.")
123 os.Exit(0)
124 }
125
124126 // find anime in animeList
125127 anime.AllanimeId, err = FindKeyByValue(animeList, fmt.Sprintf("%v (%d episodes)", userQuery, selectedAnilistAnime.Media.Episodes))
128
129 // If unable to get Allanime id automatically get manually
130 if anime.AllanimeId == "" {
131 fmt.Println("Failed to automatically select anime")
132 selectedAllanimeAnime, err := DynamicSelect(animeList)
133 if err != nil {
134 fmt.Println("No anime available")
135 os.Exit(0)
136 }
137 anime.AllanimeId = selectedAllanimeAnime.Key
138 }
126139 } else {
127140 // if anime found in database, use it
128141 anime.AllanimeId = animePointer.AllanimeId
@@ -130,18 +143,8 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
130143 anime.Ep.Resume = true
131144 anime.Ep.Number = animePointer.Ep.Number
132145 }
133
134 // If unable to get Allanime id automatically get manually
135 if anime.AllanimeId == "" {
136 fmt.Println("Failed to automatically select anime")
137 selectedAllanimeAnime, err := DynamicSelect(animeList)
138 if err != nil {
139 fmt.Println("No anime available")
140 os.Exit(0)
141 }
142 anime.AllanimeId = selectedAllanimeAnime.Key
143 }
144146
147 // Handel weird cases
145148 if anime.TotalEpisodes < anime.Ep.Number {
146149 fmt.Printf("Would like to start the anime from beginning? (y/n)\n")
147150 anime.Rewatching = true