Commit 4450a463dd

4450a463ddbefba422b6cac114637d34e50604c9

parent: 8dd90ce96d

Unsigned

Wraient <wraient.911@gmail.com> · 2026-07-22 21:22 UTC

Add idle MPV episode playlist and alternate audio entries

After playback is stable, populate MPV's playlist with episode rows
(and a dub/sub entry when that stream exists) without interrupting the
current demuxer. User picks an entry in MPV to switch episodes or audio
mode; curd resolves a fresh stream and loadfile-replaces seamlessly.
MpvEpisodePlaylist defaults to true (registered for 2.0.5).

Layout: unified · split

Build/curd-windows-build.iss +1 −1
@@ -1,6 +1,6 @@
11[Setup]
22AppName=Curd Installer
3AppVersion=2.0.4
3AppVersion=2.0.5
44DefaultDirName={userappdata}\Curd
55PrivilegesRequired=lowest
66AllowNoIcons=yes
README.md +1
@@ -381,6 +381,7 @@ If the browser reaches the localhost callback page but curd does not continue au
381381| `AddMissingOptions` | Boolean | `true`, `false` | When `true`, on a **version upgrade** only options registered as new for that release are **appended** to `curd.conf` (not every historical default). Set `false` to opt out. Defaults still apply in memory always. |
382382| `VimKeys` | Boolean | `true`, `false` | When `true`, selection menus use vim motions: `j`/`k`/`h`/`l` (and arrows) to move, `/` or `?` to search. Default: `false` (type-to-filter immediately). Add `VimKeys=true` to `~/.config/curd/curd.conf` to enable. |
383383| `CheckUpdates` | Boolean | `true`, `false` | When `true` (default), checks GitHub for a newer release **while idle** (does not delay startup). If an update is found, the next launch shows notes and options: update now / skip / remind later / turn off. |
384| `MpvEpisodePlaylist` | Boolean | `true`, `false` | When `true` (default), after playback is stable curd fills the MPV playlist with episodes (and dub/sub when available) so you can pick from MPV's playlist UI. Built only while idle — does not delay start. Selecting an entry loads that stream and keeps tracking in sync. |
384385| `AlternateScreen` | Boolean | `true`, `false` | Toggles the use of an alternate screen buffer for cleaner UI. |
385386| `RofiSelection` | Boolean | `true`, `false` | Enables or disables anime selection via Rofi. |
386387| `PercentageToMarkComplete`| Integer | `0` to `100` | Sets the percentage of an episode watched to consider it as completed. |
VERSION.txt +1 −1
@@ -1 +1 @@
12.0.4
12.0.5
cmd/curd/main.go +7 −1
@@ -17,7 +17,7 @@ var version string // Will be set by ldflags during build
1717
1818func resolvedVersion() string {
1919 if version == "" {
20 return "2.0.4"
20 return "2.0.5"
2121 }
2222
2323 return version
@@ -345,6 +345,12 @@ func main() {
345345 internal.Log(fmt.Sprint("Playback starting time: ", anime.Ep.Player.PlaybackTime))
346346 internal.Log(anime.Ep.Player.SocketPath)
347347
348 // After playback is running, lazily build MPV episode playlist / audio
349 // options while idle (no startup cost, no mid-buffer stutter).
350 if anime.Ep.Player.SocketPath != "" && anime.Ep.Player.SocketPath != "android-intent" {
351 internal.StartMPVPlaylistController(&userCurdConfig, &anime, anime.Ep.Player.SocketPath, skipLoopDone)
352 }
353
348354 // Handle Android Intent external player
349355 if anime.Ep.Player.SocketPath == "android-intent" {
350356 internal.CurdOut(fmt.Sprintf("\nOpened external player for Episode %d.", anime.Ep.Number))
internal/config.go +2
@@ -64,6 +64,7 @@ type CurdConfig struct {
6464 DiscordClientId string `config:"DiscordClientId"`
6565 VimKeys bool `config:"VimKeys"`
6666 CheckUpdates bool `config:"CheckUpdates"`
67 MpvEpisodePlaylist bool `config:"MpvEpisodePlaylist"`
6768 Provider string `config:"Provider"`
6869 DisabledProviders string `config:"DisabledProviders"`
6970 ManualProviderSearch bool `config:"ManualProviderSearch"`
@@ -122,6 +123,7 @@ func defaultConfigMap() map[string]string {
122123 "DiscordClientId": "1287457464148820089",
123124 "VimKeys": "false",
124125 "CheckUpdates": "true",
126 "MpvEpisodePlaylist": "true",
125127 "Provider": "stacked",
126128 "DisabledProviders": "[]",
127129 "ManualProviderSearch": "false",
internal/mpv_playlist.go added +547
@@ -0,0 +1,547 @@
1package internal
2
3import (
4 "fmt"
5 "strings"
6 "sync"
7 "sync/atomic"
8 "time"
9)
10
11// Placeholder media for non-current playlist rows. Short black frame so idle
12// playlist construction never pulls real streams; on select we replace immediately.
13const mpvEpisodePlaceholder = "av://lavfi:color=c=0x101010:s=16x16:d=1"
14
15const (
16 mpvPlaylistIdleDelay = 3 * time.Second
17 mpvPlaylistPollInterval = 400 * time.Millisecond
18 mpvPlaylistStableSamples = 3
19)
20
21// playlistSlot maps an MPV playlist index to curd episode + audio mode.
22type playlistSlot struct {
23 Episode int
24 Mode string // "sub" or "dub"
25 Label string
26}
27
28// MPVPlaylistController maintains a seamless MPV playlist of episodes (and
29// optional alternate audio entry) without interrupting active playback while
30// it is being built. Population happens only after playback is idle/stable.
31type MPVPlaylistController struct {
32 config *CurdConfig
33 anime *Anime
34 socket string
35 done <-chan struct{}
36
37 mu sync.Mutex
38 slots []playlistSlot
39 suppress atomic.Bool // ignore playlist-pos churn we cause ourselves
40 lastPos int
41 built bool
42 preferredMode string
43 hasAlternate bool
44 alternateMode string
45 currentPlaying int // episode number currently intended
46 currentMode string
47}
48
49// StartMPVPlaylistController waits until playback is stable, then builds the
50// episode playlist and watches for user selections. Safe to call in a goroutine.
51// Does nothing for android-intent / empty sockets or when disabled in config.
52func StartMPVPlaylistController(config *CurdConfig, anime *Anime, socket string, done <-chan struct{}) {
53 if config == nil || anime == nil || !config.MpvEpisodePlaylist {
54 return
55 }
56 if socket == "" || socket == "android-intent" {
57 return
58 }
59
60 c := &MPVPlaylistController{
61 config: config,
62 anime: anime,
63 socket: socket,
64 done: done,
65 lastPos: -1,
66 preferredMode: normalizeTranslationType(config.SubOrDub),
67 currentPlaying: anime.Ep.Number,
68 currentMode: normalizeTranslationType(config.SubOrDub),
69 }
70 if c.preferredMode == "" {
71 c.preferredMode = "sub"
72 }
73 c.currentMode = c.preferredMode
74 c.alternateMode = alternateTranslationType(c.preferredMode)
75
76 go c.run()
77}
78
79func (c *MPVPlaylistController) closed() bool {
80 select {
81 case <-c.done:
82 return true
83 default:
84 return false
85 }
86}
87
88func (c *MPVPlaylistController) run() {
89 if !c.waitUntilIdleStable() {
90 return
91 }
92 if c.closed() {
93 return
94 }
95
96 // Build episode rows without touching the currently playing demuxer path
97 // beyond append/insert of placeholders.
98 if err := c.buildEpisodePlaylist(); err != nil {
99 Log(fmt.Sprintf("MPV playlist build failed: %v", err))
100 // Still watch in case a partial list exists.
101 } else {
102 c.built = true
103 Log("MPV episode playlist ready")
104 }
105
106 if c.closed() {
107 return
108 }
109
110 // Probe alternate audio only after the list is up — never blocks first frame.
111 c.probeAndAttachAlternateAudio()
112
113 c.watchPlaylistSelection()
114}
115
116// waitUntilIdleStable waits until MPV reports a real time-pos a few times in a
117// row so we do not mutate the playlist during initial buffering.
118func (c *MPVPlaylistController) waitUntilIdleStable() bool {
119 deadline := time.Now().Add(45 * time.Second)
120 stable := 0
121 // Initial grace so loadfile/subs settle.
122 timer := time.NewTimer(mpvPlaylistIdleDelay)
123 defer timer.Stop()
124 select {
125 case <-c.done:
126 return false
127 case <-timer.C:
128 }
129
130 for time.Now().Before(deadline) {
131 if c.closed() {
132 return false
133 }
134 pos, err := MPVSendCommand(c.socket, []interface{}{"get_property", "time-pos"})
135 if err == nil && pos != nil {
136 if mpvNumber(pos) >= 0 {
137 stable++
138 if stable >= mpvPlaylistStableSamples {
139 return true
140 }
141 time.Sleep(mpvPlaylistPollInterval)
142 continue
143 }
144 }
145 stable = 0
146 time.Sleep(mpvPlaylistPollInterval)
147 }
148 Log("MPV playlist: playback never became stable; skipping playlist build")
149 return false
150}
151
152func (c *MPVPlaylistController) totalEpisodes() int {
153 if c.anime.TotalEpisodes > 0 {
154 return c.anime.TotalEpisodes
155 }
156 providerName, providerID := AnimeProviderID(c.anime)
157 if providerID == "" {
158 return 0
159 }
160 total, err := GetProviderTotalEpisodes(QualifyProviderID(providerName, providerID), c.preferredMode)
161 if err != nil || total <= 0 {
162 return 0
163 }
164 c.anime.TotalEpisodes = total
165 return total
166}
167
168func (c *MPVPlaylistController) episodeLabel(ep int, mode string) string {
169 name := GetAnimeName(*c.anime)
170 base := fmt.Sprintf("Ep %02d", ep)
171 if name != "" {
172 base = fmt.Sprintf("%s · Ep %02d", name, ep)
173 }
174 if c.anime.FillerEpisodes != nil && IsEpisodeFiller(c.anime.FillerEpisodes, ep) {
175 base += " [Filler]"
176 }
177 mode = normalizeTranslationType(mode)
178 if mode != "" && mode != c.preferredMode {
179 base += " · " + strings.ToUpper(mode)
180 } else if mode == "dub" {
181 base += " · DUB"
182 }
183 if ep == c.currentPlaying && mode == c.currentMode {
184 base += " ◀"
185 }
186 return base
187}
188
189func (c *MPVPlaylistController) buildEpisodePlaylist() error {
190 total := c.totalEpisodes()
191 if total <= 0 {
192 return fmt.Errorf("unknown total episode count")
193 }
194 currentEp := c.anime.Ep.Number
195 if currentEp < 1 {
196 currentEp = 1
197 }
198 if currentEp > total {
199 currentEp = total
200 }
201
202 c.suppress.Store(true)
203 defer c.suppress.Store(false)
204
205 // Title the currently playing item (index 0).
206 _ = c.setPlaylistTitle(0, c.episodeLabel(currentEp, c.currentMode))
207
208 // Insert previous episodes at the front (shifts current down).
209 for ep := currentEp - 1; ep >= 1; ep-- {
210 if c.closed() {
211 return nil
212 }
213 if err := c.insertPlaceholderAt(0, ep, c.preferredMode); err != nil {
214 Log(fmt.Sprintf("playlist insert ep %d: %v", ep, err))
215 }
216 // Tiny yield so IPC is not flooded mid-watch.
217 time.Sleep(30 * time.Millisecond)
218 }
219
220 // Append future episodes.
221 for ep := currentEp + 1; ep <= total; ep++ {
222 if c.closed() {
223 return nil
224 }
225 if err := c.appendPlaceholder(ep, c.preferredMode); err != nil {
226 Log(fmt.Sprintf("playlist append ep %d: %v", ep, err))
227 }
228 time.Sleep(30 * time.Millisecond)
229 }
230
231 // Rebuild slot map: index i => episode i+1 (preferred mode).
232 slots := make([]playlistSlot, 0, total)
233 for ep := 1; ep <= total; ep++ {
234 slots = append(slots, playlistSlot{
235 Episode: ep,
236 Mode: c.preferredMode,
237 Label: c.episodeLabel(ep, c.preferredMode),
238 })
239 }
240 c.mu.Lock()
241 c.slots = slots
242 c.currentPlaying = currentEp
243 c.mu.Unlock()
244
245 // Ensure MPV is still on the current episode index without forcing a reload
246 // when already correct.
247 wantPos := currentEp - 1
248 if pos, err := c.playlistPos(); err == nil && pos != wantPos {
249 // Setting playlist-pos would reload — only do it if we drifted.
250 // After inserts, mpv usually keeps the playing entry selected.
251 Log(fmt.Sprintf("MPV playlist-pos=%d want=%d (leaving as-is to avoid stutter)", pos, wantPos))
252 }
253 c.lastPos = wantPos
254 if pos, err := c.playlistPos(); err == nil {
255 c.lastPos = pos
256 }
257 return nil
258}
259
260func (c *MPVPlaylistController) insertPlaceholderAt(index, ep int, mode string) error {
261 // loadfile <url> insert-at <index>
262 _, err := MPVSendCommand(c.socket, []interface{}{"loadfile", mpvEpisodePlaceholder, "insert-at", index})
263 if err != nil {
264 // Older mpv: fall back to append (order less perfect but non-fatal).
265 _, err = MPVSendCommand(c.socket, []interface{}{"loadfile", mpvEpisodePlaceholder, "append"})
266 if err != nil {
267 return err
268 }
269 }
270 return c.setPlaylistTitle(index, c.episodeLabel(ep, mode))
271}
272
273func (c *MPVPlaylistController) appendPlaceholder(ep int, mode string) error {
274 _, err := MPVSendCommand(c.socket, []interface{}{"loadfile", mpvEpisodePlaceholder, "append"})
275 if err != nil {
276 return err
277 }
278 count, err := c.playlistCount()
279 if err != nil || count <= 0 {
280 return err
281 }
282 return c.setPlaylistTitle(count-1, c.episodeLabel(ep, mode))
283}
284
285func (c *MPVPlaylistController) setPlaylistTitle(index int, title string) error {
286 // mpv property: playlist/N/title
287 _, err := MPVSendCommand(c.socket, []interface{}{"set_property", fmt.Sprintf("playlist/%d/title", index), title})
288 return err
289}
290
291func (c *MPVPlaylistController) playlistPos() (int, error) {
292 v, err := MPVSendCommand(c.socket, []interface{}{"get_property", "playlist-pos"})
293 if err != nil {
294 return -1, err
295 }
296 return int(mpvNumber(v) + 0.5), nil
297}
298
299func (c *MPVPlaylistController) playlistCount() (int, error) {
300 v, err := MPVSendCommand(c.socket, []interface{}{"get_property", "playlist-count"})
301 if err != nil {
302 return 0, err
303 }
304 return int(mpvNumber(v) + 0.5), nil
305}
306
307// probeAndAttachAlternateAudio checks whether the opposite sub/dub mode has a
308// stream for the *current* episode. If yes, inserts a playlist row so the user
309// can switch audio by selecting it (full stream reload — only when chosen).
310func (c *MPVPlaylistController) probeAndAttachAlternateAudio() {
311 if c.closed() || c.anime == nil {
312 return
313 }
314 alt := c.alternateMode
315 cfg := *c.config
316 cfg.SubOrDub = alt
317
318 // Background resolve — does not touch MPV until we know a stream exists.
319 result, err := ResolveEpisodeURL(cfg, c.anime, c.currentPlaying)
320 if err != nil || len(result.Links) == 0 {
321 Log(fmt.Sprintf("MPV playlist: no %s stream for ep %d (%v)", alt, c.currentPlaying, err))
322 c.hasAlternate = false
323 return
324 }
325 c.hasAlternate = true
326
327 c.suppress.Store(true)
328 defer c.suppress.Store(false)
329
330 // Insert alternate entry right after the current episode index.
331 c.mu.Lock()
332 curIdx := c.currentPlaying - 1
333 if curIdx < 0 {
334 curIdx = 0
335 }
336 label := c.episodeLabel(c.currentPlaying, alt)
337 // Physical insert in mpv
338 insertAt := curIdx + 1
339 c.mu.Unlock()
340
341 if _, err := MPVSendCommand(c.socket, []interface{}{"loadfile", mpvEpisodePlaceholder, "insert-at", insertAt}); err != nil {
342 // Fallback append
343 if err := c.appendPlaceholder(c.currentPlaying, alt); err != nil {
344 Log(fmt.Sprintf("MPV playlist: failed to add %s entry: %v", alt, err))
345 return
346 }
347 c.mu.Lock()
348 c.slots = append(c.slots, playlistSlot{Episode: c.currentPlaying, Mode: alt, Label: label})
349 c.mu.Unlock()
350 return
351 }
352 _ = c.setPlaylistTitle(insertAt, label)
353
354 c.mu.Lock()
355 // Insert into slots map at insertAt
356 if insertAt >= len(c.slots) {
357 c.slots = append(c.slots, playlistSlot{Episode: c.currentPlaying, Mode: alt, Label: label})
358 } else {
359 slot := playlistSlot{Episode: c.currentPlaying, Mode: alt, Label: label}
360 c.slots = append(c.slots[:insertAt], append([]playlistSlot{slot}, c.slots[insertAt:]...)...)
361 }
362 c.mu.Unlock()
363 Log(fmt.Sprintf("MPV playlist: added %s option for ep %d", alt, c.currentPlaying))
364}
365
366func (c *MPVPlaylistController) watchPlaylistSelection() {
367 for {
368 if c.closed() {
369 return
370 }
371 if !IsMPVRunning(c.socket) {
372 return
373 }
374 if c.suppress.Load() {
375 time.Sleep(mpvPlaylistPollInterval)
376 continue
377 }
378 pos, err := c.playlistPos()
379 if err != nil {
380 time.Sleep(mpvPlaylistPollInterval)
381 continue
382 }
383 if pos < 0 {
384 time.Sleep(mpvPlaylistPollInterval)
385 continue
386 }
387 if pos == c.lastPos {
388 time.Sleep(mpvPlaylistPollInterval)
389 continue
390 }
391 // Debounce rapid scrubbing through the playlist UI.
392 time.Sleep(200 * time.Millisecond)
393 pos2, err2 := c.playlistPos()
394 if err2 != nil || pos2 != pos {
395 continue
396 }
397 c.lastPos = pos
398 c.handlePlaylistJump(pos)
399 }
400}
401
402func (c *MPVPlaylistController) handlePlaylistJump(pos int) {
403 c.mu.Lock()
404 if pos < 0 || pos >= len(c.slots) {
405 c.mu.Unlock()
406 return
407 }
408 slot := c.slots[pos]
409 curEp, curMode := c.currentPlaying, c.currentMode
410 c.mu.Unlock()
411
412 if slot.Episode == curEp && normalizeTranslationType(slot.Mode) == normalizeTranslationType(curMode) {
413 return
414 }
415
416 Log(fmt.Sprintf("MPV playlist: user selected ep %d (%s) at index %d", slot.Episode, slot.Mode, pos))
417 if err := c.playSlot(slot); err != nil {
418 Log(fmt.Sprintf("MPV playlist: failed to play ep %d: %v", slot.Episode, err))
419 CurdOut(fmt.Sprintf("Could not play episode %d: %v", slot.Episode, err))
420 // Try to restore previous playlist position without thrashing.
421 c.suppress.Store(true)
422 _, _ = MPVSendCommand(c.socket, []interface{}{"set_property", "playlist-pos", c.episodeIndex(curEp, curMode)})
423 c.suppress.Store(false)
424 }
425}
426
427func (c *MPVPlaylistController) episodeIndex(ep int, mode string) int {
428 c.mu.Lock()
429 defer c.mu.Unlock()
430 mode = normalizeTranslationType(mode)
431 for i, s := range c.slots {
432 if s.Episode == ep && normalizeTranslationType(s.Mode) == mode {
433 return i
434 }
435 }
436 // Fallback: first slot with that episode number.
437 for i, s := range c.slots {
438 if s.Episode == ep {
439 return i
440 }
441 }
442 if ep > 0 {
443 return ep - 1
444 }
445 return 0
446}
447
448func (c *MPVPlaylistController) playSlot(slot playlistSlot) error {
449 c.suppress.Store(true)
450 defer c.suppress.Store(false)
451
452 mode := normalizeTranslationType(slot.Mode)
453 if mode == "" {
454 mode = c.preferredMode
455 }
456
457 cfg := *c.config
458 cfg.SubOrDub = mode
459
460 // Work on a shallow copy for provider id resolution side effects, then copy back.
461 anime := c.anime
462 prevEp := anime.Ep.Number
463 anime.Ep.Number = slot.Episode
464
465 result, err := ResolveEpisodeURLForPlayback(cfg, anime, slot.Episode)
466 if err != nil || len(result.Links) == 0 {
467 anime.Ep.Number = prevEp
468 if err == nil {
469 err = fmt.Errorf("no streams")
470 }
471 return err
472 }
473
474 anime.Ep.Links = result.Links
475 applyStreamPlaybackHints(anime, result.Links, result.LinkHints)
476 link := PrioritizeLink(result.Links)
477 if link == "" {
478 anime.Ep.Number = prevEp
479 return fmt.Errorf("empty stream link")
480 }
481
482 title := c.episodeLabel(slot.Episode, mode)
483 // Reuse running MPV instance — loadfile replace is the intentional user switch.
484 anime.Ep.Player.SocketPath = c.socket
485 if _, err := StartVideo(link, []string{}, title, anime); err != nil {
486 anime.Ep.Number = prevEp
487 return err
488 }
489
490 anime.Ep.Number = slot.Episode
491 anime.Ep.Started = false
492 anime.Ep.IsCompleted = false
493 anime.Ep.Player.PlaybackTime = 0
494 anime.Ep.Duration = 0
495 anime.Ep.SkipTimes = SkipTimes{}
496
497 c.mu.Lock()
498 c.currentPlaying = slot.Episode
499 c.currentMode = mode
500 c.mu.Unlock()
501
502 // Refresh skip times in background (non-blocking for playback).
503 go func(ep int) {
504 if c.anime.MalId > 0 {
505 if err := GetAndParseAniSkipData(c.anime.MalId, ep, 0, c.anime); err != nil {
506 Log(fmt.Sprintf("AniSkip for ep %d: %v", ep, err))
507 }
508 if c.anime.Ep.SkipTimes.Op.Start != c.anime.Ep.SkipTimes.Op.End ||
509 c.anime.Ep.SkipTimes.Ed.Start != c.anime.Ep.SkipTimes.Ed.End {
510 _ = SendSkipTimesToMPV(c.anime)
511 }
512 }
513 }(slot.Episode)
514
515 // Rebuild playlist markers after a short idle (titles ◀ indicator, alternate audio).
516 go func() {
517 time.Sleep(mpvPlaylistIdleDelay)
518 if c.closed() {
519 return
520 }
521 // Soft retitle only — avoid full playlist rebuild (would stutter).
522 c.retitleSlots()
523 // Re-probe alternate for the new episode.
524 c.hasAlternate = false
525 c.probeAndAttachAlternateAudio()
526 }()
527
528 CurdOut(fmt.Sprintf("Playing episode %d (%s)", slot.Episode, mode))
529 return nil
530}
531
532func (c *MPVPlaylistController) retitleSlots() {
533 c.suppress.Store(true)
534 defer c.suppress.Store(false)
535 c.mu.Lock()
536 slots := append([]playlistSlot(nil), c.slots...)
537 curEp, curMode := c.currentPlaying, c.currentMode
538 c.mu.Unlock()
539 for i, s := range slots {
540 label := c.episodeLabel(s.Episode, s.Mode)
541 // episodeLabel uses c.currentPlaying for ◀ marker
542 _ = curEp
543 _ = curMode
544 _ = c.setPlaylistTitle(i, label)
545 time.Sleep(15 * time.Millisecond)
546 }
547}
internal/mpv_playlist_test.go added +60
@@ -0,0 +1,60 @@
1package internal
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestEpisodeLabelMarksCurrentAndFiller(t *testing.T) {
9 c := &MPVPlaylistController{
10 anime: &Anime{
11 Title: AnimeTitle{English: "Demo"},
12 FillerEpisodes: []int{3, 5},
13 Ep: Episode{Number: 2},
14 },
15 preferredMode: "sub",
16 currentPlaying: 2,
17 currentMode: "sub",
18 }
19 label := c.episodeLabel(2, "sub")
20 if !strings.Contains(label, "Ep 02") || !strings.Contains(label, "◀") {
21 t.Fatalf("current ep label: %q", label)
22 }
23 filler := c.episodeLabel(3, "sub")
24 if !strings.Contains(filler, "Filler") {
25 t.Fatalf("expected filler mark, got %q", filler)
26 }
27 dub := c.episodeLabel(2, "dub")
28 if !strings.Contains(strings.ToUpper(dub), "DUB") {
29 t.Fatalf("expected dub mark, got %q", dub)
30 }
31}
32
33func TestEpisodeIndexFindsAlternateModeSlot(t *testing.T) {
34 c := &MPVPlaylistController{
35 slots: []playlistSlot{
36 {Episode: 1, Mode: "sub"},
37 {Episode: 2, Mode: "sub"},
38 {Episode: 2, Mode: "dub"},
39 {Episode: 3, Mode: "sub"},
40 },
41 }
42 if got := c.episodeIndex(2, "dub"); got != 2 {
43 t.Fatalf("dub slot index=%d want 2", got)
44 }
45 if got := c.episodeIndex(2, "sub"); got != 1 {
46 t.Fatalf("sub slot index=%d want 1", got)
47 }
48 if got := c.episodeIndex(9, "sub"); got != 8 {
49 t.Fatalf("fallback index for ep9=%d want 8", got)
50 }
51}
52
53func TestIsEpisodeFillerHelper(t *testing.T) {
54 if !IsEpisodeFiller([]int{1, 4, 7}, 4) {
55 t.Fatal("expected filler")
56 }
57 if IsEpisodeFiller([]int{1, 4, 7}, 3) {
58 t.Fatal("expected non-filler")
59 }
60}
internal/provider_migrate.go +2
@@ -122,6 +122,8 @@ func configOptionsIntroducedInVersion() map[string]string {
122122 "VimKeys": "2.0.3",
123123 // 2.0.4 — idle background update checks
124124 "CheckUpdates": "2.0.4",
125 // 2.0.5 — MPV episode playlist + alternate audio entries
126 "MpvEpisodePlaylist": "2.0.5",
125127 }
126128}
127129