2019-06-27 23:09:17 +03:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2019-06-30 01:02:05 +03:00
|
|
|
// Config settings for main App.
|
2019-06-27 23:09:17 +03:00
|
|
|
type Config struct {
|
2020-03-26 07:34:19 +03:00
|
|
|
Library []*PathConfig `json:"library"`
|
|
|
|
Server *ServerConfig `json:"server"`
|
|
|
|
Thumbnailer *ThumbnailerConfig `json:"thumbnailer"`
|
|
|
|
Transcoder *TranscoderConfig `json:"transcoder"`
|
|
|
|
Feed *FeedConfig `json:"feed"`
|
2021-06-08 16:22:14 +03:00
|
|
|
Copyright *Copyright `json:"copyright"`
|
2019-07-03 21:25:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// PathConfig settings for media library path.
|
|
|
|
type PathConfig struct {
|
2023-01-16 14:33:12 +03:00
|
|
|
Path string `json:"path"`
|
|
|
|
Prefix string `json:"prefix"`
|
|
|
|
PreserveUploadFilename bool `json:"preserve_upload_filename,omitempty"`
|
2019-06-27 23:09:17 +03:00
|
|
|
}
|
|
|
|
|
2019-06-30 01:02:05 +03:00
|
|
|
// ServerConfig settings for App Server.
|
2019-06-27 23:09:17 +03:00
|
|
|
type ServerConfig struct {
|
2023-01-16 14:33:12 +03:00
|
|
|
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"`
|
2019-06-27 23:09:17 +03:00
|
|
|
}
|
|
|
|
|
2020-03-26 07:34:19 +03:00
|
|
|
// ThumbnailerConfig settings for Transcoder
|
|
|
|
type ThumbnailerConfig struct {
|
2022-08-26 02:15:27 +03:00
|
|
|
Timeout int `json:"timeout"`
|
|
|
|
PositionFromStart int `json:"position_from_start"`
|
2020-03-26 07:34:19 +03:00
|
|
|
}
|
|
|
|
|
2020-03-31 12:04:21 +03:00
|
|
|
// Sizes a map of ffmpeg -s option to suffix. e.g: hd720 -> #720p
|
|
|
|
type Sizes map[string]string
|
|
|
|
|
2020-03-22 14:41:26 +03:00
|
|
|
// TranscoderConfig settings for Transcoder
|
|
|
|
type TranscoderConfig struct {
|
2020-03-31 12:04:21 +03:00
|
|
|
Timeout int `json:"timeout"`
|
|
|
|
Sizes Sizes `json:"sizes"`
|
2020-03-22 14:41:26 +03:00
|
|
|
}
|
|
|
|
|
2019-06-30 01:02:05 +03:00
|
|
|
// FeedConfig settings for App Feed.
|
2019-06-29 06:50:59 +03:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2021-06-08 16:22:14 +03:00
|
|
|
// Copyright text for App.
|
|
|
|
type Copyright struct {
|
|
|
|
Content string `json:"content"`
|
|
|
|
}
|
|
|
|
|
2019-06-30 01:02:05 +03:00
|
|
|
// DefaultConfig returns Config initialized with default values.
|
2019-06-27 23:09:17 +03:00
|
|
|
func DefaultConfig() *Config {
|
|
|
|
return &Config{
|
2019-07-03 21:25:42 +03:00
|
|
|
Library: []*PathConfig{
|
|
|
|
&PathConfig{
|
2023-01-16 14:33:12 +03:00
|
|
|
Path: "videos",
|
|
|
|
Prefix: "",
|
|
|
|
PreserveUploadFilename: false,
|
2019-07-03 21:25:42 +03:00
|
|
|
},
|
|
|
|
},
|
2019-06-27 23:09:17 +03:00
|
|
|
Server: &ServerConfig{
|
2023-01-16 14:33:12 +03:00
|
|
|
Host: "0.0.0.0",
|
|
|
|
Port: 8000,
|
|
|
|
StorePath: "tube.db",
|
|
|
|
UploadPath: "uploads",
|
|
|
|
PreserveUploadFilename: false,
|
|
|
|
MaxUploadSize: 104857600,
|
2020-03-22 14:41:26 +03:00
|
|
|
},
|
2020-03-26 08:41:20 +03:00
|
|
|
Thumbnailer: &ThumbnailerConfig{
|
2020-03-29 10:41:10 +03:00
|
|
|
Timeout: 60,
|
2023-01-21 03:59:40 +03:00
|
|
|
PositionFromStart: 3,
|
2020-03-26 08:41:20 +03:00
|
|
|
},
|
2020-03-22 14:41:26 +03:00
|
|
|
Transcoder: &TranscoderConfig{
|
2020-03-29 10:41:10 +03:00
|
|
|
Timeout: 300,
|
2020-03-31 12:04:21 +03:00
|
|
|
Sizes: Sizes(nil),
|
2019-06-27 23:09:17 +03:00
|
|
|
},
|
2019-06-29 06:50:59 +03:00
|
|
|
Feed: &FeedConfig{
|
2020-03-29 12:02:52 +03:00
|
|
|
ExternalURL: "http://localhost:8000",
|
2019-06-29 06:50:59 +03:00
|
|
|
},
|
2021-06-08 16:22:14 +03:00
|
|
|
Copyright: &Copyright{
|
|
|
|
Content: "All Content herein Public Domain and User Contributed.",
|
|
|
|
},
|
2019-06-27 23:09:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-30 01:02:05 +03:00
|
|
|
// ReadFile reads a JSON file into Config.
|
2019-06-27 23:09:17 +03:00
|
|
|
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)
|
|
|
|
}
|