Commit 5a9b0a04b4
Unsigned
Layout: unified · split
internal/curd.go +88 −149
| @@ -2131,7 +2131,7 @@ func HandleLastEpisodeCompletion(userCurdConfig *CurdConfig, anime *Anime, userT | ||
| 2131 | 2131 | |
| 2132 | 2132 | // handleSequelCheck checks for sequels and prompts the user accordingly |
| 2133 | 2133 | func handleSequelCheck(userCurdConfig *CurdConfig, anime *Anime, userToken string) { |
| 2134 | if !UsesRemoteTracking(userCurdConfig) { | |
| 2134 | if !ShouldWriteRemoteTracking(userCurdConfig, anime) { | |
| 2135 | 2135 | return |
| 2136 | 2136 | } |
| 2137 | 2137 | |
| @@ -2154,191 +2154,130 @@ func handleSequelCheck(userCurdConfig *CurdConfig, anime *Anime, userToken strin | ||
| 2154 | 2154 | return |
| 2155 | 2155 | } |
| 2156 | 2156 | |
| 2157 | sequel := &sequels[0] | |
| 2157 | 2158 | if len(sequels) > 1 { |
| 2158 | CurdOut("Multiple sequels found for this anime.") | |
| 2159 | options := []SelectionOption{ | |
| 2160 | {Key: "yes", Label: "Open AniList page to view sequels"}, | |
| 2161 | {Key: "no", Label: "Ignore"}, | |
| 2162 | } | |
| 2163 | ||
| 2164 | selectedOption, err := DynamicSelect(options) | |
| 2165 | if err != nil { | |
| 2166 | Log(fmt.Sprintf("Error in multiple sequel prompt: %v", err)) | |
| 2159 | selectedSequel, ok := selectSequel(userCurdConfig, sequels) | |
| 2160 | if !ok { | |
| 2167 | 2161 | return |
| 2168 | 2162 | } |
| 2169 | ||
| 2170 | if selectedOption.Key == "yes" { | |
| 2171 | url := fmt.Sprintf("https://anilist.co/anime/%d", anime.AnilistId) | |
| 2172 | CurdOut(fmt.Sprintf("Opening %s", url)) | |
| 2173 | if err := browser.OpenURL(url); err != nil { | |
| 2174 | Log(fmt.Sprintf("Error opening browser: %v", err)) | |
| 2175 | CurdOut("Failed to open browser.") | |
| 2176 | } | |
| 2177 | } | |
| 2178 | return | |
| 2163 | sequel = selectedSequel | |
| 2179 | 2164 | } |
| 2180 | 2165 | |
| 2181 | sequel := &sequels[0] | |
| 2166 | promptSequelAction(userCurdConfig, sequel, userToken) | |
| 2167 | } | |
| 2182 | 2168 | |
| 2183 | // Get sequel title based on user's language preference | |
| 2184 | sequelTitle := sequel.Title.Romaji | |
| 2185 | if sequel.Title.English != "" && userCurdConfig.AnimeNameLanguage == "english" { | |
| 2186 | sequelTitle = sequel.Title.English | |
| 2169 | func selectSequel(userCurdConfig *CurdConfig, sequels []SequelInfo) (*SequelInfo, bool) { | |
| 2170 | CurdOut("Multiple sequels found.") | |
| 2171 | options := make([]SelectionOption, 0, len(sequels)+1) | |
| 2172 | for i := range sequels { | |
| 2173 | title := sequelDisplayTitle(userCurdConfig, &sequels[i]) | |
| 2174 | status := strings.ToLower(strings.ReplaceAll(sequels[i].Status, "_", " ")) | |
| 2175 | options = append(options, SelectionOption{ | |
| 2176 | Key: strconv.Itoa(i), | |
| 2177 | Label: fmt.Sprintf("%s (%s)", title, status), | |
| 2178 | }) | |
| 2187 | 2179 | } |
| 2180 | options = append(options, SelectionOption{Key: "skip", Label: "Skip"}) | |
| 2188 | 2181 | |
| 2189 | Log(fmt.Sprintf("Found sequel: %s (ID: %d)", sequelTitle, sequel.ID)) | |
| 2182 | selected, err := DynamicSelect(options) | |
| 2183 | if err != nil { | |
| 2184 | Log(fmt.Sprintf("Error selecting sequel: %v", err)) | |
| 2185 | return nil, false | |
| 2186 | } | |
| 2187 | if selected.Key == "skip" || selected.Key == "-1" || selected.Key == "-2" { | |
| 2188 | return nil, false | |
| 2189 | } | |
| 2190 | index, err := strconv.Atoi(selected.Key) | |
| 2191 | if err != nil || index < 0 || index >= len(sequels) { | |
| 2192 | return nil, false | |
| 2193 | } | |
| 2194 | return &sequels[index], true | |
| 2195 | } | |
| 2196 | ||
| 2197 | func sequelDisplayTitle(userCurdConfig *CurdConfig, sequel *SequelInfo) string { | |
| 2198 | if sequel == nil { | |
| 2199 | return "" | |
| 2200 | } | |
| 2201 | if userCurdConfig != nil && userCurdConfig.AnimeNameLanguage == "english" && sequel.Title.English != "" { | |
| 2202 | return sequel.Title.English | |
| 2203 | } | |
| 2204 | if sequel.Title.Romaji != "" { | |
| 2205 | return sequel.Title.Romaji | |
| 2206 | } | |
| 2207 | return strconv.Itoa(sequel.ID) | |
| 2208 | } | |
| 2190 | 2209 | |
| 2191 | // Check if sequel is not yet released | |
| 2192 | if sequel.Status == "NOT_YET_RELEASED" { | |
| 2193 | CurdOut(fmt.Sprintf("A sequel '%s' is announced but not yet released.", sequelTitle)) | |
| 2210 | func promptSequelAction(userCurdConfig *CurdConfig, sequel *SequelInfo, userToken string) { | |
| 2211 | if sequel == nil { | |
| 2194 | 2212 | return |
| 2195 | 2213 | } |
| 2196 | 2214 | |
| 2215 | sequelTitle := sequelDisplayTitle(userCurdConfig, sequel) | |
| 2216 | Log(fmt.Sprintf("Found sequel: %s (ID: %d)", sequelTitle, sequel.ID)) | |
| 2217 | ||
| 2197 | 2218 | currentUser := GetGlobalUser() |
| 2198 | 2219 | userAnimeList := AnimeList{} |
| 2199 | 2220 | if currentUser != nil { |
| 2200 | 2221 | userAnimeList = currentUser.AnimeList |
| 2201 | 2222 | } |
| 2202 | if !hasAnyEntries(userAnimeList) { | |
| 2203 | Log("Tracked anime list is empty, skipping sequel list check") | |
| 2204 | promptSequelNotInList(sequel, sequelTitle, userToken, anime) | |
| 2205 | return | |
| 2223 | sequelStatus, isInList := "", false | |
| 2224 | if hasAnyEntries(userAnimeList) { | |
| 2225 | sequelStatus, isInList = FindSequelInAnimeList(userAnimeList, sequel.ID) | |
| 2206 | 2226 | } |
| 2207 | sequelStatus, isInList := FindSequelInAnimeList(userAnimeList, sequel.ID) | |
| 2208 | ||
| 2209 | if !isInList { | |
| 2210 | // Sequel is not in any list - ask if user wants to add it | |
| 2211 | CurdOut(fmt.Sprintf("A sequel is available: %s", sequelTitle)) | |
| 2212 | ||
| 2213 | options := []SelectionOption{ | |
| 2214 | {Key: "watching", Label: "Add to Watching list"}, | |
| 2215 | {Key: "planning", Label: "Add to Plan to Watch"}, | |
| 2216 | {Key: "skip", Label: "No thanks"}, | |
| 2217 | } | |
| 2218 | ||
| 2219 | selectedOption, err := DynamicSelect(options) | |
| 2220 | if err != nil { | |
| 2221 | Log(fmt.Sprintf("Error in sequel prompt: %v", err)) | |
| 2222 | return | |
| 2223 | } | |
| 2224 | 2227 | |
| 2225 | switch selectedOption.Key { | |
| 2226 | case "watching": | |
| 2227 | err = AddAnimeToList(sequel.ID, "CURRENT", userToken) | |
| 2228 | if err != nil { | |
| 2229 | Log(fmt.Sprintf("Error adding sequel to watching list: %v", err)) | |
| 2230 | CurdOut("Failed to add sequel to watching list") | |
| 2231 | } else { | |
| 2232 | CurdOut(fmt.Sprintf("Added '%s' to your Watching list!", sequelTitle)) | |
| 2233 | } | |
| 2234 | case "planning": | |
| 2235 | err = AddAnimeToList(sequel.ID, "PLANNING", userToken) | |
| 2236 | if err != nil { | |
| 2237 | Log(fmt.Sprintf("Error adding sequel to planning list: %v", err)) | |
| 2238 | CurdOut("Failed to add sequel to Plan to Watch") | |
| 2239 | } else { | |
| 2240 | CurdOut(fmt.Sprintf("Added '%s' to your Plan to Watch list!", sequelTitle)) | |
| 2241 | } | |
| 2242 | case "skip", "-1": | |
| 2243 | Log("User declined to add sequel") | |
| 2244 | } | |
| 2228 | if isInList { | |
| 2229 | CurdOut(fmt.Sprintf("Sequel found: %s (%s)", sequelTitle, sequelStatus)) | |
| 2245 | 2230 | } else { |
| 2246 | // Sequel is already in a list | |
| 2247 | switch sequelStatus { | |
| 2248 | case "CURRENT": | |
| 2249 | // Already in watching list | |
| 2250 | CurdOut(fmt.Sprintf("The sequel '%s' is already in your Watching list!", sequelTitle)) | |
| 2251 | ||
| 2252 | case "PLANNING": | |
| 2253 | // In planning list - ask if user wants to move to watching | |
| 2254 | CurdOut(fmt.Sprintf("The sequel '%s' is in your Plan to Watch list. Move to Watching?", sequelTitle)) | |
| 2255 | ||
| 2256 | options := []SelectionOption{ | |
| 2257 | {Key: "yes", Label: "Yes, move to Watching list"}, | |
| 2258 | {Key: "no", Label: "No, keep in Plan to Watch"}, | |
| 2259 | } | |
| 2260 | ||
| 2261 | selectedOption, err := DynamicSelect(options) | |
| 2262 | if err != nil { | |
| 2263 | Log(fmt.Sprintf("Error in sequel planning prompt: %v", err)) | |
| 2264 | return | |
| 2265 | } | |
| 2266 | ||
| 2267 | if selectedOption.Key == "yes" { | |
| 2268 | err = AddAnimeToList(sequel.ID, "CURRENT", userToken) | |
| 2269 | if err != nil { | |
| 2270 | Log(fmt.Sprintf("Error moving sequel to watching list: %v", err)) | |
| 2271 | CurdOut("Failed to move sequel to Watching list") | |
| 2272 | } else { | |
| 2273 | CurdOut(fmt.Sprintf("Moved '%s' to Watching list!", sequelTitle)) | |
| 2274 | } | |
| 2275 | } | |
| 2276 | ||
| 2277 | case "COMPLETED": | |
| 2278 | CurdOut(fmt.Sprintf("You've already completed the sequel '%s'!", sequelTitle)) | |
| 2279 | ||
| 2280 | case "PAUSED", "DROPPED": | |
| 2281 | CurdOut(fmt.Sprintf("The sequel '%s' is in your %s list.", sequelTitle, sequelStatus)) | |
| 2282 | ||
| 2283 | options := []SelectionOption{ | |
| 2284 | {Key: "yes", Label: "Move to Watching list"}, | |
| 2285 | {Key: "no", Label: "No thanks"}, | |
| 2286 | } | |
| 2287 | ||
| 2288 | selectedOption, err := DynamicSelect(options) | |
| 2289 | if err != nil { | |
| 2290 | Log(fmt.Sprintf("Error in sequel resume prompt: %v", err)) | |
| 2291 | return | |
| 2292 | } | |
| 2231 | CurdOut(fmt.Sprintf("Sequel found: %s", sequelTitle)) | |
| 2232 | } | |
| 2293 | 2233 | |
| 2294 | if selectedOption.Key == "yes" { | |
| 2295 | err = AddAnimeToList(sequel.ID, "CURRENT", userToken) | |
| 2296 | if err != nil { | |
| 2297 | Log(fmt.Sprintf("Error moving sequel to watching list: %v", err)) | |
| 2298 | CurdOut("Failed to move sequel to Watching list") | |
| 2299 | } else { | |
| 2300 | CurdOut(fmt.Sprintf("Moved '%s' to Watching list!", sequelTitle)) | |
| 2301 | } | |
| 2302 | } | |
| 2234 | options := []SelectionOption{} | |
| 2235 | if sequel.Status != "NOT_YET_RELEASED" { | |
| 2236 | if !isInList || sequelStatus == "PLANNING" || sequelStatus == "PAUSED" || sequelStatus == "DROPPED" { | |
| 2237 | options = append(options, SelectionOption{Key: "watching", Label: "Add to Watching"}) | |
| 2303 | 2238 | } |
| 2304 | 2239 | } |
| 2305 | } | |
| 2306 | ||
| 2307 | // promptSequelNotInList prompts user to add sequel when we can't check their list | |
| 2308 | func promptSequelNotInList(sequel *SequelInfo, sequelTitle string, userToken string, anime *Anime) { | |
| 2309 | CurdOut(fmt.Sprintf("A sequel is available: %s", sequelTitle)) | |
| 2310 | ||
| 2311 | options := []SelectionOption{ | |
| 2312 | {Key: "watching", Label: "Add to Watching list"}, | |
| 2313 | {Key: "planning", Label: "Add to Plan to Watch"}, | |
| 2314 | {Key: "skip", Label: "No thanks"}, | |
| 2240 | if !isInList || sequelStatus != "PLANNING" { | |
| 2241 | options = append(options, SelectionOption{Key: "planning", Label: "Add to Plan to Watch"}) | |
| 2315 | 2242 | } |
| 2243 | options = append(options, | |
| 2244 | SelectionOption{Key: "details", Label: "Open AniList details"}, | |
| 2245 | SelectionOption{Key: "skip", Label: "Skip"}, | |
| 2246 | ) | |
| 2316 | 2247 | |
| 2317 | selectedOption, err := DynamicSelect(options) | |
| 2248 | selected, err := DynamicSelect(options) | |
| 2318 | 2249 | if err != nil { |
| 2319 | Log(fmt.Sprintf("Error in sequel prompt: %v", err)) | |
| 2250 | Log(fmt.Sprintf("Error in sequel action prompt: %v", err)) | |
| 2320 | 2251 | return |
| 2321 | 2252 | } |
| 2322 | 2253 | |
| 2323 | switch selectedOption.Key { | |
| 2254 | switch selected.Key { | |
| 2324 | 2255 | case "watching": |
| 2325 | err = AddAnimeToList(sequel.ID, "CURRENT", userToken) | |
| 2326 | if err != nil { | |
| 2256 | if err := AddAnimeToList(sequel.ID, "CURRENT", userToken); err != nil { | |
| 2327 | 2257 | Log(fmt.Sprintf("Error adding sequel to watching list: %v", err)) |
| 2328 | CurdOut("Failed to add sequel to watching list") | |
| 2258 | CurdOut("Failed to add sequel to Watching.") | |
| 2329 | 2259 | } else { |
| 2330 | CurdOut(fmt.Sprintf("Added '%s' to your Watching list!", sequelTitle)) | |
| 2260 | CurdOut(fmt.Sprintf("Added '%s' to Watching.", sequelTitle)) | |
| 2331 | 2261 | } |
| 2332 | 2262 | case "planning": |
| 2333 | err = AddAnimeToList(sequel.ID, "PLANNING", userToken) | |
| 2334 | if err != nil { | |
| 2263 | if err := AddAnimeToList(sequel.ID, "PLANNING", userToken); err != nil { | |
| 2335 | 2264 | Log(fmt.Sprintf("Error adding sequel to planning list: %v", err)) |
| 2336 | CurdOut("Failed to add sequel to Plan to Watch") | |
| 2265 | CurdOut("Failed to add sequel to Plan to Watch.") | |
| 2337 | 2266 | } else { |
| 2338 | CurdOut(fmt.Sprintf("Added '%s' to your Plan to Watch list!", sequelTitle)) | |
| 2267 | CurdOut(fmt.Sprintf("Added '%s' to Plan to Watch.", sequelTitle)) | |
| 2268 | } | |
| 2269 | case "details": | |
| 2270 | url := sequel.SiteURL | |
| 2271 | if url == "" { | |
| 2272 | url = fmt.Sprintf("https://anilist.co/anime/%d", sequel.ID) | |
| 2273 | } | |
| 2274 | CurdOut(fmt.Sprintf("Opening %s", url)) | |
| 2275 | if err := browser.OpenURL(url); err != nil { | |
| 2276 | Log(fmt.Sprintf("Error opening browser: %v", err)) | |
| 2277 | CurdOut("Failed to open browser.") | |
| 2339 | 2278 | } |
| 2340 | case "skip", "-1": | |
| 2341 | Log("User declined to add sequel") | |
| 2279 | case "skip", "-1", "-2": | |
| 2280 | Log("User skipped sequel action") | |
| 2342 | 2281 | } |
| 2343 | 2282 | } |
| 2344 | 2283 | |