mpvfs

9P file server for controlling mpv playback

git clone https://git.8pit.net/mpvfs.git

 1package main
 2
 3import (
 4	"github.com/nmeum/mpvfs/fileserver"
 5	"github.com/nmeum/mpvfs/mpv"
 6	"github.com/nmeum/mpvfs/playlistfs"
 7
 8	"strings"
 9)
10
11type playlist struct {
12	*playlistfs.BlockRecv
13
14	state *playerState
15	mpv   *mpv.Client
16}
17
18func newPlaylist() (fileserver.File, error) {
19	p := &playlist{state: state, mpv: mpvClient}
20	p.BlockRecv = playlistfs.NewBlockRecv(p)
21	return p, nil
22}
23
24func (l *playlist) CurrentReader() *strings.Reader {
25	out := strings.Join(l.state.Playlist(), "\n")
26	return strings.NewReader(out + "\n")
27}
28
29func (l *playlist) NextReader() *strings.Reader {
30	out := l.state.WaitPlayist()
31	return strings.NewReader(out + "\n")
32}
33
34func (l *playlist) Write(off int64, p []byte) (int, error) {
35	entry, err := playlistfs.PlaylistCmd(p)
36	if err != nil {
37		return 0, err
38	}
39
40	// TODO: There currently doesn't seem to be any way to retrieve
41	// this information for a playlist-entry, only for the currently
42	// loaded file.
43	opts := map[string]string{
44		"media-title": entry.Description,
45	}
46
47	_, err = l.mpv.ExecCmd("loadfile", entry.FileName, "append", opts)
48	if err != nil {
49		return 0, err
50	}
51
52	return len(p), nil
53}
54
55func (l *playlist) Close() error {
56	return nil
57}