Commit 47ca99d8d3
Unsigned
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 | ||
| 96 | 96 | fmt.Println("Error converting Anilist ID:", err) |
| 97 | 97 | } |
| 98 | 98 | |
| 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 | ||
| 110 | 102 | // Get anime entry |
| 111 | 103 | selectedAnilistAnime, err := FindAnimeByAnilistID(user.AnimeList, anilistSelectedOption.Key) |
| 112 | 104 | if err != nil { |
| 113 | 105 | fmt.Println("Can not find the anime in anilist animelist") |
| 114 | 106 | } |
| 115 | 107 | |
| 108 | // Set anime entry | |
| 116 | 109 | anime.Title = selectedAnilistAnime.Media.Title |
| 117 | 110 | anime.TotalEpisodes = selectedAnilistAnime.Media.Episodes |
| 118 | 111 | anime.Ep.Number = selectedAnilistAnime.Progress+1 |
| 119 | // Find anime in Local history | |
| 120 | animePointer := LocalFindAnime(*databaseAnimes, anime.AnilistId, "") | |
| 121 | 112 | |
| 122 | 113 | // if anime not found in database, find it in animeList |
| 123 | 114 | 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 | ||
| 124 | 126 | // find anime in animeList |
| 125 | 127 | 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 | } | |
| 126 | 139 | } else { |
| 127 | 140 | // if anime found in database, use it |
| 128 | 141 | anime.AllanimeId = animePointer.AllanimeId |
| @@ -130,18 +143,8 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni | ||
| 130 | 143 | anime.Ep.Resume = true |
| 131 | 144 | anime.Ep.Number = animePointer.Ep.Number |
| 132 | 145 | } |
| 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 | } | |
| 144 | 146 | |
| 147 | // Handel weird cases | |
| 145 | 148 | if anime.TotalEpisodes < anime.Ep.Number { |
| 146 | 149 | fmt.Printf("Would like to start the anime from beginning? (y/n)\n") |
| 147 | 150 | anime.Rewatching = true |