Commit e1d6a35cf6
Unsigned
Layout: unified · split
internal/episode_url.go +18 −1
| @@ -161,12 +161,29 @@ func GetEpisodeURL(config CurdConfig, id string, epNo int) ([]string, error) { | |||
| 161 | 161 | ||
| 162 | // Pre-count valid URLs and create slice to preserve order | 162 | // Pre-count valid URLs and create slice to preserve order |
| 163 | validURLs := make([]string, 0) | 163 | validURLs := make([]string, 0) |
| 164 | highestPriority := -1 | ||
| 165 | var highestPriorityURL string | ||
| 166 | |||
| 164 | for _, url := range response.Data.Episode.SourceUrls { | 167 | for _, url := range response.Data.Episode.SourceUrls { |
| 165 | if len(url.SourceUrl) > 2 && unicode.IsDigit(rune(url.SourceUrl[2])) { | 168 | if len(url.SourceUrl) > 2 && unicode.IsDigit(rune(url.SourceUrl[2])) { |
| 166 | validURLs = append(validURLs, url.SourceUrl) | 169 | decodedURL := decodeProviderID(url.SourceUrl[2:]) |
| 170 | if strings.Contains(decodedURL, LinkPriorities[0]) { | ||
| 171 | priority := int(url.SourceUrl[2] - '0') | ||
| 172 | if priority > highestPriority { | ||
| 173 | highestPriority = priority | ||
| 174 | highestPriorityURL = url.SourceUrl | ||
| 175 | } | ||
| 176 | } else { | ||
| 177 | validURLs = append(validURLs, url.SourceUrl) | ||
| 178 | } | ||
| 167 | } | 179 | } |
| 168 | } | 180 | } |
| 169 | 181 | ||
| 182 | // If we found a highest priority URL, use only that | ||
| 183 | if highestPriorityURL != "" { | ||
| 184 | validURLs = []string{highestPriorityURL} | ||
| 185 | } | ||
| 186 | |||
| 170 | if len(validURLs) == 0 { | 187 | if len(validURLs) == 0 { |
| 171 | return nil, fmt.Errorf("no valid source URLs found in response") | 188 | return nil, fmt.Errorf("no valid source URLs found in response") |
| 172 | } | 189 | } |