Commit 3bfcdea64b
Unregistered key
Layout: unified · split
Build/curd-windows-build.iss +1 −1
| @@ -1,6 +1,6 @@ | |||
| 1 | [Setup] | 1 | [Setup] |
| 2 | AppName=Curd Installer | 2 | AppName=Curd Installer |
| 3 | AppVersion=1.0.8 | 3 | AppVersion=1.2.0 |
| 4 | DefaultDirName={userappdata}\Curd | 4 | DefaultDirName={userappdata}\Curd |
| 5 | PrivilegesRequired=lowest | 5 | PrivilegesRequired=lowest |
| 6 | AllowNoIcons=yes | 6 | AllowNoIcons=yes |
internal/anime_list.go +66 −7
| @@ -8,7 +8,7 @@ import ( | |||
| 8 | "net/url" | 8 | "net/url" |
| 9 | "os" | 9 | "os" |
| 10 | "path/filepath" | 10 | "path/filepath" |
| 11 | // "strings" | 11 | "strings" |
| 12 | ) | 12 | ) |
| 13 | 13 | ||
| 14 | type anime struct { | 14 | type anime struct { |
| @@ -27,6 +27,20 @@ type response struct { | |||
| 27 | } `json:"data"` | 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 | // func main() { | 44 | // func main() { |
| 31 | // // Get environment variables | 45 | // // Get environment variables |
| 32 | // mode := "sub" | 46 | // mode := "sub" |
| @@ -43,6 +57,42 @@ type response struct { | |||
| 43 | // } | 57 | // } |
| 44 | 58 | ||
| 45 | func SearchAnime(query, mode string) ([]SelectionOption, error) { | 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 | userCurdConfig := GetGlobalConfig() | 96 | userCurdConfig := GetGlobalConfig() |
| 47 | if userCurdConfig == nil { | 97 | if userCurdConfig == nil { |
| 48 | logFile = os.ExpandEnv("$HOME/.local/share/curd/debug.log") | 98 | logFile = os.ExpandEnv("$HOME/.local/share/curd/debug.log") |
| @@ -56,7 +106,9 @@ func SearchAnime(query, mode string) ([]SelectionOption, error) { | |||
| 56 | allanimeAPI = "https://api." + allanimeBase + "/api" | 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 | animeList := make([]SelectionOption, 0) | 112 | animeList := make([]SelectionOption, 0) |
| 61 | 113 | ||
| 62 | searchGql := `query($search: SearchInput, $limit: Int, $page: Int, $translationType: VaildTranslationTypeEnumType, $countryOrigin: VaildCountryOriginEnumType) { | 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 | for _, anime := range response.Data.Shows.Edges { | 186 | for _, anime := range response.Data.Shows.Edges { |
| 135 | var episodesStr string | 187 | var episodesStr string |
| 136 | if episodes, ok := anime.AvailableEpisodes.(map[string]interface{}); ok { | 188 | if episodes, ok := anime.AvailableEpisodes.(map[string]interface{}); ok { |
| 137 | if subEpisodes, ok := episodes["sub"].(float64); ok { | 189 | if modeEpisodes, ok := episodes[mode].(float64); ok { |
| 138 | episodesStr = fmt.Sprintf("%d", int(subEpisodes)) | 190 | episodesStr = fmt.Sprintf("%d", int(modeEpisodes)) |
| 139 | } else { | 191 | } else { |
| 140 | Log(subEpisodes) | ||
| 141 | episodesStr = "Unknown" | 192 | episodesStr = "Unknown" |
| 142 | } | 193 | } |
| 194 | } else { | ||
| 195 | episodesStr = "Unknown" | ||
| 143 | } | 196 | } |
| 144 | 197 | ||
| 145 | // Use English name if available and configured, otherwise use default name | 198 | // Use English name if available and configured, otherwise use default name |
| 146 | displayName := anime.Name | 199 | displayName := anime.Name |
| 147 | if anime.EnglishName != "" && userCurdConfig.AnimeNameLanguage == "english" { | 200 | if anime.EnglishName != "" && userCurdConfig != nil && userCurdConfig.AnimeNameLanguage == "english" { |
| 148 | displayName = anime.EnglishName | 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 | animeList = append(animeList, SelectionOption{ | 209 | animeList = append(animeList, SelectionOption{ |
| 210 | Title: displayName, | ||
| 152 | Key: anime.ID, | 211 | Key: anime.ID, |
| 153 | Label: fmt.Sprintf("%s (%s episodes)", displayName, episodesStr), | 212 | Label: label, |
| 154 | Thumbnail: anime.Thumbnail, | 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 | if !found { | 1089 | if !found { |
| 1090 | targetLabel := fmt.Sprintf("%v (%d episodes)", userQuery, selectedAnilistAnime.Media.Episodes) | 1090 | targetLabel := fmt.Sprintf("%v (%d episodes)", userQuery, selectedAnilistAnime.Media.Episodes) |
| 1091 | for _, option := range animeList { | 1091 | for _, option := range animeList { |
| 1092 | if option.Label == targetLabel { | 1092 | if fmt.Sprintf("%s (%d episodes)", option.Title, selectedAnilistAnime.Media.Episodes) == targetLabel { |
| 1093 | anime.AllanimeId = option.Key | 1093 | anime.AllanimeId = option.Key |
| 1094 | Log(fmt.Sprintf("Found exact text match! Setting AllanimeId to: %s", anime.AllanimeId)) | 1094 | Log(fmt.Sprintf("Found exact text match! Setting AllanimeId to: %s", anime.AllanimeId)) |
| 1095 | found = true | 1095 | found = true |
internal/episode_list.go +12 −1
| @@ -32,6 +32,7 @@ type episodesResponse struct { | |||
| 32 | 32 | ||
| 33 | // episodesList performs the API call and fetches the episodes list | 33 | // episodesList performs the API call and fetches the episodes list |
| 34 | func EpisodesList(showID, mode string) ([]string, error) { | 34 | func EpisodesList(showID, mode string) ([]string, error) { |
| 35 | preferredMode := normalizeTranslationType(mode) | ||
| 35 | const ( | 36 | const ( |
| 36 | agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0" | 37 | agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0" |
| 37 | allanimeRef = "https://allanime.to" | 38 | allanimeRef = "https://allanime.to" |
| @@ -77,7 +78,17 @@ func EpisodesList(showID, mode string) ([]string, error) { | |||
| 77 | } | 78 | } |
| 78 | 79 | ||
| 79 | // Extract and sort the episodes | 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 | return episodes, nil | 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 | // - []string: a list of links for specified episode. | 151 | // - []string: a list of links for specified episode. |
| 152 | // - error: an error if the episode is not found or if there is an issue during the search. | 152 | // - error: an error if the episode is not found or if there is an issue during the search. |
| 153 | func GetEpisodeURL(config CurdConfig, id string, epNo int) ([]string, error) { | 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 | query := `query($showId:String!,$translationType:VaildTranslationTypeEnumType!,$episodeString:String!){episode(showId:$showId,translationType:$translationType,episodeString:$episodeString){episodeString sourceUrls}}` | 171 | query := `query($showId:String!,$translationType:VaildTranslationTypeEnumType!,$episodeString:String!){episode(showId:$showId,translationType:$translationType,episodeString:$episodeString){episodeString sourceUrls}}` |
| 155 | 172 | ||
| 156 | variables := map[string]string{ | 173 | variables := map[string]string{ |
| 157 | "showId": id, | 174 | "showId": id, |
| 158 | "translationType": config.SubOrDub, | 175 | "translationType": normalizeTranslationType(mode), |
| 159 | "episodeString": fmt.Sprintf("%d", epNo), | 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 | anime.AllanimeId = selectedAnime.Key | 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 | break | 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 | // SelectionOption holds the label and the internal key | 141 | // SelectionOption holds the label and the internal key |
| 142 | type SelectionOption struct { | 142 | type SelectionOption struct { |
| 143 | Title string | ||
| 143 | Label string | 144 | Label string |
| 144 | Key string | 145 | Key string |
| 145 | Thumbnail string | 146 | Thumbnail string |