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
33on:
44 push:
55 branches:
6 - main # Trigger on pushes to the main branch
6 - main # Trigger on pushes to the main branch
77 pull_request:
88 branches:
9 - main # Trigger on pull requests targeting the main branch
9 - main # Trigger on pull requests targeting the main branch
1010 workflow_dispatch:
1111 inputs:
1212 pr_number:
13 description: 'Pull Request Number'
13 description: "Pull Request Number"
1414 required: false
1515 type: string
1616
@@ -22,13 +22,13 @@ jobs:
2222 - name: Checkout code
2323 uses: actions/checkout@v4
2424 with:
25 fetch-depth: 0 # Fetch all history and tags
25 fetch-depth: 0 # Fetch all history and tags
2626 ref: ${{ github.event.pull_request.head.sha || (github.event.inputs.pr_number && format('refs/pull/{0}/head', github.event.inputs.pr_number)) || github.sha }}
2727
2828 - name: Set up Go
29 uses: actions/setup-go@v4
29 uses: actions/setup-go@v5
3030 with:
31 go-version: '1.21'
31 go-version: "1.21"
3232
3333 - name: Install Dependencies
3434 run: go mod tidy
@@ -147,16 +147,16 @@ jobs:
147147 $version = Get-Content VERSION.txt
148148 echo "CURD_VERSION=$version" >> $env:GITHUB_ENV
149149 $release_dir = "releases/curd-$version"
150
150
151151 # Create directory structure
152152 New-Item -ItemType Directory -Force -Path "$release_dir/windows"
153153 New-Item -ItemType Directory -Force -Path "$release_dir/macos"
154154 New-Item -ItemType Directory -Force -Path "$release_dir/linux"
155
155
156156 # List contents of Build directory to debug
157157 Write-Host "Contents of Build directory:"
158158 Get-ChildItem -Path "Build" -Recurse
159
159
160160 # Move files to their respective directories
161161 Move-Item "Build/windows/curd-windows-x86_64.exe" "$release_dir/windows/"
162162 Move-Item "Build/macos/curd-macos-universal" "$release_dir/macos/"
@@ -177,7 +177,7 @@ jobs:
177177
178178 - name: Create Windows Installer
179179 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"
181181 shell: pwsh
182182
183183 - name: Build direct commit release notes
@@ -218,7 +218,10 @@ jobs:
218218 $rawCommits = @()
219219 }
220220
221 $directCommitLines = @()
221 $feats = @()
222 $fixes = @()
223 $chores = @()
224 $others = @()
222225 $contributorSet = @{}
223226
224227 foreach ($entry in $rawCommits) {
@@ -271,33 +274,63 @@ jobs:
271274 }
272275
273276 $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 }
275288 }
276289
277290 $notesPath = "Build/release-notes-extra.md"
278291
279292 $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) {
282318 $body += "- No direct commits in this release range."
283 } else {
284 $body += $directCommitLines
319 $body += ""
285320 }
286321
287 $body += ""
288 $body += "## Direct Commit Contributors"
322 $body += "## ๐Ÿค Contributors"
289323 $contributors = @($contributorSet.Keys | Sort-Object)
290324 if ($contributors.Count -eq 0) {
291325 $body += "- None"
292326 } else {
293 foreach ($contributor in $contributors) {
294 $body += "- $contributor"
295 }
327 $body += "- " + ($contributors -join ", ")
296328 }
297329
298330 if ($previousTag) {
299331 $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)_"
301334 }
302335
303336 $body | Set-Content -Path $notesPath -Encoding utf8
@@ -305,7 +338,7 @@ jobs:
305338
306339 - name: Create Release
307340 id: create_release
308 uses: softprops/action-gh-release@v1
341 uses: softprops/action-gh-release@v2
309342 with:
310343 tag_name: "v${{ env.CURD_VERSION }}"
311344 name: "Curd v${{ env.CURD_VERSION }}"
Build/curd-windows-build.iss +1 โˆ’1
@@ -1,6 +1,6 @@
11[Setup]
22AppName=Curd Installer
3AppVersion=2.0.0
3AppVersion=2.0.2
44DefaultDirName={userappdata}\Curd
55PrivilegesRequired=lowest
66AllowNoIcons=yes
README.md +1
@@ -377,6 +377,7 @@ If the browser reaches the localhost callback page but curd does not continue au
377377| `DiscordPresence` | Boolean | `true`, `false` | Enables or disables Discord Rich Presence integration. |
378378| `AnimeNameLanguage` | Enum | `english`, `romaji` | Sets the preferred language for anime names. |
379379| `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` |
380381| `AddMissingOptions` | Boolean | `true`, `false` | Automatically adds missing configuration options with default values to the config file. |
381382| `AlternateScreen` | Boolean | `true`, `false` | Toggles the use of an alternate screen buffer for cleaner UI. |
382383| `RofiSelection` | Boolean | `true`, `false` | Enables or disables anime selection via Rofi. |
internal/config.go +19
@@ -40,6 +40,7 @@ type AnilistToken struct {
4040type CurdConfig struct {
4141 Player string `config:"Player"`
4242 MpvArgs []string `config:"MpvArgs"`
43 MpvPlaybackStartTimeout int `config:"MpvPlaybackStartTimeout"`
4344 SubsLanguage string `config:"SubsLanguage"`
4445 SubOrDub string `config:"SubOrDub"`
4546 SubStyle string `config:"SubStyle"`
@@ -73,6 +74,17 @@ type CurdConfig struct {
7374 MyAnimeListImportDismissed bool `config:"MyAnimeListImportDismissed"`
7475}
7576
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
7688func GetStoragePath() string {
7789 if globalConfig != nil && globalConfig.StoragePath != "" {
7890 return os.ExpandEnv(globalConfig.StoragePath)
@@ -85,6 +97,7 @@ func defaultConfigMap() map[string]string {
8597 return map[string]string{
8698 "Player": "mpv",
8799 "MpvArgs": "[]",
100 "MpvPlaybackStartTimeout": "20",
88101 "StoragePath": "$HOME/.local/share/curd",
89102 "AnimeNameLanguage": "english",
90103 "SubsLanguage": "english",
@@ -677,6 +690,12 @@ func PopulateConfig(configMap map[string]string) CurdConfig {
677690 config.PercentageToMarkComplete = 100
678691 }
679692
693 if config.MpvPlaybackStartTimeout <= 0 {
694 config.MpvPlaybackStartTimeout = DefaultMpvPlaybackStartTimeout
695 } else if config.MpvPlaybackStartTimeout > maxMpvPlaybackStartTimeout {
696 config.MpvPlaybackStartTimeout = maxMpvPlaybackStartTimeout
697 }
698
680699 return config
681700}
682701
internal/curd.go +37 โˆ’6
@@ -1473,14 +1473,45 @@ episodeLinksReady:
14731473 } else {
14741474 CurdOut(fmt.Sprintf("%s - Episode %d", GetAnimeName(*anime), anime.Ep.Number))
14751475 }
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
14771478
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))
14821494
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 }
14841515}
14851516
14861517func resolveRuntimeProviderID(userCurdConfig *CurdConfig, anime *Anime) error {
internal/logic_regression_test.go +4
@@ -185,11 +185,15 @@ func TestPopulateConfigFallsBackToDefaultsOnInvalidValues(t *testing.T) {
185185 config := PopulateConfig(map[string]string{
186186 "PercentageToMarkComplete": "not-a-number",
187187 "SkipOp": "not-a-bool",
188 "MpvPlaybackStartTimeout": "not-a-number",
188189 })
189190
190191 if config.PercentageToMarkComplete != 85 {
191192 t.Fatalf("expected default completion percentage, got %d", config.PercentageToMarkComplete)
192193 }
194 if config.MpvPlaybackStartTimeout != DefaultMpvPlaybackStartTimeout {
195 t.Fatalf("expected default playback timeout, got %d", config.MpvPlaybackStartTimeout)
196 }
193197 if !config.SkipOp {
194198 t.Fatalf("expected invalid bool to fall back to default true")
195199 }
internal/player.go +56
@@ -18,6 +18,8 @@ import (
1818
1919var logFile = "debug.log"
2020
21const mpvPlaybackPollInterval = 500 * time.Millisecond
22
2123// This is not generic but we have MpvArgs in CurdConfig to add custom ones
2224const defaultStreamReferrer = "https://allanime.day/"
2325
@@ -471,6 +473,60 @@ func StartVideo(link string, args []string, title string, anime *Anime) (string,
471473 return mpvSocketPath, nil
472474}
473475
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
474530// Helper function to join args with a space
475531func joinArgs(args []string) string {
476532 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
703703 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, "; "))
704704}
705705
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
706734func ResolveEpisodeURL(config CurdConfig, anime *Anime, epNo int) (ProviderEpisodeResult, error) {
707735 return episodeModeResult(config, anime, epNo, config.SubOrDub)
708736}
internal/provider_stack_test.go +44
@@ -337,6 +337,50 @@ func TestResolveEpisodeURLUsesProviderListOrder(t *testing.T) {
337337 }
338338}
339339
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
340384func TestResolveEpisodeURLForPlaybackTriesAllPreferredProvidersBeforeAudioFallback(t *testing.T) {
341385 allanime := &stackStubProvider{
342386 name: "allanime",