summaryrefslogtreecommitdiff
path: root/app/config.go
blob: d0e1e2ffb69f2cf9dab6e337061448bd6947f750 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package app

import (
	"encoding/json"
	"os"
)

// Config settings for main App.
type Config struct {
	Library     []*PathConfig      `json:"library"`
	Server      *ServerConfig      `json:"server"`
	Thumbnailer *ThumbnailerConfig `json:"thumbnailer"`
	Transcoder  *TranscoderConfig  `json:"transcoder"`
	Feed        *FeedConfig        `json:"feed"`
	Copyright   *Copyright         `json:"copyright"`
}

// PathConfig settings for media library path.
type PathConfig struct {
	Path                   string `json:"path"`
	Prefix                 string `json:"prefix"`
	PreserveUploadFilename bool   `json:"preserve_upload_filename,omitempty"`
}

// ServerConfig settings for App Server.
type ServerConfig struct {
	Host                   string `json:"host"`
	Port                   int    `json:"port"`
	StorePath              string `json:"store_path"`
	UploadPath             string `json:"upload_path"`
	PreserveUploadFilename bool   `json:"preserve_upload_filename,omitempty"`
	MaxUploadSize          int64  `json:"max_upload_size"`
}

// ThumbnailerConfig settings for Transcoder
type ThumbnailerConfig struct {
	Timeout           int `json:"timeout"`
	PositionFromStart int `json:"position_from_start"`
}

// Sizes a map of ffmpeg -s option to suffix. e.g: hd720 -> #720p
type Sizes map[string]string

// TranscoderConfig settings for Transcoder
type TranscoderConfig struct {
	Timeout int   `json:"timeout"`
	Sizes   Sizes `json:"sizes"`
}

// FeedConfig settings for App Feed.
type FeedConfig struct {
	ExternalURL string `json:"external_url"`
	Title       string `json:"title"`
	Link        string `json:"link"`
	Description string `json:"description"`
	Author      struct {
		Name  string `json:"name"`
		Email string `json:"email"`
	} `json:"author"`
	Copyright string `json:"copyright"`
}

// Copyright text for App.
type Copyright struct {
	Content string `json:"content"`
}

// DefaultConfig returns Config initialized with default values.
func DefaultConfig() *Config {
	return &Config{
		Library: []*PathConfig{
			{
				Path:                   "videos",
				Prefix:                 "",
				PreserveUploadFilename: false,
			},
		},
		Server: &ServerConfig{
			Host:                   "0.0.0.0",
			Port:                   8000,
			StorePath:              "tube.db",
			UploadPath:             "uploads",
			PreserveUploadFilename: false,
			MaxUploadSize:          104857600,
		},
		Thumbnailer: &ThumbnailerConfig{
			Timeout:           60,
			PositionFromStart: 3,
		},
		Transcoder: &TranscoderConfig{
			Timeout: 300,
			Sizes:   Sizes(nil),
		},
		Feed: &FeedConfig{
			ExternalURL: "http://localhost:8000",
		},
		Copyright: &Copyright{
			Content: "All Content herein Public Domain and User Contributed.",
		},
	}
}

// ReadFile reads a JSON file into Config.
func (c *Config) ReadFile(path string) error {
	f, err := os.Open(path)
	if err != nil {
		return err
	}
	defer f.Close()
	d := json.NewDecoder(f)
	return d.Decode(c)
}