add: add types and config package
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
@@ -0,0 +1,76 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"videnc-vibe/pkg/types"
|
||||
)
|
||||
|
||||
const (
|
||||
appName = "videnc-vibe"
|
||||
configName = "config.yaml"
|
||||
)
|
||||
|
||||
func Load(configPath string) (*types.Config, error) {
|
||||
var configFile string
|
||||
|
||||
if configPath != "" {
|
||||
configFile = configPath
|
||||
} else {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting home directory: %w", err)
|
||||
}
|
||||
configFile = filepath.Join(homeDir, ".config", appName, configName)
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(configFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading config file %s: %w", configFile, err)
|
||||
}
|
||||
|
||||
var cfg types.Config
|
||||
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
||||
return nil, fmt.Errorf("parsing config file: %w", err)
|
||||
}
|
||||
|
||||
if cfg.Paths.Input == "" {
|
||||
cfg.Paths.Input = "./input"
|
||||
}
|
||||
if cfg.Paths.Output == "" {
|
||||
cfg.Paths.Output = "./output"
|
||||
}
|
||||
if cfg.Paths.Originals == "" {
|
||||
cfg.Paths.Originals = "./originals"
|
||||
}
|
||||
if cfg.Paths.Failed == "" {
|
||||
cfg.Paths.Failed = "./failed"
|
||||
}
|
||||
if cfg.Encoding.DVD.CRF == 0 {
|
||||
cfg.Encoding.DVD.CRF = 30
|
||||
}
|
||||
if cfg.Encoding.DVD.Preset == 0 {
|
||||
cfg.Encoding.DVD.Preset = 2
|
||||
}
|
||||
if cfg.Encoding.Bluray.CRF == 0 {
|
||||
cfg.Encoding.Bluray.CRF = 29
|
||||
}
|
||||
if cfg.Encoding.Bluray.Preset == 0 {
|
||||
cfg.Encoding.Bluray.Preset = 3
|
||||
}
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
func EnsureDirs(cfg *types.Config) error {
|
||||
dirs := []string{cfg.Paths.Input, cfg.Paths.Output, cfg.Paths.Originals, cfg.Paths.Failed}
|
||||
for _, dir := range dirs {
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
return fmt.Errorf("creating directory %s: %w", dir, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type MediaType string
|
||||
|
||||
const (
|
||||
MediaTypeDVD MediaType = "DVD"
|
||||
MediaTypeBluRay MediaType = "Blu-ray"
|
||||
)
|
||||
|
||||
type Job struct {
|
||||
InputPath string
|
||||
OutputPath string
|
||||
MediaType MediaType
|
||||
Metadata *Metadata
|
||||
CRF int
|
||||
Preset int
|
||||
DeleteOrigin bool
|
||||
}
|
||||
|
||||
type Metadata struct {
|
||||
Title string
|
||||
Collection string
|
||||
Season string
|
||||
Episode string
|
||||
DateReleased string
|
||||
IMDBID string
|
||||
TVMazeID string
|
||||
OriginalMedia MediaType
|
||||
IsSeries bool
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
OMDBAPIKey string `yaml:"omdb_api_key"`
|
||||
Encoding EncodingConfig
|
||||
Paths PathsConfig
|
||||
}
|
||||
|
||||
type EncodingConfig struct {
|
||||
DVD EncodingParams `yaml:"dvd"`
|
||||
Bluray EncodingParams `yaml:"bluray"`
|
||||
}
|
||||
|
||||
type EncodingParams struct {
|
||||
CRF int `yaml:"crf"`
|
||||
Preset int `yaml:"preset"`
|
||||
}
|
||||
|
||||
type PathsConfig struct {
|
||||
Input string `yaml:"input"`
|
||||
Output string `yaml:"output"`
|
||||
Originals string `yaml:"originals"`
|
||||
Failed string `yaml:"failed"`
|
||||
}
|
||||
|
||||
type LogEntry struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Level string `json:"level"`
|
||||
Message string `json:"message"`
|
||||
File string `json:"file,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user