| @@ -555,6 +555,11 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni |
| 555 | 555 | var anilistUserData map[string]interface{} |
| 556 | 556 | var anilistUserDataPreview map[string]interface{} |
| 557 | 557 | |
| 558 | // Filter anime list based on selected category |
| 559 | var animeListMap map[string]string |
| 560 | var animeListMapPreview map[string]RofiSelectPreview |
| 561 | |
| 562 | |
| 558 | 563 | // Get user id, username and Anime list |
| 559 | 564 | user.Id, user.Username, err = GetAnilistUserID(user.Token) |
| 560 | 565 | if err != nil { |
| @@ -579,77 +584,106 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni |
| 579 | 584 | user.AnimeList = ParseAnimeList(anilistUserData) |
| 580 | 585 | } |
| 581 | 586 | |
| 582 | | // Skip category selection if Current flag is set |
| 583 | | var categorySelection SelectionOption |
| 584 | | if userCurdConfig.CurrentCategory { |
| 585 | | categorySelection = SelectionOption{ |
| 586 | | Key: "CURRENT", |
| 587 | | Label: "Currently Watching", |
| 588 | | } |
| 589 | | } else { |
| 590 | | // Create category selection map |
| 591 | | categories := map[string]string{ |
| 592 | | "ALL": "Show All", |
| 593 | | "CURRENT": "Currently Watching", |
| 594 | | "PAUSED": "On Hold", |
| 595 | | "PLANNING": "Plan to Watch", |
| 596 | | "COMPLETED": "Completed", |
| 597 | | "DROPPED": "Dropped", |
| 598 | | "UPDATE": "Update Anime Entry", |
| 599 | | "UNTRACKED": "Untracked Watching", |
| 587 | // If continueLast flag is set, directly get the last watched anime |
| 588 | if anime.Ep.ContinueLast { |
| 589 | // Get the last anime ID from the curd_id file |
| 590 | idFilePath := filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "curd_id") |
| 591 | idBytes, err := os.ReadFile(idFilePath) |
| 592 | if err != nil { |
| 593 | Log("Error reading curd_id file: "+err.Error(), logFile) |
| 594 | ExitCurd(fmt.Errorf("No last watched anime found")) |
| 600 | 595 | } |
| 601 | | |
| 602 | | // Select category using DynamicSelect |
| 603 | | var err error |
| 604 | | categorySelection, err = DynamicSelect(categories, false) |
| 596 | |
| 597 | anilistID, err := strconv.Atoi(string(idBytes)) |
| 605 | 598 | if err != nil { |
| 606 | | Log(fmt.Sprintf("Failed to select category: %v", err), logFile) |
| 607 | | ExitCurd(fmt.Errorf("Failed to select category")) |
| 599 | Log("Error converting anilist ID: "+err.Error(), logFile) |
| 600 | ExitCurd(fmt.Errorf("Invalid anime ID in curd_id file")) |
| 608 | 601 | } |
| 609 | 602 | |
| 610 | | if categorySelection.Key == "-1" { |
| 611 | | ExitCurd(nil) |
| 603 | // Find the anime in database |
| 604 | animePointer := LocalFindAnime(*databaseAnimes, anilistID, "") |
| 605 | if animePointer == nil { |
| 606 | ExitCurd(fmt.Errorf("Last watched anime not found in database")) |
| 612 | 607 | } |
| 613 | 608 | |
| 614 | | // Handle UPDATE option |
| 615 | | if categorySelection.Key == "UPDATE" { |
| 616 | | ClearScreen() |
| 617 | | UpdateAnimeEntry(userCurdConfig, user, logFile) |
| 618 | | ExitCurd(nil) |
| 619 | | } else if categorySelection.Key == "UNTRACKED" { |
| 620 | | ClearScreen() |
| 621 | | WatchUntracked(userCurdConfig, logFile) |
| 622 | | } |
| 609 | // Set the anime details |
| 610 | anime.AnilistId = animePointer.AnilistId |
| 611 | // anime.AllanimeId = animePointer.AllanimeId |
| 612 | // anime.Title = animePointer.Title |
| 613 | // anime.Ep.Number = animePointer.Ep.Number |
| 614 | // anime.Ep.Player.PlaybackTime = animePointer.Ep.Player.PlaybackTime |
| 615 | // anime.Ep.Resume = true |
| 616 | |
| 617 | } else { |
| 618 | // Skip category selection if Current flag is set |
| 619 | var categorySelection SelectionOption |
| 620 | if userCurdConfig.CurrentCategory { |
| 621 | categorySelection = SelectionOption{ |
| 622 | Key: "CURRENT", |
| 623 | Label: "Currently Watching", |
| 624 | } |
| 625 | } else { |
| 626 | // Create category selection map |
| 627 | categories := map[string]string{ |
| 628 | "ALL": "Show All", |
| 629 | "CURRENT": "Currently Watching", |
| 630 | "PAUSED": "On Hold", |
| 631 | "PLANNING": "Plan to Watch", |
| 632 | "COMPLETED": "Completed", |
| 633 | "DROPPED": "Dropped", |
| 634 | "UPDATE": "Update Anime Entry", |
| 635 | "UNTRACKED": "Untracked Watching", |
| 636 | } |
| 623 | 637 | |
| 624 | | ClearScreen() |
| 625 | | } |
| 638 | // Select category using DynamicSelect |
| 639 | var err error |
| 640 | categorySelection, err = DynamicSelect(categories, false) |
| 641 | if err != nil { |
| 642 | Log(fmt.Sprintf("Failed to select category: %v", err), logFile) |
| 643 | ExitCurd(fmt.Errorf("Failed to select category")) |
| 644 | } |
| 626 | 645 | |
| 627 | | // Filter anime list based on selected category |
| 628 | | var animeListMap map[string]string |
| 629 | | var animeListMapPreview map[string]RofiSelectPreview |
| 630 | | |
| 631 | | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 632 | | animeListMapPreview = make(map[string]RofiSelectPreview) |
| 633 | | for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { |
| 634 | | title := entry.Media.Title.English |
| 635 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 636 | | title = entry.Media.Title.Romaji |
| 637 | | } |
| 638 | | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 639 | | Title: title, |
| 640 | | CoverImage: entry.CoverImage, |
| 641 | | } |
| 642 | | } |
| 643 | | } else { |
| 644 | | animeListMap = make(map[string]string) |
| 645 | | for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { |
| 646 | | title := entry.Media.Title.English |
| 647 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 648 | | title = entry.Media.Title.Romaji |
| 649 | | } |
| 650 | | animeListMap[strconv.Itoa(entry.Media.ID)] = title |
| 651 | | } |
| 652 | | } |
| 646 | if categorySelection.Key == "-1" { |
| 647 | ExitCurd(nil) |
| 648 | } |
| 649 | |
| 650 | // Handle UPDATE option |
| 651 | if categorySelection.Key == "UPDATE" { |
| 652 | ClearScreen() |
| 653 | UpdateAnimeEntry(userCurdConfig, user, logFile) |
| 654 | ExitCurd(nil) |
| 655 | } else if categorySelection.Key == "UNTRACKED" { |
| 656 | ClearScreen() |
| 657 | WatchUntracked(userCurdConfig, logFile) |
| 658 | } |
| 659 | |
| 660 | ClearScreen() |
| 661 | } |
| 662 | |
| 663 | |
| 664 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 665 | animeListMapPreview = make(map[string]RofiSelectPreview) |
| 666 | for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { |
| 667 | title := entry.Media.Title.English |
| 668 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 669 | title = entry.Media.Title.Romaji |
| 670 | } |
| 671 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 672 | Title: title, |
| 673 | CoverImage: entry.CoverImage, |
| 674 | } |
| 675 | } |
| 676 | } else { |
| 677 | animeListMap = make(map[string]string) |
| 678 | for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { |
| 679 | title := entry.Media.Title.English |
| 680 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 681 | title = entry.Media.Title.Romaji |
| 682 | } |
| 683 | animeListMap[strconv.Itoa(entry.Media.ID)] = title |
| 684 | } |
| 685 | } |
| 686 | } |
| 653 | 687 | |
| 654 | 688 | var anilistSelectedOption SelectionOption |
| 655 | 689 | var selectedAllanimeAnime SelectionOption |