1package main23import (4 "github.com/nmeum/mpvfs/fileserver"5 "github.com/nmeum/mpvfs/mpv"6 "github.com/nmeum/mpvfs/playlistfs"78 "strings"9)1011type playlist struct {12 *playlistfs.BlockRecv1314 state *playerState15 mpv *mpv.Client16}1718func newPlaylist() (fileserver.File, error) {19 p := &playlist{state: state, mpv: mpvClient}20 p.BlockRecv = playlistfs.NewBlockRecv(p)21 return p, nil22}2324func (l *playlist) CurrentReader() *strings.Reader {25 out := strings.Join(l.state.Playlist(), "\n")26 return strings.NewReader(out + "\n")27}2829func (l *playlist) NextReader() *strings.Reader {30 out := l.state.WaitPlayist()31 return strings.NewReader(out + "\n")32}3334func (l *playlist) Write(off int64, p []byte) (int, error) {35 entry, err := playlistfs.PlaylistCmd(p)36 if err != nil {37 return 0, err38 }3940 // TODO: There currently doesn't seem to be any way to retrieve41 // this information for a playlist-entry, only for the currently42 // loaded file.43 opts := map[string]string{44 "media-title": entry.Description,45 }4647 _, err = l.mpv.ExecCmd("loadfile", entry.FileName, "append", opts)48 if err != nil {49 return 0, err50 }5152 return len(p), nil53}5455func (l *playlist) Close() error {56 return nil57}