Commit 3bfcdea64b
Unregistered key
Layout: unified · split
Build/curd-windows-build.iss +1 −1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | [Setup] |
| 2 | 2 | AppName=Curd Installer |
| 3 | AppVersion=1.0.8 | |
| 3 | AppVersion=1.2.0 | |
| 4 | 4 | DefaultDirName={userappdata}\Curd |
| 5 | 5 | PrivilegesRequired=lowest |
| 6 | 6 | AllowNoIcons=yes |
internal/anime_list.go +66 −7
| @@ -8,7 +8,7 @@ import ( | ||
| 8 | 8 | "net/url" |
| 9 | 9 | "os" |
| 10 | 10 | "path/filepath" |
| 11 | // "strings" | |
| 11 | "strings" | |
| 12 | 12 | ) |
| 13 | 13 | |
| 14 | 14 | type anime struct { |
| @@ -27,6 +27,20 @@ type response struct { | ||
| 27 | 27 | } `json:"data"` |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | func normalizeTranslationType(mode string) string { | |
| 31 | if strings.EqualFold(strings.TrimSpace(mode), "dub") { | |
| 32 | return "dub" | |
| 33 | } | |
| 34 | return "sub" | |
| 35 | } | |
| 36 | ||
| 37 | func alternateTranslationType(mode string) string { | |
| 38 | if normalizeTranslationType(mode) == "dub" { | |
| 39 | return "sub" | |
| 40 | } | |
| 41 | return "dub" | |
| 42 | } | |
| 43 | ||
| 30 | 44 | // func main() { |
| 31 | 45 | // // Get environment variables |
| 32 | 46 | // mode := "sub" |
| @@ -43,6 +57,42 @@ type response struct { | ||
| 43 | 57 | // } |
| 44 | 58 | |
| 45 | 59 | func SearchAnime(query, mode string) ([]SelectionOption, error) { |
| 60 | preferredMode := normalizeTranslationType(mode) | |
| 61 | alternateMode := alternateTranslationType(preferredMode) | |
| 62 | ||
| 63 | preferredResults, preferredErr := searchAnimeByMode(query, preferredMode, preferredMode) | |
| 64 | alternateResults, alternateErr := searchAnimeByMode(query, alternateMode, preferredMode) | |
| 65 | ||
| 66 | if preferredErr != nil { | |
| 67 | Log(fmt.Sprintf("Failed searching %s results for %q: %v", preferredMode, query, preferredErr)) | |
| 68 | } | |
| 69 | if alternateErr != nil { | |
| 70 | Log(fmt.Sprintf("Failed searching %s results for %q: %v", alternateMode, query, alternateErr)) | |
| 71 | } | |
| 72 | ||
| 73 | if preferredErr != nil && alternateErr != nil { | |
| 74 | return nil, preferredErr | |
| 75 | } | |
| 76 | ||
| 77 | animeList := make([]SelectionOption, 0, len(preferredResults)+len(alternateResults)) | |
| 78 | seen := make(map[string]struct{}, len(preferredResults)+len(alternateResults)) | |
| 79 | ||
| 80 | for _, option := range preferredResults { | |
| 81 | animeList = append(animeList, option) | |
| 82 | seen[option.Key] = struct{}{} | |
| 83 | } | |
| 84 | ||
| 85 | for _, option := range alternateResults { | |
| 86 | if _, exists := seen[option.Key]; exists { | |
| 87 | continue | |
| 88 | } | |
| 89 | animeList = append(animeList, option) | |
| 90 | } | |
| 91 | ||
| 92 | return animeList, nil | |
| 93 | } | |
| 94 | ||
| 95 | func searchAnimeByMode(query, mode, preferredMode string) ([]SelectionOption, error) { | |
| 46 | 96 | userCurdConfig := GetGlobalConfig() |
| 47 | 97 | if userCurdConfig == nil { |
| 48 | 98 | logFile = os.ExpandEnv("$HOME/.local/share/curd/debug.log") |
| @@ -56,7 +106,9 @@ func SearchAnime(query, mode string) ([]SelectionOption, error) { | ||
| 56 | 106 | allanimeAPI = "https://api." + allanimeBase + "/api" |
| 57 | 107 | ) |
| 58 | 108 | |
| 59 | // Prepare the anime list | |
| 109 | mode = normalizeTranslationType(mode) | |
| 110 | preferredMode = normalizeTranslationType(preferredMode) | |
| 111 | ||
| 60 | 112 | animeList := make([]SelectionOption, 0) |
| 61 | 113 | |
| 62 | 114 | searchGql := `query($search: SearchInput, $limit: Int, $page: Int, $translationType: VaildTranslationTypeEnumType, $countryOrigin: VaildCountryOriginEnumType) { |
| @@ -134,23 +186,30 @@ func SearchAnime(query, mode string) ([]SelectionOption, error) { | ||
| 134 | 186 | for _, anime := range response.Data.Shows.Edges { |
| 135 | 187 | var episodesStr string |
| 136 | 188 | if episodes, ok := anime.AvailableEpisodes.(map[string]interface{}); ok { |
| 137 | if subEpisodes, ok := episodes["sub"].(float64); ok { | |
| 138 | episodesStr = fmt.Sprintf("%d", int(subEpisodes)) | |
| 189 | if modeEpisodes, ok := episodes[mode].(float64); ok { | |
| 190 | episodesStr = fmt.Sprintf("%d", int(modeEpisodes)) | |
| 139 | 191 | } else { |
| 140 | Log(subEpisodes) | |
| 141 | 192 | episodesStr = "Unknown" |
| 142 | 193 | } |
| 194 | } else { | |
| 195 | episodesStr = "Unknown" | |
| 143 | 196 | } |
| 144 | 197 | |
| 145 | 198 | // Use English name if available and configured, otherwise use default name |
| 146 | 199 | displayName := anime.Name |
| 147 | if anime.EnglishName != "" && userCurdConfig.AnimeNameLanguage == "english" { | |
| 200 | if anime.EnglishName != "" && userCurdConfig != nil && userCurdConfig.AnimeNameLanguage == "english" { | |
| 148 | 201 | displayName = anime.EnglishName |
| 149 | 202 | } |
| 150 | 203 | |
| 204 | label := fmt.Sprintf("%s (%s episodes)", displayName, episodesStr) | |
| 205 | if mode != preferredMode { | |
| 206 | label = fmt.Sprintf("%s [%s]", label, mode) | |
| 207 | } | |
| 208 | ||
| 151 | 209 | animeList = append(animeList, SelectionOption{ |
| 210 | Title: displayName, | |
| 152 | 211 | Key: anime.ID, |
| 153 | Label: fmt.Sprintf("%s (%s episodes)", displayName, episodesStr), | |
| 212 | Label: label, | |
| 154 | 213 | Thumbnail: anime.Thumbnail, |
| 155 | 214 | }) |
| 156 | 215 | } |
internal/curd.go +1 −1
| @@ -1089,7 +1089,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni | ||
| 1089 | 1089 | if !found { |
| 1090 | 1090 | targetLabel := fmt.Sprintf("%v (%d episodes)", userQuery, selectedAnilistAnime.Media.Episodes) |
| 1091 | 1091 | for _, option := range animeList { |
| 1092 | if option.Label == targetLabel { | |
| 1092 | if fmt.Sprintf("%s (%d episodes)", option.Title, selectedAnilistAnime.Media.Episodes) == targetLabel { | |
| 1093 | 1093 | anime.AllanimeId = option.Key |
| 1094 | 1094 | Log(fmt.Sprintf("Found exact text match! Setting AllanimeId to: %s", anime.AllanimeId)) |
| 1095 | 1095 | found = true |
internal/episode_list.go +12 −1
| @@ -32,6 +32,7 @@ type episodesResponse struct { | ||
| 32 | 32 | |
| 33 | 33 | // episodesList performs the API call and fetches the episodes list |
| 34 | 34 | func EpisodesList(showID, mode string) ([]string, error) { |
| 35 | preferredMode := normalizeTranslationType(mode) | |
| 35 | 36 | const ( |
| 36 | 37 | agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0" |
| 37 | 38 | allanimeRef = "https://allanime.to" |
| @@ -77,7 +78,17 @@ func EpisodesList(showID, mode string) ([]string, error) { | ||
| 77 | 78 | } |
| 78 | 79 | |
| 79 | 80 | // Extract and sort the episodes |
| 80 | episodes = extractEpisodes(response.Data.Show.AvailableEpisodesDetail, mode) | |
| 81 | episodes = extractEpisodes(response.Data.Show.AvailableEpisodesDetail, preferredMode) | |
| 82 | if len(episodes) == 0 { | |
| 83 | fallbackMode := alternateTranslationType(preferredMode) | |
| 84 | episodes = extractEpisodes(response.Data.Show.AvailableEpisodesDetail, fallbackMode) | |
| 85 | if len(episodes) > 0 { | |
| 86 | Log(fmt.Sprintf("Falling back to %s episode list for anime %s", fallbackMode, showID)) | |
| 87 | } | |
| 88 | } | |
| 89 | if len(episodes) == 0 { | |
| 90 | return episodes, fmt.Errorf("no episodes found for anime %s", showID) | |
| 91 | } | |
| 81 | 92 | return episodes, nil |
| 82 | 93 | } |
| 83 | 94 | |
internal/episode_url.go +18 −1
| @@ -151,11 +151,28 @@ func extractLinks(provider_id string) map[string]interface{} { | ||
| 151 | 151 | // - []string: a list of links for specified episode. |
| 152 | 152 | // - error: an error if the episode is not found or if there is an issue during the search. |
| 153 | 153 | func GetEpisodeURL(config CurdConfig, id string, epNo int) ([]string, error) { |
| 154 | preferredMode := normalizeTranslationType(config.SubOrDub) | |
| 155 | links, err := getEpisodeURLForMode(id, preferredMode, epNo) | |
| 156 | if err == nil { | |
| 157 | return links, nil | |
| 158 | } | |
| 159 | ||
| 160 | fallbackMode := alternateTranslationType(preferredMode) | |
| 161 | fallbackLinks, fallbackErr := getEpisodeURLForMode(id, fallbackMode, epNo) | |
| 162 | if fallbackErr == nil { | |
| 163 | Log(fmt.Sprintf("Falling back to %s for anime %s episode %d", fallbackMode, id, epNo)) | |
| 164 | return fallbackLinks, nil | |
| 165 | } | |
| 166 | ||
| 167 | return nil, err | |
| 168 | } | |
| 169 | ||
| 170 | func getEpisodeURLForMode(id, mode string, epNo int) ([]string, error) { | |
| 154 | 171 | query := `query($showId:String!,$translationType:VaildTranslationTypeEnumType!,$episodeString:String!){episode(showId:$showId,translationType:$translationType,episodeString:$episodeString){episodeString sourceUrls}}` |
| 155 | 172 | |
| 156 | 173 | variables := map[string]string{ |
| 157 | 174 | "showId": id, |
| 158 | "translationType": config.SubOrDub, | |
| 175 | "translationType": normalizeTranslationType(mode), | |
| 159 | 176 | "episodeString": fmt.Sprintf("%d", epNo), |
| 160 | 177 | } |
| 161 | 178 | |
internal/localTracking.go +7 −2
| @@ -297,7 +297,13 @@ func WatchUntracked(userCurdConfig *CurdConfig) { | ||
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | anime.AllanimeId = selectedAnime.Key |
| 300 | anime.Title.English = selectedAnime.Label | |
| 300 | if selectedAnime.Title != "" { | |
| 301 | anime.Title.English = selectedAnime.Title | |
| 302 | anime.Title.Romaji = selectedAnime.Title | |
| 303 | } else { | |
| 304 | anime.Title.English = selectedAnime.Label | |
| 305 | anime.Title.Romaji = selectedAnime.Label | |
| 306 | } | |
| 301 | 307 | break |
| 302 | 308 | } |
| 303 | 309 | |
| @@ -422,4 +428,3 @@ func WatchUntracked(userCurdConfig *CurdConfig) { | ||
| 422 | 428 | } |
| 423 | 429 | |
| 424 | 430 | } |
| 425 | ||
internal/structs.go +1
| @@ -140,6 +140,7 @@ type SelectionOptionImage struct { | ||
| 140 | 140 | |
| 141 | 141 | // SelectionOption holds the label and the internal key |
| 142 | 142 | type SelectionOption struct { |
| 143 | Title string | |
| 143 | 144 | Label string |
| 144 | 145 | Key string |
| 145 | 146 | Thumbnail string |