Newer
Older
//
// tank
//
// Import and Playlist Daemon for autoradio project
//
//
// Copyright (C) 2017-2018 Christian Pointner <equinox@helsinki.at>
//
// This file is part of tank.
//
// tank is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// tank is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with tank. If not, see <http://www.gnu.org/licenses/>.
//
package store
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import (
"errors"
"strings"
)
type AudioFormat int
const (
FormatWAV AudioFormat = iota
FormatFlac
)
func (f AudioFormat) String() string {
switch f {
case FormatWAV:
return "wav"
case FormatFlac:
return "flac"
}
return "unknown"
}
func (f *AudioFormat) fromString(str string) error {
switch strings.ToLower(str) {
case "wav":
*f = FormatWAV
case "flac":
*f = FormatFlac
default:
return errors.New("invalid audio format: '" + str + "'")
}
return nil
}
func (f AudioFormat) MarshalText() (data []byte, err error) {
data = []byte(f.String())
return
}
func (f *AudioFormat) UnmarshalText(data []byte) (err error) {
return f.fromString(string(data))
}
func (f AudioFormat) Extension() string {
switch f {
case FormatWAV:
return ".wav"
case FormatFlac:
return ".flac"
}
return ""
}
type AudioConfig struct {
Format AudioFormat `json:"format" yaml:"format" toml:"format"`
SampleRate uint `json:"sample-rate" yaml:"sample-rate" toml:"sample-rate"`
}
type DBConfig struct {
Type string `json:"type" yaml:"type" toml:"type"`
Connection string `json:"connection" yaml:"connection" toml:"connection"`
}
BasePath string `json:"path" yaml:"path" toml:"path"`
Audio AudioConfig `json:"audio" yaml:"audio" toml:"audio"`
DB DBConfig `json:"db" yaml:"db" toml:"db"`