| @@ -726,6 +726,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni |
| 726 | var err error |
726 | var err error |
| 727 | var anilistUserData map[string]interface{} |
727 | var anilistUserData map[string]interface{} |
| 728 | var anilistUserDataPreview map[string]interface{} |
728 | var anilistUserDataPreview map[string]interface{} |
| |
729 | var startingRewatch bool |
| 729 | |
730 | |
| 730 | // Filter anime list based on selected category |
731 | // Filter anime list based on selected category |
| 731 | var animeListOptions []SelectionOption |
732 | var animeListOptions []SelectionOption |
| @@ -763,6 +764,8 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni |
| 763 | |
764 | |
| 764 | // Navigation loop for the entire setup process |
765 | // Navigation loop for the entire setup process |
| 765 | for { |
766 | for { |
| |
767 | startingRewatch = false |
| |
768 | |
| 766 | // If continueLast flag is set, directly get the last watched anime |
769 | // If continueLast flag is set, directly get the last watched anime |
| 767 | if anime.Ep.ContinueLast { |
770 | if anime.Ep.ContinueLast { |
| 768 | // Get the last anime ID from the curd_id file |
771 | // Get the last anime ID from the curd_id file |
| @@ -966,10 +969,47 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni |
| 966 | anime.Title = selectedAnilistAnime.Media.Title |
969 | anime.Title = selectedAnilistAnime.Media.Title |
| 967 | anime.TotalEpisodes = selectedAnilistAnime.Media.Episodes |
970 | anime.TotalEpisodes = selectedAnilistAnime.Media.Episodes |
| 968 | anime.IsAiring = selectedAnilistAnime.Media.Status == "RELEASING" || selectedAnilistAnime.Media.Status == "NOT_YET_RELEASED" |
971 | anime.IsAiring = selectedAnilistAnime.Media.Status == "RELEASING" || selectedAnilistAnime.Media.Status == "NOT_YET_RELEASED" |
| |
972 | anime.Rewatching = selectedAnilistAnime.Status == "REPEATING" |
| |
973 | anime.Repeat = selectedAnilistAnime.Repeat |
| |
974 | anime.StartedAt = selectedAnilistAnime.StartedAt |
| |
975 | anime.CompletedAt = selectedAnilistAnime.CompletedAt |
| 969 | anime.Ep.Number = selectedAnilistAnime.Progress + 1 |
976 | anime.Ep.Number = selectedAnilistAnime.Progress + 1 |
| 970 | var animeList []SelectionOption |
977 | var animeList []SelectionOption |
| 971 | userQuery = anime.Title.Romaji |
978 | userQuery = anime.Title.Romaji |
| 972 | |
979 | |
| |
980 | if selectedAnilistAnime.Status == "COMPLETED" { |
| |
981 | status := "REPEATING" |
| |
982 | progress := 0 |
| |
983 | err = SaveAnimeListEntry(user.Token, anime.AnilistId, &status, &progress, nil, &anime.StartedAt, &anime.CompletedAt) |
| |
984 | if err != nil { |
| |
985 | Log(fmt.Sprintf("Error starting anime rewatch: %v", err)) |
| |
986 | ExitCurd(fmt.Errorf("Failed to move anime to rewatching")) |
| |
987 | } |
| |
988 | |
| |
989 | anime.Rewatching = true |
| |
990 | anime.Ep.Number = 1 |
| |
991 | anime.Ep.Player.PlaybackTime = 0 |
| |
992 | anime.Ep.Resume = false |
| |
993 | startingRewatch = true |
| |
994 | CurdOut("Moved anime to Rewatching and restarting from episode 1.") |
| |
995 | |
| |
996 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| |
997 | anilistUserDataPreview, err = GetUserDataPreview(user.Token, user.Id) |
| |
998 | if err != nil { |
| |
999 | Log("Error refreshing anime list: " + err.Error()) |
| |
1000 | ExitCurd(err) |
| |
1001 | } |
| |
1002 | user.AnimeList = ParseAnimeList(anilistUserDataPreview) |
| |
1003 | } else { |
| |
1004 | anilistUserData, err = GetUserData(user.Token, user.Id) |
| |
1005 | if err != nil { |
| |
1006 | Log("Error refreshing anime list: " + err.Error()) |
| |
1007 | ExitCurd(err) |
| |
1008 | } |
| |
1009 | user.AnimeList = ParseAnimeList(anilistUserData) |
| |
1010 | } |
| |
1011 | } |
| |
1012 | |
| 973 | // if anime not found in database, find it in animeList |
1013 | // if anime not found in database, find it in animeList |
| 974 | if animePointer == nil { |
1014 | if animePointer == nil { |
| 975 | Log("Anime not found in database, searching in animeList...") |
1015 | Log("Anime not found in database, searching in animeList...") |
| @@ -1013,7 +1053,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni |
| 1013 | matches := malRegex.FindStringSubmatch(option.Thumbnail) |
1053 | matches := malRegex.FindStringSubmatch(option.Thumbnail) |
| 1014 | if len(matches) > 1 { |
1054 | if len(matches) > 1 { |
| 1015 | fileName := matches[1] |
1055 | fileName := matches[1] |
| 1016 | |
1056 | |
| 1017 | // Fetch Jikan pictures lazily (only once) |
1057 | // Fetch Jikan pictures lazily (only once) |
| 1018 | if !fetchedJikan { |
1058 | if !fetchedJikan { |
| 1019 | if anime.MalId == 0 { |
1059 | if anime.MalId == 0 { |
| @@ -1094,6 +1134,11 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni |
| 1094 | } |
1134 | } |
| 1095 | } |
1135 | } |
| 1096 | |
1136 | |
| |
1137 | if startingRewatch { |
| |
1138 | anime.Ep.Player.PlaybackTime = 0 |
| |
1139 | anime.Ep.Resume = false |
| |
1140 | } |
| |
1141 | |
| 1097 | if selectedAllanimeAnime.Key == "-1" { |
1142 | if selectedAllanimeAnime.Key == "-1" { |
| 1098 | ExitCurd(nil) |
1143 | ExitCurd(nil) |
| 1099 | } |
1144 | } |
| @@ -1106,6 +1151,17 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni |
| 1106 | break |
1151 | break |
| 1107 | } |
1152 | } |
| 1108 | } |
1153 | } |
| |
1154 | if !isInWatchingList { |
| |
1155 | for _, entry := range user.AnimeList.Rewatching { |
| |
1156 | if entry.Media.ID == anime.AnilistId { |
| |
1157 | isInWatchingList = true |
| |
1158 | break |
| |
1159 | } |
| |
1160 | } |
| |
1161 | } |
| |
1162 | if anime.Rewatching { |
| |
1163 | isInWatchingList = true |
| |
1164 | } |
| 1109 | |
1165 | |
| 1110 | if !isInWatchingList { |
1166 | if !isInWatchingList { |
| 1111 | // Create options for the prompt |
1167 | // Create options for the prompt |
| @@ -1444,7 +1500,10 @@ func getEntriesByCategory(list AnimeList, category string) []Entry { |
| 1444 | allEntries = append(allEntries, list.Rewatching...) |
1500 | allEntries = append(allEntries, list.Rewatching...) |
| 1445 | return allEntries |
1501 | return allEntries |
| 1446 | case "CURRENT": |
1502 | case "CURRENT": |
| 1447 | return list.Watching |
1503 | currentEntries := make([]Entry, 0, len(list.Watching)+len(list.Rewatching)) |
| |
1504 | currentEntries = append(currentEntries, list.Watching...) |
| |
1505 | currentEntries = append(currentEntries, list.Rewatching...) |
| |
1506 | return currentEntries |
| 1448 | case "COMPLETED": |
1507 | case "COMPLETED": |
| 1449 | return list.Completed |
1508 | return list.Completed |
| 1450 | case "PAUSED": |
1509 | case "PAUSED": |
| @@ -1541,15 +1600,12 @@ func NextEpisodePromptContinuous(userCurdConfig *CurdConfig, databaseFile string |
| 1541 | Log("Error updating local database on quit: " + err.Error()) |
1600 | Log("Error updating local database on quit: " + err.Error()) |
| 1542 | } |
1601 | } |
| 1543 | |
1602 | |
| 1544 | // Update Anilist progress if not rewatching |
1603 | go func() { |
| 1545 | if !anime.Rewatching { |
1604 | err = UpdateAnimeProgress(userToken, anime.AnilistId, anime.Ep.Number) |
| 1546 | go func() { |
1605 | if err != nil { |
| 1547 | err = UpdateAnimeProgress(userToken, anime.AnilistId, anime.Ep.Number) |
1606 | Log("Error updating Anilist progress on quit: " + err.Error()) |
| 1548 | if err != nil { |
1607 | } |
| 1549 | Log("Error updating Anilist progress on quit: " + err.Error()) |
1608 | }() |
| 1550 | } |
| |
| 1551 | }() |
| |
| 1552 | } |
| |
| 1553 | |
1609 | |
| 1554 | CurdOut(fmt.Sprintf("Episode completed (%.1f%% watched). Exiting.", percentageWatched)) |
1610 | CurdOut(fmt.Sprintf("Episode completed (%.1f%% watched). Exiting.", percentageWatched)) |
| 1555 | } else { |
1611 | } else { |
| @@ -1571,15 +1627,12 @@ func NextEpisodePromptContinuous(userCurdConfig *CurdConfig, databaseFile string |
| 1571 | Log("Error updating local database with completed episode: " + err.Error()) |
1627 | Log("Error updating local database with completed episode: " + err.Error()) |
| 1572 | } |
1628 | } |
| 1573 | |
1629 | |
| 1574 | // Update Anilist progress for the completed episode if not rewatching |
1630 | go func() { |
| 1575 | if !anime.Rewatching { |
1631 | err = UpdateAnimeProgress(userToken, anime.AnilistId, anime.Ep.Number) |
| 1576 | go func() { |
1632 | if err != nil { |
| 1577 | err = UpdateAnimeProgress(userToken, anime.AnilistId, anime.Ep.Number) |
1633 | Log("Error updating Anilist progress: " + err.Error()) |
| 1578 | if err != nil { |
1634 | } |
| 1579 | Log("Error updating Anilist progress: " + err.Error()) |
1635 | }() |
| 1580 | } |
| |
| 1581 | }() |
| |
| 1582 | } |
| |
| 1583 | |
1636 | |
| 1584 | // Increment to next episode and update database with next episode number and 0 playback time |
1637 | // Increment to next episode and update database with next episode number and 0 playback time |
| 1585 | anime.Ep.Number++ |
1638 | anime.Ep.Number++ |
| @@ -1641,14 +1694,11 @@ func StartNextEpisode(anime *Anime, userCurdConfig *CurdConfig, databaseFile str |
| 1641 | // Handle scoring and completion for the last episode |
1694 | // Handle scoring and completion for the last episode |
| 1642 | HandleLastEpisodeCompletion(userCurdConfig, anime, userToken) |
1695 | HandleLastEpisodeCompletion(userCurdConfig, anime, userToken) |
| 1643 | |
1696 | |
| 1644 | // Update Anilist progress for the last episode if not rewatching |
1697 | err := UpdateAnimeProgress(userToken, anime.AnilistId, prevEpisode) |
| 1645 | if !anime.Rewatching { |
1698 | if err != nil { |
| 1646 | err := UpdateAnimeProgress(userToken, anime.AnilistId, prevEpisode) |
1699 | Log("Error updating Anilist progress: " + err.Error()) |
| 1647 | if err != nil { |
| |
| 1648 | Log("Error updating Anilist progress: " + err.Error()) |
| |
| 1649 | } |
| |
| 1650 | // Note: UpdateAnimeProgress already outputs a message on success |
| |
| 1651 | } |
1700 | } |
| |
1701 | // Note: UpdateAnimeProgress already outputs a message on success |
| 1652 | |
1702 | |
| 1653 | CurdOut("Series completed!") |
1703 | CurdOut("Series completed!") |
| 1654 | ExitCurd(nil) |
1704 | ExitCurd(nil) |
| @@ -1688,15 +1738,12 @@ func StartNextEpisode(anime *Anime, userCurdConfig *CurdConfig, databaseFile str |
| 1688 | Log("Error updating local database: " + err.Error()) |
1738 | Log("Error updating local database: " + err.Error()) |
| 1689 | } |
1739 | } |
| 1690 | |
1740 | |
| 1691 | // Update Anilist progress for the previous episode if not rewatching |
1741 | go func() { |
| 1692 | if !anime.Rewatching { |
1742 | err = UpdateAnimeProgress(userToken, anime.AnilistId, prevEpisode) |
| 1693 | go func() { |
1743 | if err != nil { |
| 1694 | err = UpdateAnimeProgress(userToken, anime.AnilistId, prevEpisode) |
1744 | Log("Error updating Anilist progress: " + err.Error()) |
| 1695 | if err != nil { |
1745 | } |
| 1696 | Log("Error updating Anilist progress: " + err.Error()) |
1746 | }() |
| 1697 | } |
| |
| 1698 | }() |
| |
| 1699 | } |
| |
| 1700 | |
1747 | |
| 1701 | // Output message to user |
1748 | // Output message to user |
| 1702 | CurdOut(fmt.Sprint("Starting next episode: ", anime.Ep.Number)) |
1749 | CurdOut(fmt.Sprint("Starting next episode: ", anime.Ep.Number)) |
| @@ -1729,14 +1776,21 @@ func HandleLastEpisodeCompletion(userCurdConfig *CurdConfig, anime *Anime, userT |
| 1729 | // Back (-2) and no are treated as skip |
1776 | // Back (-2) and no are treated as skip |
| 1730 | } |
1777 | } |
| 1731 | |
1778 | |
| 1732 | // Update anime status to completed on AniList |
1779 | // Update anime status to completed on AniList. |
| 1733 | // This is done regardless of scoring preference |
1780 | // For rewatches, preserve the original completion date and only increment repeat count. |
| 1734 | if anime.TotalEpisodes > 0 && anime.Ep.Number == anime.TotalEpisodes && !anime.Rewatching && !anime.IsAiring { |
1781 | if anime.TotalEpisodes > 0 && anime.Ep.Number == anime.TotalEpisodes && !anime.IsAiring { |
| 1735 | err := UpdateAnimeStatus(userToken, anime.AnilistId, "COMPLETED") |
1782 | if anime.Rewatching { |
| 1736 | if err != nil { |
1783 | err := CompleteAnimeRewatch(userToken, *anime) |
| 1737 | Log("Error updating anime status to completed: " + err.Error()) |
1784 | if err != nil { |
| |
1785 | Log("Error completing anime rewatch: " + err.Error()) |
| |
1786 | } |
| |
1787 | } else { |
| |
1788 | err := UpdateAnimeStatus(userToken, anime.AnilistId, "COMPLETED") |
| |
1789 | if err != nil { |
| |
1790 | Log("Error updating anime status to completed: " + err.Error()) |
| |
1791 | } |
| |
1792 | // Note: UpdateAnimeStatus already outputs a message on success |
| 1738 | } |
1793 | } |
| 1739 | // Note: UpdateAnimeStatus already outputs a message on success |
| |
| 1740 | } |
1794 | } |
| 1741 | |
1795 | |
| 1742 | // Check for sequel after completion (only if this is the last episode) |
1796 | // Check for sequel after completion (only if this is the last episode) |