playlist retry-exhaustion handling
This commit is contained in:
@@ -11,8 +11,9 @@ import (
|
||||
)
|
||||
|
||||
type playlistFile struct {
|
||||
Entries []playlistFileEntry `json:"entries"`
|
||||
Loop bool `json:"loop"`
|
||||
Entries []playlistFileEntry `json:"entries"`
|
||||
Loop bool `json:"loop"`
|
||||
OnFailure string `json:"on_failure"`
|
||||
}
|
||||
|
||||
type playlistFileEntry struct {
|
||||
@@ -62,6 +63,16 @@ func decodePlaylistFile(reader io.Reader) (playback.Playlist, error) {
|
||||
Entries: make([]playback.PlaylistEntry, len(file.Entries)),
|
||||
Loop: file.Loop,
|
||||
}
|
||||
switch file.OnFailure {
|
||||
case "", "wait":
|
||||
playlist.OnFailure = playback.PlaylistFailureWait
|
||||
case "next":
|
||||
playlist.OnFailure = playback.PlaylistFailureNext
|
||||
default:
|
||||
return playback.Playlist{}, fmt.Errorf(
|
||||
"on_failure %q: %w", file.OnFailure, playback.ErrPlaylistFailurePolicy,
|
||||
)
|
||||
}
|
||||
for index, entry := range file.Entries {
|
||||
duration := time.Duration(0)
|
||||
if entry.Duration != "" {
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
func TestDecodePlaylistFile(t *testing.T) {
|
||||
input := `{
|
||||
"loop": true,
|
||||
"on_failure": "next",
|
||||
"entries": [
|
||||
{
|
||||
"name": "sync",
|
||||
@@ -44,7 +45,8 @@ func TestDecodePlaylistFile(t *testing.T) {
|
||||
t.Fatalf("decodePlaylistFile() error = %v", err)
|
||||
}
|
||||
want := playback.Playlist{
|
||||
Loop: true,
|
||||
Loop: true,
|
||||
OnFailure: playback.PlaylistFailureNext,
|
||||
Entries: []playback.PlaylistEntry{
|
||||
{
|
||||
Name: "sync",
|
||||
@@ -69,7 +71,7 @@ func TestDecodePlaylistFile(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if len(got.Entries) != len(want.Entries) || got.Loop != want.Loop {
|
||||
if len(got.Entries) != len(want.Entries) || got.Loop != want.Loop || got.OnFailure != want.OnFailure {
|
||||
t.Fatalf("decodePlaylistFile() = %#v, want %#v", got, want)
|
||||
}
|
||||
for index := range want.Entries {
|
||||
@@ -100,6 +102,7 @@ func TestDecodePlaylistFileRejectsInvalidInput(t *testing.T) {
|
||||
{name: "malformed JSON", input: `{"entries": [`, wantText: "decode JSON"},
|
||||
{name: "unknown field", input: `{"unknown": true}`, wantText: "unknown field"},
|
||||
{name: "multiple roots", input: `{"entries": []} {"entries": []}`, wantText: "multiple root values"},
|
||||
{name: "invalid failure policy", input: `{"on_failure":"skip","entries":[]}`, wantErr: playback.ErrPlaylistFailurePolicy},
|
||||
{
|
||||
name: "invalid duration",
|
||||
input: `{"entries":[{"video":{"domain":"/video","uuid":"video"},"duration":"later"}]}`,
|
||||
|
||||
Reference in New Issue
Block a user