Commit f3686059ea
Unsigned
Layout: unified · split
internal/curd.go +76 −15
| @@ -298,6 +298,16 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User) { | |||
| 298 | CoverImage: entry.CoverImage, | 298 | CoverImage: entry.CoverImage, |
| 299 | } | 299 | } |
| 300 | } | 300 | } |
| 301 | for _, entry := range user.AnimeList.Rewatching { | ||
| 302 | title := entry.Media.Title.English | ||
| 303 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { | ||
| 304 | title = entry.Media.Title.Romaji | ||
| 305 | } | ||
| 306 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ | ||
| 307 | Title: title, | ||
| 308 | CoverImage: entry.CoverImage, | ||
| 309 | } | ||
| 310 | } | ||
| 301 | } else { | 311 | } else { |
| 302 | animeListOptions = make([]SelectionOption, 0) | 312 | animeListOptions = make([]SelectionOption, 0) |
| 303 | // Include anime from all categories | 313 | // Include anime from all categories |
| @@ -351,6 +361,16 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User) { | |||
| 351 | Label: title, | 361 | Label: title, |
| 352 | }) | 362 | }) |
| 353 | } | 363 | } |
| 364 | for _, entry := range user.AnimeList.Rewatching { | ||
| 365 | title := entry.Media.Title.English | ||
| 366 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { | ||
| 367 | title = entry.Media.Title.Romaji | ||
| 368 | } | ||
| 369 | animeListOptions = append(animeListOptions, SelectionOption{ | ||
| 370 | Key: strconv.Itoa(entry.Media.ID), | ||
| 371 | Label: title, | ||
| 372 | }) | ||
| 373 | } | ||
| 354 | } | 374 | } |
| 355 | 375 | ||
| 356 | // Select anime to update | 376 | // Select anime to update |
| @@ -395,7 +415,13 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User) { | |||
| 395 | 415 | ||
| 396 | currentStatus := "None" | 416 | currentStatus := "None" |
| 397 | if selectedAnilistAnime.Status != "" { | 417 | if selectedAnilistAnime.Status != "" { |
| 398 | currentStatus = categories[selectedAnilistAnime.Status] | 418 | // Find the label for the current status |
| 419 | for _, cat := range categories { | ||
| 420 | if cat.Key == selectedAnilistAnime.Status { | ||
| 421 | currentStatus = cat.Label | ||
| 422 | break | ||
| 423 | } | ||
| 424 | } | ||
| 399 | } | 425 | } |
| 400 | CurdOut(fmt.Sprintf("Current category: %s", currentStatus)) | 426 | CurdOut(fmt.Sprintf("Current category: %s", currentStatus)) |
| 401 | 427 | ||
| @@ -585,7 +611,19 @@ func AddNewAnime(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseA | |||
| 585 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { | 611 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 586 | animeMapPreview, err = SearchAnimeAnilistPreview(query, user.Token) | 612 | animeMapPreview, err = SearchAnimeAnilistPreview(query, user.Token) |
| 587 | } else { | 613 | } else { |
| 588 | animeMap, err = SearchAnimeAnilist(query, user.Token) | 614 | animeMap, err := SearchAnimeAnilist(query, user.Token) |
| 615 | if err != nil { | ||
| 616 | Log(fmt.Sprintf("Failed to search anime: %v", err)) | ||
| 617 | ExitCurd(fmt.Errorf("Failed to search anime")) | ||
| 618 | } | ||
| 619 | // Convert map to []SelectionOption | ||
| 620 | animeOptions = make([]SelectionOption, 0, len(animeMap)) | ||
| 621 | for key, label := range animeMap { | ||
| 622 | animeOptions = append(animeOptions, SelectionOption{ | ||
| 623 | Key: key, | ||
| 624 | Label: label, | ||
| 625 | }) | ||
| 626 | } | ||
| 589 | } | 627 | } |
| 590 | if err != nil { | 628 | if err != nil { |
| 591 | Log(fmt.Sprintf("Failed to search anime: %v", err)) | 629 | Log(fmt.Sprintf("Failed to search anime: %v", err)) |
| @@ -870,7 +908,6 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni | |||
| 870 | Log(fmt.Sprintf("Searching for anime with query: %s, SubOrDub: %s", userQuery, userCurdConfig.SubOrDub)) | 908 | Log(fmt.Sprintf("Searching for anime with query: %s, SubOrDub: %s", userQuery, userCurdConfig.SubOrDub)) |
| 871 | 909 | ||
| 872 | animeList, err = SearchAnime(string(userQuery), userCurdConfig.SubOrDub) | 910 | animeList, err = SearchAnime(string(userQuery), userCurdConfig.SubOrDub) |
| 873 | Log(fmt.Sprintf("SearchAnime result - animeList: %+v, err: %v", animeList, err)) | ||
| 874 | if err != nil { | 911 | if err != nil { |
| 875 | Log(fmt.Sprintf("Failed to select anime: %v", err)) | 912 | Log(fmt.Sprintf("Failed to select anime: %v", err)) |
| 876 | ExitCurd(fmt.Errorf("Failed to select anime")) | 913 | ExitCurd(fmt.Errorf("Failed to select anime")) |
| @@ -879,10 +916,21 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni | |||
| 879 | ExitCurd(fmt.Errorf("No results found.")) | 916 | ExitCurd(fmt.Errorf("No results found.")) |
| 880 | } | 917 | } |
| 881 | 918 | ||
| 882 | // find anime in animeList | 919 | // find anime in animeList by searching through the options |
| 883 | anime.AllanimeId, err = FindKeyByValue(animeList, fmt.Sprintf("%v (%d episodes)", userQuery, selectedAnilistAnime.Media.Episodes)) | 920 | targetLabel := fmt.Sprintf("%v (%d episodes)", userQuery, selectedAnilistAnime.Media.Episodes) |
| 884 | if err != nil { | 921 | found := false |
| 885 | Log(fmt.Sprintf("Failed to find anime in animeList: %v", err)) | 922 | for i, option := range animeList { |
| 923 | Log(fmt.Sprintf("Checking option %d: Key='%s', Label='%s'", i, option.Key, option.Label)) | ||
| 924 | if option.Label == targetLabel { | ||
| 925 | anime.AllanimeId = option.Key | ||
| 926 | Log(fmt.Sprintf("Found exact match! Setting AllanimeId to: %s", anime.AllanimeId)) | ||
| 927 | found = true | ||
| 928 | break | ||
| 929 | } | ||
| 930 | } | ||
| 931 | |||
| 932 | if !found { | ||
| 933 | Log(fmt.Sprintf("No exact match found for label '%s'. Will require manual selection.", targetLabel)) | ||
| 886 | } | 934 | } |
| 887 | 935 | ||
| 888 | // If unable to get Allanime id automatically get manually | 936 | // If unable to get Allanime id automatically get manually |
| @@ -895,7 +943,6 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni | |||
| 895 | } | 943 | } |
| 896 | 944 | ||
| 897 | if err != nil { | 945 | if err != nil { |
| 898 | // fmt.Println("No anime available") | ||
| 899 | ExitCurd(fmt.Errorf("No anime available")) | 946 | ExitCurd(fmt.Errorf("No anime available")) |
| 900 | } | 947 | } |
| 901 | anime.AllanimeId = selectedAllanimeAnime.Key | 948 | anime.AllanimeId = selectedAllanimeAnime.Key |
| @@ -1101,12 +1148,24 @@ func WriteTokenToFile(token string, filePath string) error { | |||
| 1101 | 1148 | ||
| 1102 | func StartCurd(userCurdConfig *CurdConfig, anime *Anime) string { | 1149 | func StartCurd(userCurdConfig *CurdConfig, anime *Anime) string { |
| 1103 | 1150 | ||
| 1104 | if anime.Ep.NextEpisode.Number == anime.Ep.Number { | 1151 | // Validate inputs |
| 1152 | if anime.AllanimeId == "" { | ||
| 1153 | CurdOut("Error: No anime ID found") | ||
| 1154 | os.Exit(1) | ||
| 1155 | } | ||
| 1156 | if anime.Ep.Number <= 0 { | ||
| 1157 | CurdOut("Error: Invalid episode number") | ||
| 1158 | os.Exit(1) | ||
| 1159 | } | ||
| 1160 | |||
| 1161 | if (anime.Ep.NextEpisode.Number == anime.Ep.Number) && (len(anime.Ep.NextEpisode.Links) > 0) { | ||
| 1105 | anime.Ep.Links = anime.Ep.NextEpisode.Links | 1162 | anime.Ep.Links = anime.Ep.NextEpisode.Links |
| 1106 | Log("using prefetched next episode link") | ||
| 1107 | } else { | 1163 | } else { |
| 1108 | // Get episode link | 1164 | // Get episode link |
| 1109 | link, err := GetEpisodeURL(*userCurdConfig, anime.AllanimeId, anime.Ep.Number) | 1165 | link, err := GetEpisodeURL(*userCurdConfig, anime.AllanimeId, anime.Ep.Number) |
| 1166 | if len(link) > 0 { | ||
| 1167 | Log(fmt.Sprintf("Links details: %+v", link)) | ||
| 1168 | } | ||
| 1110 | if err != nil { | 1169 | if err != nil { |
| 1111 | // If unable to get episode link automatically get manually | 1170 | // If unable to get episode link automatically get manually |
| 1112 | episodeList, err := EpisodesList(anime.AllanimeId, userCurdConfig.SubOrDub) | 1171 | episodeList, err := EpisodesList(anime.AllanimeId, userCurdConfig.SubOrDub) |
| @@ -1131,7 +1190,8 @@ func StartCurd(userCurdConfig *CurdConfig, anime *Anime) string { | |||
| 1131 | CurdOut("Failed to get episode link") | 1190 | CurdOut("Failed to get episode link") |
| 1132 | os.Exit(1) | 1191 | os.Exit(1) |
| 1133 | } | 1192 | } |
| 1134 | // anime.Ep.Links = link | 1193 | } else { |
| 1194 | Log(fmt.Sprintf("Successfully retrieved episode link on first try. Links count: %d", len(link))) | ||
| 1135 | } | 1195 | } |
| 1136 | anime.Ep.Links = link | 1196 | anime.Ep.Links = link |
| 1137 | } | 1197 | } |
| @@ -1139,10 +1199,10 @@ func StartCurd(userCurdConfig *CurdConfig, anime *Anime) string { | |||
| 1139 | if len(anime.Ep.Links) == 0 { | 1199 | if len(anime.Ep.Links) == 0 { |
| 1140 | CurdOut("No episode links found") | 1200 | CurdOut("No episode links found") |
| 1141 | os.Exit(1) | 1201 | os.Exit(1) |
| 1202 | } else { | ||
| 1203 | Log(fmt.Sprintf("Episode links validation passed. Found %d links", len(anime.Ep.Links))) | ||
| 1142 | } | 1204 | } |
| 1143 | 1205 | ||
| 1144 | Log(anime) | ||
| 1145 | |||
| 1146 | // Modify the goroutine in main.go where next episode links are fetched | 1206 | // Modify the goroutine in main.go where next episode links are fetched |
| 1147 | // Get next episode link in parallel | 1207 | // Get next episode link in parallel |
| 1148 | go func() { | 1208 | go func() { |
| @@ -1154,14 +1214,15 @@ func StartCurd(userCurdConfig *CurdConfig, anime *Anime) string { | |||
| 1154 | } | 1214 | } |
| 1155 | nextLinks, err := GetEpisodeURL(*userCurdConfig, anime.AllanimeId, nextEpNum) | 1215 | nextLinks, err := GetEpisodeURL(*userCurdConfig, anime.AllanimeId, nextEpNum) |
| 1156 | if err != nil { | 1216 | if err != nil { |
| 1157 | Log("Error getting next episode link: " + err.Error()) | 1217 | Log(fmt.Sprintf("Error getting next episode link for ep %d: %v", nextEpNum, err)) |
| 1158 | } else { | 1218 | } else { |
| 1159 | anime.Ep.NextEpisode = NextEpisode{ | 1219 | anime.Ep.NextEpisode = NextEpisode{ |
| 1160 | Number: nextEpNum, | 1220 | Number: nextEpNum, |
| 1161 | Links: nextLinks, | 1221 | Links: nextLinks, |
| 1162 | } | 1222 | } |
| 1163 | Log(fmt.Sprintf("Next episode link fetched for ep %d", nextEpNum)) | ||
| 1164 | } | 1223 | } |
| 1224 | } else { | ||
| 1225 | Log(fmt.Sprintf("Next episode %d exceeds total episodes %d, skipping prefetch", nextEpNum, anime.TotalEpisodes)) | ||
| 1165 | } | 1226 | } |
| 1166 | }() | 1227 | }() |
| 1167 | 1228 | ||