Commit d2d884983f
Unsigned
Layout: unified ยท split
.github/workflows/ci-cd.yml +56 โ23
| @@ -3,14 +3,14 @@ name: CI/CD Pipeline | ||
| 3 | 3 | on: |
| 4 | 4 | push: |
| 5 | 5 | branches: |
| 6 | - main # Trigger on pushes to the main branch | |
| 6 | - main # Trigger on pushes to the main branch | |
| 7 | 7 | pull_request: |
| 8 | 8 | branches: |
| 9 | - main # Trigger on pull requests targeting the main branch | |
| 9 | - main # Trigger on pull requests targeting the main branch | |
| 10 | 10 | workflow_dispatch: |
| 11 | 11 | inputs: |
| 12 | 12 | pr_number: |
| 13 | description: 'Pull Request Number' | |
| 13 | description: "Pull Request Number" | |
| 14 | 14 | required: false |
| 15 | 15 | type: string |
| 16 | 16 | |
| @@ -22,13 +22,13 @@ jobs: | ||
| 22 | 22 | - name: Checkout code |
| 23 | 23 | uses: actions/checkout@v4 |
| 24 | 24 | with: |
| 25 | fetch-depth: 0 # Fetch all history and tags | |
| 25 | fetch-depth: 0 # Fetch all history and tags | |
| 26 | 26 | ref: ${{ github.event.pull_request.head.sha || (github.event.inputs.pr_number && format('refs/pull/{0}/head', github.event.inputs.pr_number)) || github.sha }} |
| 27 | 27 | |
| 28 | 28 | - name: Set up Go |
| 29 | uses: actions/setup-go@v4 | |
| 29 | uses: actions/setup-go@v5 | |
| 30 | 30 | with: |
| 31 | go-version: '1.21' | |
| 31 | go-version: "1.21" | |
| 32 | 32 | |
| 33 | 33 | - name: Install Dependencies |
| 34 | 34 | run: go mod tidy |
| @@ -147,16 +147,16 @@ jobs: | ||
| 147 | 147 | $version = Get-Content VERSION.txt |
| 148 | 148 | echo "CURD_VERSION=$version" >> $env:GITHUB_ENV |
| 149 | 149 | $release_dir = "releases/curd-$version" |
| 150 | ||
| 150 | ||
| 151 | 151 | # Create directory structure |
| 152 | 152 | New-Item -ItemType Directory -Force -Path "$release_dir/windows" |
| 153 | 153 | New-Item -ItemType Directory -Force -Path "$release_dir/macos" |
| 154 | 154 | New-Item -ItemType Directory -Force -Path "$release_dir/linux" |
| 155 | ||
| 155 | ||
| 156 | 156 | # List contents of Build directory to debug |
| 157 | 157 | Write-Host "Contents of Build directory:" |
| 158 | 158 | Get-ChildItem -Path "Build" -Recurse |
| 159 | ||
| 159 | ||
| 160 | 160 | # Move files to their respective directories |
| 161 | 161 | Move-Item "Build/windows/curd-windows-x86_64.exe" "$release_dir/windows/" |
| 162 | 162 | Move-Item "Build/macos/curd-macos-universal" "$release_dir/macos/" |
| @@ -177,7 +177,7 @@ jobs: | ||
| 177 | 177 | |
| 178 | 178 | - name: Create Windows Installer |
| 179 | 179 | run: | |
| 180 | & "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" "Build\curd-windows-build.iss" | |
| 180 | & "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" "Build\curd-windows-build.iss" | |
| 181 | 181 | shell: pwsh |
| 182 | 182 | |
| 183 | 183 | - name: Build direct commit release notes |
| @@ -218,7 +218,10 @@ jobs: | ||
| 218 | 218 | $rawCommits = @() |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | $directCommitLines = @() | |
| 221 | $feats = @() | |
| 222 | $fixes = @() | |
| 223 | $chores = @() | |
| 224 | $others = @() | |
| 222 | 225 | $contributorSet = @{} |
| 223 | 226 | |
| 224 | 227 | foreach ($entry in $rawCommits) { |
| @@ -271,33 +274,63 @@ jobs: | ||
| 271 | 274 | } |
| 272 | 275 | |
| 273 | 276 | $contributorSet[$authorDisplay] = $true |
| 274 | $directCommitLines += "- $subject ([$shortSha](https://github.com/$repo/commit/$sha)) by $authorDisplay" | |
| 277 | $commitLine = "- $subject ([$shortSha](https://github.com/$repo/commit/$sha)) by $authorDisplay" | |
| 278 | ||
| 279 | if ($subject -match '^(?i)(feat|add)') { | |
| 280 | $feats += $commitLine | |
| 281 | } elseif ($subject -match '^(?i)(fix|bug|hotfix)') { | |
| 282 | $fixes += $commitLine | |
| 283 | } elseif ($subject -match '^(?i)(chore|clean|update|refactor|docs|style|test|ver)') { | |
| 284 | $chores += $commitLine | |
| 285 | } else { | |
| 286 | $others += $commitLine | |
| 287 | } | |
| 275 | 288 | } |
| 276 | 289 | |
| 277 | 290 | $notesPath = "Build/release-notes-extra.md" |
| 278 | 291 | |
| 279 | 292 | $body = @() |
| 280 | $body += "## Direct Commits" | |
| 281 | if ($directCommitLines.Count -eq 0) { | |
| 293 | $body += "## ๐ Changelog" | |
| 294 | $body += "" | |
| 295 | ||
| 296 | if ($feats.Count -gt 0) { | |
| 297 | $body += "### ๐ Features" | |
| 298 | $body += $feats | |
| 299 | $body += "" | |
| 300 | } | |
| 301 | if ($fixes.Count -gt 0) { | |
| 302 | $body += "### ๐ Bug Fixes" | |
| 303 | $body += $fixes | |
| 304 | $body += "" | |
| 305 | } | |
| 306 | if ($chores.Count -gt 0) { | |
| 307 | $body += "### ๐ง Maintenance & Improvements" | |
| 308 | $body += $chores | |
| 309 | $body += "" | |
| 310 | } | |
| 311 | if ($others.Count -gt 0) { | |
| 312 | $body += "### ๐ Other Changes" | |
| 313 | $body += $others | |
| 314 | $body += "" | |
| 315 | } | |
| 316 | ||
| 317 | if ($feats.Count -eq 0 -and $fixes.Count -eq 0 -and $chores.Count -eq 0 -and $others.Count -eq 0) { | |
| 282 | 318 | $body += "- No direct commits in this release range." |
| 283 | } else { | |
| 284 | $body += $directCommitLines | |
| 319 | $body += "" | |
| 285 | 320 | } |
| 286 | 321 | |
| 287 | $body += "" | |
| 288 | $body += "## Direct Commit Contributors" | |
| 322 | $body += "## ๐ค Contributors" | |
| 289 | 323 | $contributors = @($contributorSet.Keys | Sort-Object) |
| 290 | 324 | if ($contributors.Count -eq 0) { |
| 291 | 325 | $body += "- None" |
| 292 | 326 | } else { |
| 293 | foreach ($contributor in $contributors) { | |
| 294 | $body += "- $contributor" | |
| 295 | } | |
| 327 | $body += "- " + ($contributors -join ", ") | |
| 296 | 328 | } |
| 297 | 329 | |
| 298 | 330 | if ($previousTag) { |
| 299 | 331 | $body += "" |
| 300 | $body += "_Range: $previousTag..HEAD_" | |
| 332 | $body += "---" | |
| 333 | $body += "_Diff range: [$previousTag..v$env:CURD_VERSION](https://github.com/$repo/compare/$previousTag...v$env:CURD_VERSION)_" | |
| 301 | 334 | } |
| 302 | 335 | |
| 303 | 336 | $body | Set-Content -Path $notesPath -Encoding utf8 |
| @@ -305,7 +338,7 @@ jobs: | ||
| 305 | 338 | |
| 306 | 339 | - name: Create Release |
| 307 | 340 | id: create_release |
| 308 | uses: softprops/action-gh-release@v1 | |
| 341 | uses: softprops/action-gh-release@v2 | |
| 309 | 342 | with: |
| 310 | 343 | tag_name: "v${{ env.CURD_VERSION }}" |
| 311 | 344 | name: "Curd v${{ env.CURD_VERSION }}" |
Build/curd-windows-build.iss +1 โ1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | [Setup] |
| 2 | 2 | AppName=Curd Installer |
| 3 | AppVersion=2.0.0 | |
| 3 | AppVersion=2.0.2 | |
| 4 | 4 | DefaultDirName={userappdata}\Curd |
| 5 | 5 | PrivilegesRequired=lowest |
| 6 | 6 | AllowNoIcons=yes |
README.md +1
| @@ -377,6 +377,7 @@ If the browser reaches the localhost callback page but curd does not continue au | ||
| 377 | 377 | | `DiscordPresence` | Boolean | `true`, `false` | Enables or disables Discord Rich Presence integration. | |
| 378 | 378 | | `AnimeNameLanguage` | Enum | `english`, `romaji` | Sets the preferred language for anime names. | |
| 379 | 379 | | `MpvArgs` | List | all mpv args eg ["--fullscreen=yes", "--mute=yes"] | Add args to mpv player | |
| 380 | | `MpvPlaybackStartTimeout` | Integer | `1` to `600` (seconds) | How long to wait for MPV playback to start before trying another provider. Default: `20` | | |
| 380 | 381 | | `AddMissingOptions` | Boolean | `true`, `false` | Automatically adds missing configuration options with default values to the config file. | |
| 381 | 382 | | `AlternateScreen` | Boolean | `true`, `false` | Toggles the use of an alternate screen buffer for cleaner UI. | |
| 382 | 383 | | `RofiSelection` | Boolean | `true`, `false` | Enables or disables anime selection via Rofi. | |
internal/config.go +19
| @@ -40,6 +40,7 @@ type AnilistToken struct { | ||
| 40 | 40 | type CurdConfig struct { |
| 41 | 41 | Player string `config:"Player"` |
| 42 | 42 | MpvArgs []string `config:"MpvArgs"` |
| 43 | MpvPlaybackStartTimeout int `config:"MpvPlaybackStartTimeout"` | |
| 43 | 44 | SubsLanguage string `config:"SubsLanguage"` |
| 44 | 45 | SubOrDub string `config:"SubOrDub"` |
| 45 | 46 | SubStyle string `config:"SubStyle"` |
| @@ -73,6 +74,17 @@ type CurdConfig struct { | ||
| 73 | 74 | MyAnimeListImportDismissed bool `config:"MyAnimeListImportDismissed"` |
| 74 | 75 | } |
| 75 | 76 | |
| 77 | const DefaultMpvPlaybackStartTimeout = 20 | |
| 78 | const maxMpvPlaybackStartTimeout = 600 | |
| 79 | ||
| 80 | func MpvPlaybackStartTimeoutDuration(config *CurdConfig) time.Duration { | |
| 81 | seconds := DefaultMpvPlaybackStartTimeout | |
| 82 | if config != nil && config.MpvPlaybackStartTimeout > 0 { | |
| 83 | seconds = config.MpvPlaybackStartTimeout | |
| 84 | } | |
| 85 | return time.Duration(seconds) * time.Second | |
| 86 | } | |
| 87 | ||
| 76 | 88 | func GetStoragePath() string { |
| 77 | 89 | if globalConfig != nil && globalConfig.StoragePath != "" { |
| 78 | 90 | return os.ExpandEnv(globalConfig.StoragePath) |
| @@ -85,6 +97,7 @@ func defaultConfigMap() map[string]string { | ||
| 85 | 97 | return map[string]string{ |
| 86 | 98 | "Player": "mpv", |
| 87 | 99 | "MpvArgs": "[]", |
| 100 | "MpvPlaybackStartTimeout": "20", | |
| 88 | 101 | "StoragePath": "$HOME/.local/share/curd", |
| 89 | 102 | "AnimeNameLanguage": "english", |
| 90 | 103 | "SubsLanguage": "english", |
| @@ -677,6 +690,12 @@ func PopulateConfig(configMap map[string]string) CurdConfig { | ||
| 677 | 690 | config.PercentageToMarkComplete = 100 |
| 678 | 691 | } |
| 679 | 692 | |
| 693 | if config.MpvPlaybackStartTimeout <= 0 { | |
| 694 | config.MpvPlaybackStartTimeout = DefaultMpvPlaybackStartTimeout | |
| 695 | } else if config.MpvPlaybackStartTimeout > maxMpvPlaybackStartTimeout { | |
| 696 | config.MpvPlaybackStartTimeout = maxMpvPlaybackStartTimeout | |
| 697 | } | |
| 698 | ||
| 680 | 699 | return config |
| 681 | 700 | } |
| 682 | 701 | |
internal/curd.go +37 โ6
| @@ -1473,14 +1473,45 @@ episodeLinksReady: | ||
| 1473 | 1473 | } else { |
| 1474 | 1474 | CurdOut(fmt.Sprintf("%s - Episode %d", GetAnimeName(*anime), anime.Ep.Number)) |
| 1475 | 1475 | } |
| 1476 | mpvSocketPath, err := StartVideo(PrioritizeLink(anime.Ep.Links), []string{}, fmt.Sprintf("%s - Episode %d", GetAnimeName(*anime), anime.Ep.Number), anime) | |
| 1476 | title := fmt.Sprintf("%s - Episode %d", GetAnimeName(*anime), anime.Ep.Number) | |
| 1477 | var excludedProviders []string | |
| 1477 | 1478 | |
| 1478 | if err != nil { | |
| 1479 | Log("Failed to start mpv") | |
| 1480 | exitWithRestore(1) | |
| 1481 | } | |
| 1479 | for { | |
| 1480 | mpvSocketPath, err := StartVideo(PrioritizeLink(anime.Ep.Links), []string{}, title, anime) | |
| 1481 | if err != nil { | |
| 1482 | Log("Failed to start mpv") | |
| 1483 | exitWithRestore(1) | |
| 1484 | } | |
| 1485 | ||
| 1486 | if mpvSocketPath == "android-intent" || WaitForMPVPlaybackStart(mpvSocketPath, MpvPlaybackStartTimeoutDuration(userCurdConfig)) { | |
| 1487 | return mpvSocketPath | |
| 1488 | } | |
| 1489 | ||
| 1490 | failedProvider := CurrentAnimeProviderName(anime) | |
| 1491 | playbackTimeout := MpvPlaybackStartTimeoutDuration(userCurdConfig) | |
| 1492 | Log(fmt.Sprintf("Playback did not start with provider %s within %s", failedProvider, playbackTimeout)) | |
| 1493 | CurdOut(fmt.Sprintf("Playback failed to start with %s. Trying another provider...", failedProvider)) | |
| 1482 | 1494 | |
| 1483 | return mpvSocketPath | |
| 1495 | if mpvSocketPath != "" { | |
| 1496 | ExitMPV(mpvSocketPath) | |
| 1497 | } | |
| 1498 | anime.Ep.Player.SocketPath = "" | |
| 1499 | ||
| 1500 | excludedProviders = append(excludedProviders, failedProvider) | |
| 1501 | episodeResult, err := ResolveEpisodeURLExcludingProviders(*userCurdConfig, anime, anime.Ep.Number, excludedProviders) | |
| 1502 | if err != nil || len(episodeResult.Links) == 0 { | |
| 1503 | CurdOut("No alternative provider could start playback for this episode.") | |
| 1504 | if err != nil { | |
| 1505 | Log(fmt.Sprintf("Provider fallback failed: %v", err)) | |
| 1506 | } | |
| 1507 | exitWithRestore(1) | |
| 1508 | } | |
| 1509 | ||
| 1510 | anime.Ep.Links = episodeResult.Links | |
| 1511 | applyStreamPlaybackHints(anime, anime.Ep.Links, episodeResult.LinkHints) | |
| 1512 | Log(fmt.Sprintf("Retrying playback with %s/%s: %+v", episodeResult.ProviderName, episodeResult.Mode, episodeResult.Links)) | |
| 1513 | CurdOut(fmt.Sprintf("Retrying with %s...", episodeResult.ProviderName)) | |
| 1514 | } | |
| 1484 | 1515 | } |
| 1485 | 1516 | |
| 1486 | 1517 | func resolveRuntimeProviderID(userCurdConfig *CurdConfig, anime *Anime) error { |
internal/logic_regression_test.go +4
| @@ -185,11 +185,15 @@ func TestPopulateConfigFallsBackToDefaultsOnInvalidValues(t *testing.T) { | ||
| 185 | 185 | config := PopulateConfig(map[string]string{ |
| 186 | 186 | "PercentageToMarkComplete": "not-a-number", |
| 187 | 187 | "SkipOp": "not-a-bool", |
| 188 | "MpvPlaybackStartTimeout": "not-a-number", | |
| 188 | 189 | }) |
| 189 | 190 | |
| 190 | 191 | if config.PercentageToMarkComplete != 85 { |
| 191 | 192 | t.Fatalf("expected default completion percentage, got %d", config.PercentageToMarkComplete) |
| 192 | 193 | } |
| 194 | if config.MpvPlaybackStartTimeout != DefaultMpvPlaybackStartTimeout { | |
| 195 | t.Fatalf("expected default playback timeout, got %d", config.MpvPlaybackStartTimeout) | |
| 196 | } | |
| 193 | 197 | if !config.SkipOp { |
| 194 | 198 | t.Fatalf("expected invalid bool to fall back to default true") |
| 195 | 199 | } |
internal/player.go +56
| @@ -18,6 +18,8 @@ import ( | ||
| 18 | 18 | |
| 19 | 19 | var logFile = "debug.log" |
| 20 | 20 | |
| 21 | const mpvPlaybackPollInterval = 500 * time.Millisecond | |
| 22 | ||
| 21 | 23 | // This is not generic but we have MpvArgs in CurdConfig to add custom ones |
| 22 | 24 | const defaultStreamReferrer = "https://allanime.day/" |
| 23 | 25 | |
| @@ -471,6 +473,60 @@ func StartVideo(link string, args []string, title string, anime *Anime) (string, | ||
| 471 | 473 | return mpvSocketPath, nil |
| 472 | 474 | } |
| 473 | 475 | |
| 476 | // WaitForMPVPlaybackStart polls MPV until time-pos is available or the timeout elapses. | |
| 477 | // Returns true when playback has started, false when MPV exits or the timeout is reached. | |
| 478 | func WaitForMPVPlaybackStart(ipcSocketPath string, timeout time.Duration) bool { | |
| 479 | if ipcSocketPath == "" || ipcSocketPath == "android-intent" { | |
| 480 | return true | |
| 481 | } | |
| 482 | ||
| 483 | deadline := time.Now().Add(timeout) | |
| 484 | Log(fmt.Sprintf("Waiting up to %s for MPV playback to start at %s", timeout, ipcSocketPath)) | |
| 485 | ||
| 486 | for time.Now().Before(deadline) { | |
| 487 | timePos, err := MPVSendCommand(ipcSocketPath, []interface{}{"get_property", "time-pos"}) | |
| 488 | if err == nil && timePos != nil { | |
| 489 | if _, ok := timePos.(float64); ok { | |
| 490 | Log("MPV playback started") | |
| 491 | return true | |
| 492 | } | |
| 493 | } | |
| 494 | ||
| 495 | if err != nil { | |
| 496 | if isMPVConnectionGoneError(err) { | |
| 497 | Log("MPV exited before playback could start") | |
| 498 | return false | |
| 499 | } | |
| 500 | } | |
| 501 | ||
| 502 | time.Sleep(mpvPlaybackPollInterval) | |
| 503 | } | |
| 504 | ||
| 505 | Log(fmt.Sprintf("MPV playback did not start within %s", timeout)) | |
| 506 | return false | |
| 507 | } | |
| 508 | ||
| 509 | func isMPVConnectionGoneError(err error) bool { | |
| 510 | if err == nil { | |
| 511 | return false | |
| 512 | } | |
| 513 | errMsg := strings.ToLower(err.Error()) | |
| 514 | goneErrors := []string{ | |
| 515 | "connect: connection refused", | |
| 516 | "connect: no such file or directory", | |
| 517 | "cannot find the file specified", | |
| 518 | "pipe has been ended", | |
| 519 | "pipe is being closed", | |
| 520 | "no process is on the other end of the pipe", | |
| 521 | } | |
| 522 | for _, goneError := range goneErrors { | |
| 523 | if strings.Contains(errMsg, goneError) { | |
| 524 | return true | |
| 525 | } | |
| 526 | } | |
| 527 | return false | |
| 528 | } | |
| 529 | ||
| 474 | 530 | // Helper function to join args with a space |
| 475 | 531 | func joinArgs(args []string) string { |
| 476 | 532 | result := "" |
internal/player_playback_test.go added +45
| @@ -0,0 +1,45 @@ | ||
| 1 | package internal | |
| 2 | ||
| 3 | import ( | |
| 4 | "errors" | |
| 5 | "testing" | |
| 6 | "time" | |
| 7 | ) | |
| 8 | ||
| 9 | func TestWaitForMPVPlaybackStartSkipsNonIPCPlayers(t *testing.T) { | |
| 10 | timeout := MpvPlaybackStartTimeoutDuration(nil) | |
| 11 | if !WaitForMPVPlaybackStart("android-intent", timeout) { | |
| 12 | t.Fatal("expected android-intent playback wait to succeed immediately") | |
| 13 | } | |
| 14 | if !WaitForMPVPlaybackStart("", timeout) { | |
| 15 | t.Fatal("expected empty socket playback wait to succeed immediately") | |
| 16 | } | |
| 17 | } | |
| 18 | ||
| 19 | func TestMpvPlaybackStartTimeoutDurationUsesConfig(t *testing.T) { | |
| 20 | config := PopulateConfig(map[string]string{ | |
| 21 | "MpvPlaybackStartTimeout": "45", | |
| 22 | }) | |
| 23 | if got := MpvPlaybackStartTimeoutDuration(&config); got != 45*time.Second { | |
| 24 | t.Fatalf("expected 45s timeout, got %s", got) | |
| 25 | } | |
| 26 | } | |
| 27 | ||
| 28 | func TestIsMPVConnectionGoneError(t *testing.T) { | |
| 29 | for _, message := range []string{ | |
| 30 | "dial unix /tmp/curd: connect: connection refused", | |
| 31 | "dial unix /tmp/curd: connect: no such file or directory", | |
| 32 | "open \\\\.\\pipe\\curd: The system cannot find the file specified.", | |
| 33 | "read \\\\.\\pipe\\curd: The pipe has been ended.", | |
| 34 | "write \\\\.\\pipe\\curd: The pipe is being closed.", | |
| 35 | "read \\\\.\\pipe\\curd: No process is on the other end of the pipe.", | |
| 36 | } { | |
| 37 | if !isMPVConnectionGoneError(errors.New(message)) { | |
| 38 | t.Fatalf("expected gone error for %q", message) | |
| 39 | } | |
| 40 | } | |
| 41 | ||
| 42 | if isMPVConnectionGoneError(errors.New("i/o timeout")) { | |
| 43 | t.Fatal("did not expect timeout to be treated as closed connection") | |
| 44 | } | |
| 45 | } | |
internal/provider.go +28
| @@ -703,6 +703,34 @@ func episodeModeResultWithProviders(config CurdConfig, anime *Anime, epNo int, m | ||
| 703 | 703 | return ProviderEpisodeResult{}, fmt.Errorf("no %s episode links found across providers %s for %q episode %d: %s", mode, strings.Join(providerNames, ","), animeSearchTitle(anime), epNo, strings.Join(errors, "; ")) |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | func filterExcludedProviders(providerNames []string, exclude []string) []string { | |
| 707 | excludeSet := make(map[string]struct{}, len(exclude)) | |
| 708 | for _, name := range exclude { | |
| 709 | if normalized := normalizeProviderName(name); normalized != "" { | |
| 710 | excludeSet[normalized] = struct{}{} | |
| 711 | } | |
| 712 | } | |
| 713 | ||
| 714 | filtered := make([]string, 0, len(providerNames)) | |
| 715 | for _, name := range providerNames { | |
| 716 | if _, excluded := excludeSet[normalizeProviderName(name)]; excluded { | |
| 717 | continue | |
| 718 | } | |
| 719 | filtered = append(filtered, name) | |
| 720 | } | |
| 721 | return filtered | |
| 722 | } | |
| 723 | ||
| 724 | // ResolveEpisodeURLExcludingProviders tries configured providers in order, skipping any in exclude. | |
| 725 | func ResolveEpisodeURLExcludingProviders(config CurdConfig, anime *Anime, epNo int, exclude []string) (ProviderEpisodeResult, error) { | |
| 726 | mode := normalizeTranslationType(config.SubOrDub) | |
| 727 | providerNames := filterExcludedProviders(providerNamesForAnime(&config, anime), exclude) | |
| 728 | if len(providerNames) == 0 { | |
| 729 | return ProviderEpisodeResult{}, fmt.Errorf("no providers left to try") | |
| 730 | } | |
| 731 | return episodeModeResultWithProviders(config, anime, epNo, mode, providerNames) | |
| 732 | } | |
| 733 | ||
| 706 | 734 | func ResolveEpisodeURL(config CurdConfig, anime *Anime, epNo int) (ProviderEpisodeResult, error) { |
| 707 | 735 | return episodeModeResult(config, anime, epNo, config.SubOrDub) |
| 708 | 736 | } |
internal/provider_stack_test.go +44
| @@ -337,6 +337,50 @@ func TestResolveEpisodeURLUsesProviderListOrder(t *testing.T) { | ||
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | func TestFilterExcludedProviders(t *testing.T) { | |
| 341 | filtered := filterExcludedProviders([]string{"senshi", "allanime", "anipub"}, []string{"senshi", "SENSHI"}) | |
| 342 | if len(filtered) != 2 || filtered[0] != "allanime" || filtered[1] != "anipub" { | |
| 343 | t.Fatalf("unexpected filtered providers: %#v", filtered) | |
| 344 | } | |
| 345 | } | |
| 346 | ||
| 347 | func TestResolveEpisodeURLExcludingProviders(t *testing.T) { | |
| 348 | allanime := &stackStubProvider{ | |
| 349 | name: "allanime", | |
| 350 | episodeResults: map[string]map[string][]string{ | |
| 351 | "allanime-id": {"sub": {"allanime-sub"}}, | |
| 352 | }, | |
| 353 | searchResults: map[string][]SelectionOption{ | |
| 354 | "sub": {{Title: "Example", Key: "allanime-id"}}, | |
| 355 | }, | |
| 356 | } | |
| 357 | senshi := &stackStubProvider{ | |
| 358 | name: "senshi", | |
| 359 | episodeResults: map[string]map[string][]string{ | |
| 360 | "senshi-id": {"sub": {"senshi-sub"}}, | |
| 361 | }, | |
| 362 | searchResults: map[string][]SelectionOption{ | |
| 363 | "sub": {{Title: "Example", Key: "senshi-id"}}, | |
| 364 | }, | |
| 365 | } | |
| 366 | withProviderFactories(t, allanime, senshi) | |
| 367 | ||
| 368 | cfg := CurdConfig{Provider: `["senshi","allanime"]`, SubOrDub: "sub"} | |
| 369 | anime := &Anime{ | |
| 370 | Title: AnimeTitle{Romaji: "Example"}, | |
| 371 | ProviderName: "senshi", | |
| 372 | ProviderId: "senshi-id", | |
| 373 | } | |
| 374 | ||
| 375 | result, err := ResolveEpisodeURLExcludingProviders(cfg, anime, 1, []string{"senshi"}) | |
| 376 | if err != nil { | |
| 377 | t.Fatalf("ResolveEpisodeURLExcludingProviders returned error: %v", err) | |
| 378 | } | |
| 379 | if result.ProviderName != "allanime" || result.Links[0] != "allanime-sub" { | |
| 380 | t.Fatalf("expected allanime fallback, got %#v", result) | |
| 381 | } | |
| 382 | } | |
| 383 | ||
| 340 | 384 | func TestResolveEpisodeURLForPlaybackTriesAllPreferredProvidersBeforeAudioFallback(t *testing.T) { |
| 341 | 385 | allanime := &stackStubProvider{ |
| 342 | 386 | name: "allanime", |