Commit 8a0174b661
Unsigned
Layout: unified · split
internal/anilist.go +18 −4
| @@ -921,10 +921,12 @@ type SequelInfo struct { | ||
| 921 | 921 | CoverImage string |
| 922 | 922 | Episodes int |
| 923 | 923 | Status string // "FINISHED", "RELEASING", "NOT_YET_RELEASED" |
| 924 | SiteURL string | |
| 924 | 925 | } |
| 925 | 926 | |
| 926 | 927 | // GetAnimeSequel fetches sequel information for a given anime from AniList |
| 927 | func GetAnimeSequel(animeID int, token string) (*SequelInfo, error) { | |
| 928 | // GetAnimeSequel fetches sequel information for a given anime from AniList | |
| 929 | func GetAnimeSequel(animeID int, token string) ([]SequelInfo, error) { | |
| 928 | 930 | url := "https://graphql.anilist.co" |
| 929 | 931 | query := ` |
| 930 | 932 | query ($id: Int) { |
| @@ -943,6 +945,7 @@ func GetAnimeSequel(animeID int, token string) (*SequelInfo, error) { | ||
| 943 | 945 | } |
| 944 | 946 | episodes |
| 945 | 947 | status |
| 948 | siteUrl | |
| 946 | 949 | } |
| 947 | 950 | } |
| 948 | 951 | } |
| @@ -983,6 +986,8 @@ func GetAnimeSequel(animeID int, token string) (*SequelInfo, error) { | ||
| 983 | 986 | return nil, nil // No edges found |
| 984 | 987 | } |
| 985 | 988 | |
| 989 | var sequels []SequelInfo | |
| 990 | ||
| 986 | 991 | // Look for a SEQUEL relation |
| 987 | 992 | for _, edge := range edges { |
| 988 | 993 | edgeData, ok := edge.(map[string]interface{}) |
| @@ -1000,7 +1005,7 @@ func GetAnimeSequel(animeID int, token string) (*SequelInfo, error) { | ||
| 1000 | 1005 | continue |
| 1001 | 1006 | } |
| 1002 | 1007 | |
| 1003 | sequel := &SequelInfo{} | |
| 1008 | var sequel SequelInfo | |
| 1004 | 1009 | |
| 1005 | 1010 | // Parse ID |
| 1006 | 1011 | if id, ok := node["id"].(float64); ok { |
| @@ -1034,10 +1039,19 @@ func GetAnimeSequel(animeID int, token string) (*SequelInfo, error) { | ||
| 1034 | 1039 | sequel.Status = status |
| 1035 | 1040 | } |
| 1036 | 1041 | |
| 1037 | return sequel, nil | |
| 1042 | // Parse siteUrl | |
| 1043 | if siteUrl, ok := node["siteUrl"].(string); ok { | |
| 1044 | sequel.SiteURL = siteUrl | |
| 1045 | } | |
| 1046 | ||
| 1047 | sequels = append(sequels, sequel) | |
| 1048 | } | |
| 1049 | ||
| 1050 | if len(sequels) == 0 { | |
| 1051 | return nil, nil // No sequel found | |
| 1038 | 1052 | } |
| 1039 | 1053 | |
| 1040 | return nil, nil // No sequel found | |
| 1054 | return sequels, nil | |
| 1041 | 1055 | } |
| 1042 | 1056 | |
| 1043 | 1057 | // AddAnimeToList adds an anime to a specified list (CURRENT, PLANNING, PAUSED, DROPPED) |
internal/curd.go +29 −2
| @@ -17,6 +17,7 @@ import ( | ||
| 17 | 17 | "time" |
| 18 | 18 | |
| 19 | 19 | "github.com/gen2brain/beeep" |
| 20 | "github.com/pkg/browser" | |
| 20 | 21 | ) |
| 21 | 22 | |
| 22 | 23 | func EditConfig(configFilePath string) { |
| @@ -1695,17 +1696,43 @@ func handleSequelCheck(userCurdConfig *CurdConfig, anime *Anime, userToken strin | ||
| 1695 | 1696 | }() |
| 1696 | 1697 | |
| 1697 | 1698 | // Fetch sequel information |
| 1698 | sequel, err := GetAnimeSequel(anime.AnilistId, userToken) | |
| 1699 | sequels, err := GetAnimeSequel(anime.AnilistId, userToken) | |
| 1699 | 1700 | if err != nil { |
| 1700 | 1701 | Log(fmt.Sprintf("Error fetching sequel information: %v", err)) |
| 1701 | 1702 | return |
| 1702 | 1703 | } |
| 1703 | 1704 | |
| 1704 | if sequel == nil { | |
| 1705 | if len(sequels) == 0 { | |
| 1705 | 1706 | Log("No sequel found for this anime") |
| 1706 | 1707 | return |
| 1707 | 1708 | } |
| 1708 | 1709 | |
| 1710 | if len(sequels) > 1 { | |
| 1711 | CurdOut("Multiple sequels found for this anime.") | |
| 1712 | options := []SelectionOption{ | |
| 1713 | {Key: "yes", Label: "Open AniList page to view sequels"}, | |
| 1714 | {Key: "no", Label: "Ignore"}, | |
| 1715 | } | |
| 1716 | ||
| 1717 | selectedOption, err := DynamicSelect(options) | |
| 1718 | if err != nil { | |
| 1719 | Log(fmt.Sprintf("Error in multiple sequel prompt: %v", err)) | |
| 1720 | return | |
| 1721 | } | |
| 1722 | ||
| 1723 | if selectedOption.Key == "yes" { | |
| 1724 | url := fmt.Sprintf("https://anilist.co/anime/%d", anime.AnilistId) | |
| 1725 | CurdOut(fmt.Sprintf("Opening %s", url)) | |
| 1726 | if err := browser.OpenURL(url); err != nil { | |
| 1727 | Log(fmt.Sprintf("Error opening browser: %v", err)) | |
| 1728 | CurdOut("Failed to open browser.") | |
| 1729 | } | |
| 1730 | } | |
| 1731 | return | |
| 1732 | } | |
| 1733 | ||
| 1734 | sequel := &sequels[0] | |
| 1735 | ||
| 1709 | 1736 | // Get sequel title based on user's language preference |
| 1710 | 1737 | sequelTitle := sequel.Title.Romaji |
| 1711 | 1738 | if sequel.Title.English != "" && userCurdConfig.AnimeNameLanguage == "english" { |