more controlling, more config options

This commit is contained in:
garionion 2020-12-26 17:20:18 +01:00
parent 0d9ce5656f
commit 9ed2982253
7 changed files with 181 additions and 68 deletions

View file

@ -3,35 +3,38 @@ package store
import (
"errors"
"ffmpeg-playout/playout"
"fmt"
"github.com/google/uuid"
"log"
"sync"
"time"
)
type Store struct {
Playouts map[uuid.UUID]*playout.Job
Playouts map[int]*playout.Job
DefaultDuration time.Duration
Outputs []string
*playout.Config
sync.RWMutex
}
func NewStore(o []string, defaultDuration string) (*Store, error) {
playouts := make(map[uuid.UUID]*playout.Job)
func NewStore(o []string, defaultDuration string, playoutScriptPath string, playoutScript string, tmpDir string) (*Store, error) {
playouts := make(map[int]*playout.Job)
var d time.Duration
var err error
if d, err = time.ParseDuration(defaultDuration); err != nil {
log.Fatal("Failed to set Default Duration: ", err)
}
store := &Store{Playouts: playouts, DefaultDuration: d, Outputs: o}
pcfg := playout.Config{
PlayoutScriptPath: playoutScriptPath,
PlayoutScript: playoutScript,
ProgressDir: tmpDir,
}
store := &Store{Playouts: playouts, DefaultDuration: d, Outputs: o, Config: &pcfg}
return store, nil
}
func (s *Store) AddPlayout(p *playout.Job) (uuid.UUID, error) {
func (s *Store) AddPlayout(p *playout.Job) (string, error) {
outputs := s.Outputs
for _, value := range s.Playouts {
if len(outputs) != 0 &&
@ -49,15 +52,17 @@ func (s *Store) AddPlayout(p *playout.Job) (uuid.UUID, error) {
if len(outputs) != 0 {
output = outputs[0]
} else {
return uuid.Nil, errors.New("no output available")
}
uid, err := uuid.NewUUID()
if err != nil {
return uuid.Nil, fmt.Errorf("couldn't generate uuid: %s", err.Error())
return "", errors.New("no output available")
}
p.Output = output
s.Playouts[uid] = p
return uid, nil
s.Playouts[p.ID] = p
return output, nil
}
func (s *Store) DeletePlayout(id int) {
s.Lock()
delete(s.Playouts, id)
s.Unlock()
}
//https://stackoverflow.com/a/15323988/10997297