Commit d2d884983f

d2d884983f6bc912dfdf84538d11c49adc55fee3

parent: 0f2cbb7a25

Unsigned

Wraient <wraient.911@gmail.com> ยท 2026-07-22 18:59 UTC

Add MPV playback-start timeout with provider fallback

When a stream opens MPV but never begins playing, wait for time-pos up
to MpvPlaybackStartTimeout (default 20s), quit the player, and retry the
episode on the next configured provider. Also categorize release notes,
bump installer AppVersion to 2.0.2, and refresh CI action pins.

Layout: unified ยท split

.github/workflows/ci-cd.yml +56 โˆ’23
@@ -3,14 +3,14 @@ name: CI/CD Pipeline
3on: 3on:
4 push: 4 push:
5 branches: 5 branches:
6 - main # Trigger on pushes to the main branch 6 - main # Trigger on pushes to the main branch
7 pull_request: 7 pull_request:
8 branches: 8 branches:
9 - main # Trigger on pull requests targeting the main branch 9 - main # Trigger on pull requests targeting the main branch
10 workflow_dispatch: 10 workflow_dispatch:
11 inputs: 11 inputs:
12 pr_number: 12 pr_number:
13 description: 'Pull Request Number' 13 description: "Pull Request Number"
14 required: false 14 required: false
15 type: string 15 type: string
16 16
@@ -22,13 +22,13 @@ jobs:
22 - name: Checkout code 22 - name: Checkout code
23 uses: actions/checkout@v4 23 uses: actions/checkout@v4
24 with: 24 with:
25 fetch-depth: 0 # Fetch all history and tags 25 fetch-depth: 0 # Fetch all history and tags
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 }} 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 - name: Set up Go 28 - name: Set up Go
29 uses: actions/setup-go@v4 29 uses: actions/setup-go@v5
30 with: 30 with:
31 go-version: '1.21' 31 go-version: "1.21"
32 32
33 - name: Install Dependencies 33 - name: Install Dependencies
34 run: go mod tidy 34 run: go mod tidy
@@ -147,16 +147,16 @@ jobs:
147 $version = Get-Content VERSION.txt 147 $version = Get-Content VERSION.txt
148 echo "CURD_VERSION=$version" >> $env:GITHUB_ENV 148 echo "CURD_VERSION=$version" >> $env:GITHUB_ENV
149 $release_dir = "releases/curd-$version" 149 $release_dir = "releases/curd-$version"
150 150
151 # Create directory structure 151 # Create directory structure
152 New-Item -ItemType Directory -Force -Path "$release_dir/windows" 152 New-Item -ItemType Directory -Force -Path "$release_dir/windows"
153 New-Item -ItemType Directory -Force -Path "$release_dir/macos" 153 New-Item -ItemType Directory -Force -Path "$release_dir/macos"
154 New-Item -ItemType Directory -Force -Path "$release_dir/linux" 154 New-Item -ItemType Directory -Force -Path "$release_dir/linux"
155 155
156 # List contents of Build directory to debug 156 # List contents of Build directory to debug
157 Write-Host "Contents of Build directory:" 157 Write-Host "Contents of Build directory:"
158 Get-ChildItem -Path "Build" -Recurse 158 Get-ChildItem -Path "Build" -Recurse
159 159
160 # Move files to their respective directories 160 # Move files to their respective directories
161 Move-Item "Build/windows/curd-windows-x86_64.exe" "$release_dir/windows/" 161 Move-Item "Build/windows/curd-windows-x86_64.exe" "$release_dir/windows/"
162 Move-Item "Build/macos/curd-macos-universal" "$release_dir/macos/" 162 Move-Item "Build/macos/curd-macos-universal" "$release_dir/macos/"
@@ -177,7 +177,7 @@ jobs:
177 177
178 - name: Create Windows Installer 178 - name: Create Windows Installer
179 run: | 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 shell: pwsh 181 shell: pwsh
182 182
183 - name: Build direct commit release notes 183 - name: Build direct commit release notes
@@ -218,7 +218,10 @@ jobs:
218 $rawCommits = @() 218 $rawCommits = @()
219 } 219 }
220 220
221 $directCommitLines = @() 221 $feats = @()
222 $fixes = @()
223 $chores = @()
224 $others = @()
222 $contributorSet = @{} 225 $contributorSet = @{}
223 226
224 foreach ($entry in $rawCommits) { 227 foreach ($entry in $rawCommits) {
@@ -271,33 +274,63 @@ jobs:
271 } 274 }
272 275
273 $contributorSet[$authorDisplay] = $true 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 $notesPath = "Build/release-notes-extra.md" 290 $notesPath = "Build/release-notes-extra.md"
278 291
279 $body = @() 292 $body = @()
280 $body += "## Direct Commits" 293 $body += "## ๐Ÿ“ Changelog"
281 if ($directCommitLines.Count -eq 0) { 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 $body += "- No direct commits in this release range." 318 $body += "- No direct commits in this release range."
283 } else { 319 $body += ""
284 $body += $directCommitLines
285 } 320 }
286 321
287 $body += "" 322 $body += "## ๐Ÿค Contributors"
288 $body += "## Direct Commit Contributors"
289 $contributors = @($contributorSet.Keys | Sort-Object) 323 $contributors = @($contributorSet.Keys | Sort-Object)
290 if ($contributors.Count -eq 0) { 324 if ($contributors.Count -eq 0) {
291 $body += "- None" 325 $body += "- None"
292 } else { 326 } else {
293 foreach ($contributor in $contributors) { 327 $body += "- " + ($contributors -join ", ")
294 $body += "- $contributor"
295 }
296 } 328 }
297 329
298 if ($previousTag) { 330 if ($previousTag) {
299 $body += "" 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 $body | Set-Content -Path $notesPath -Encoding utf8 336 $body | Set-Content -Path $notesPath -Encoding utf8
@@ -305,7 +338,7 @@ jobs:
305 338
306 - name: Create Release 339 - name: Create Release
307 id: create_release 340 id: create_release
308 uses: softprops/action-gh-release@v1 341 uses: softprops/action-gh-release@v2
309 with: 342 with:
310 tag_name: "v${{ env.CURD_VERSION }}" 343 tag_name: "v${{ env.CURD_VERSION }}"
311 name: "Curd v${{ env.CURD_VERSION }}" 344 name: "Curd v${{ env.CURD_VERSION }}"
Build/curd-windows-build.iss +1 โˆ’1
@@ -1,6 +1,6 @@
1[Setup] 1[Setup]
2AppName=Curd Installer 2AppName=Curd Installer
3AppVersion=2.0.0 3AppVersion=2.0.2
4DefaultDirName={userappdata}\Curd 4DefaultDirName={userappdata}\Curd
5PrivilegesRequired=lowest 5PrivilegesRequired=lowest
6AllowNoIcons=yes 6AllowNoIcons=yes
README.md +1
@@ -377,6 +377,7 @@ If the browser reaches the localhost callback page but curd does not continue au
377| `DiscordPresence` | Boolean | `true`, `false` | Enables or disables Discord Rich Presence integration. | 377| `DiscordPresence` | Boolean | `true`, `false` | Enables or disables Discord Rich Presence integration. |
378| `AnimeNameLanguage` | Enum | `english`, `romaji` | Sets the preferred language for anime names. | 378| `AnimeNameLanguage` | Enum | `english`, `romaji` | Sets the preferred language for anime names. |
379| `MpvArgs` | List | all mpv args eg ["--fullscreen=yes", "--mute=yes"] | Add args to mpv player | 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| `AddMissingOptions` | Boolean | `true`, `false` | Automatically adds missing configuration options with default values to the config file. | 381| `AddMissingOptions` | Boolean | `true`, `false` | Automatically adds missing configuration options with default values to the config file. |
381| `AlternateScreen` | Boolean | `true`, `false` | Toggles the use of an alternate screen buffer for cleaner UI. | 382| `AlternateScreen` | Boolean | `true`, `false` | Toggles the use of an alternate screen buffer for cleaner UI. |
382| `RofiSelection` | Boolean | `true`, `false` | Enables or disables anime selection via Rofi. | 383| `RofiSelection` | Boolean | `true`, `false` | Enables or disables anime selection via Rofi. |
internal/config.go +19
@@ -40,6 +40,7 @@ type AnilistToken struct {
40type CurdConfig struct { 40type CurdConfig struct {
41 Player string `config:"Player"` 41 Player string `config:"Player"`
42 MpvArgs []string `config:"MpvArgs"` 42 MpvArgs []string `config:"MpvArgs"`
43 MpvPlaybackStartTimeout int `config:"MpvPlaybackStartTimeout"`
43 SubsLanguage string `config:"SubsLanguage"` 44 SubsLanguage string `config:"SubsLanguage"`
44 SubOrDub string `config:"SubOrDub"` 45 SubOrDub string `config:"SubOrDub"`
45 SubStyle string `config:"SubStyle"` 46 SubStyle string `config:"SubStyle"`
@@ -73,6 +74,17 @@ type CurdConfig struct {
73 MyAnimeListImportDismissed bool `config:"MyAnimeListImportDismissed"` 74 MyAnimeListImportDismissed bool `config:"MyAnimeListImportDismissed"`
74} 75}
75 76
77const DefaultMpvPlaybackStartTimeout = 20
78const maxMpvPlaybackStartTimeout = 600
79
80func 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
76func GetStoragePath() string { 88func GetStoragePath() string {
77 if globalConfig != nil && globalConfig.StoragePath != "" { 89 if globalConfig != nil && globalConfig.StoragePath != "" {
78 return os.ExpandEnv(globalConfig.StoragePath) 90 return os.ExpandEnv(globalConfig.StoragePath)
@@ -85,6 +97,7 @@ func defaultConfigMap() map[string]string {
85 return map[string]string{ 97 return map[string]string{
86 "Player": "mpv", 98 "Player": "mpv",
87 "MpvArgs": "[]", 99 "MpvArgs": "[]",
100 "MpvPlaybackStartTimeout": "20",
88 "StoragePath": "$HOME/.local/share/curd", 101 "StoragePath": "$HOME/.local/share/curd",
89 "AnimeNameLanguage": "english", 102 "AnimeNameLanguage": "english",
90 "SubsLanguage": "english", 103 "SubsLanguage": "english",
@@ -677,6 +690,12 @@ func PopulateConfig(configMap map[string]string) CurdConfig {
677 config.PercentageToMarkComplete = 100 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 return config 699 return config
681} 700}
682 701
internal/curd.go +37 โˆ’6
@@ -1473,14 +1473,45 @@ episodeLinksReady:
1473 } else { 1473 } else {
1474 CurdOut(fmt.Sprintf("%s - Episode %d", GetAnimeName(*anime), anime.Ep.Number)) 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 for {
1479 Log("Failed to start mpv") 1480 mpvSocketPath, err := StartVideo(PrioritizeLink(anime.Ep.Links), []string{}, title, anime)
1480 exitWithRestore(1) 1481 if err != nil {
1481 } 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
1486func resolveRuntimeProviderID(userCurdConfig *CurdConfig, anime *Anime) error { 1517func resolveRuntimeProviderID(userCurdConfig *CurdConfig, anime *Anime) error {
internal/logic_regression_test.go +4
@@ -185,11 +185,15 @@ func TestPopulateConfigFallsBackToDefaultsOnInvalidValues(t *testing.T) {
185 config := PopulateConfig(map[string]string{ 185 config := PopulateConfig(map[string]string{
186 "PercentageToMarkComplete": "not-a-number", 186 "PercentageToMarkComplete": "not-a-number",
187 "SkipOp": "not-a-bool", 187 "SkipOp": "not-a-bool",
188 "MpvPlaybackStartTimeout": "not-a-number",
188 }) 189 })
189 190
190 if config.PercentageToMarkComplete != 85 { 191 if config.PercentageToMarkComplete != 85 {
191 t.Fatalf("expected default completion percentage, got %d", config.PercentageToMarkComplete) 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 if !config.SkipOp { 197 if !config.SkipOp {
194 t.Fatalf("expected invalid bool to fall back to default true") 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
19var logFile = "debug.log" 19var logFile = "debug.log"
20 20
21const mpvPlaybackPollInterval = 500 * time.Millisecond
22
21// This is not generic but we have MpvArgs in CurdConfig to add custom ones 23// This is not generic but we have MpvArgs in CurdConfig to add custom ones
22const defaultStreamReferrer = "https://allanime.day/" 24const defaultStreamReferrer = "https://allanime.day/"
23 25
@@ -471,6 +473,60 @@ func StartVideo(link string, args []string, title string, anime *Anime) (string,
471 return mpvSocketPath, nil 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.
478func 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
509func 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// Helper function to join args with a space 530// Helper function to join args with a space
475func joinArgs(args []string) string { 531func joinArgs(args []string) string {
476 result := "" 532 result := ""
internal/player_playback_test.go added +45
@@ -0,0 +1,45 @@
1package internal
2
3import (
4 "errors"
5 "testing"
6 "time"
7)
8
9func 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
19func 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
28func 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 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, "; ")) 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
706func 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.
725func 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
706func ResolveEpisodeURL(config CurdConfig, anime *Anime, epNo int) (ProviderEpisodeResult, error) { 734func ResolveEpisodeURL(config CurdConfig, anime *Anime, epNo int) (ProviderEpisodeResult, error) {
707 return episodeModeResult(config, anime, epNo, config.SubOrDub) 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
340func 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
347func 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
340func TestResolveEpisodeURLForPlaybackTriesAllPreferredProvidersBeforeAudioFallback(t *testing.T) { 384func TestResolveEpisodeURLForPlaybackTriesAllPreferredProvidersBeforeAudioFallback(t *testing.T) {
341 allanime := &stackStubProvider{ 385 allanime := &stackStubProvider{
342 name: "allanime", 386 name: "allanime",