1- package config
1+ package main
22
33import (
44 "fmt"
55 "io/ioutil"
66 "path/filepath"
77 "regexp"
8- "time"
98
109 "github.com/hashicorp/go-multierror"
1110 "github.com/pelletier/go-toml"
1211 "github.com/pkg/errors"
1312
13+ "github.com/mxpv/podsync/pkg/db"
14+ "github.com/mxpv/podsync/pkg/feed"
1415 "github.com/mxpv/podsync/pkg/model"
16+ "github.com/mxpv/podsync/pkg/ytdl"
1517)
1618
17- // Feed is a configuration for a feed
18- type Feed struct {
19- ID string `toml:"-"`
20- // URL is a full URL of the field
21- URL string `toml:"url"`
22- // PageSize is the number of pages to query from YouTube API.
23- // NOTE: larger page sizes/often requests might drain your API token.
24- PageSize int `toml:"page_size"`
25- // UpdatePeriod is how often to check for updates.
26- // Format is "300ms", "1.5h" or "2h45m".
27- // Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
28- // NOTE: too often update check might drain your API token.
29- UpdatePeriod time.Duration `toml:"update_period"`
30- // Cron expression format is how often to check update
31- // NOTE: too often update check might drain your API token.
32- CronSchedule string `toml:"cron_schedule"`
33- // Quality to use for this feed
34- Quality model.Quality `toml:"quality"`
35- // Maximum height of video
36- MaxHeight int `toml:"max_height"`
37- // Format to use for this feed
38- Format model.Format `toml:"format"`
39- // Only download episodes that match this regexp (defaults to matching anything)
40- Filters Filters `toml:"filters"`
41- // Clean is a cleanup policy to use for this feed
42- Clean Cleanup `toml:"clean"`
43- // Custom is a list of feed customizations
44- Custom Custom `toml:"custom"`
45- // List of additional youtube-dl arguments passed at download time
46- YouTubeDLArgs []string `toml:"youtube_dl_args"`
47- // Included in OPML file
48- OPML bool `toml:"opml"`
49- // Playlist sort
50- PlaylistSort model.Sorting `toml:"playlist_sort"`
51- }
52-
53- type Filters struct {
54- Title string `toml:"title"`
55- NotTitle string `toml:"not_title"`
56- Description string `toml:"description"`
57- NotDescription string `toml:"not_description"`
58- // More filters to be added here
59- }
60-
61- type Custom struct {
62- CoverArt string `toml:"cover_art"`
63- CoverArtQuality model.Quality `toml:"cover_art_quality"`
64- Category string `toml:"category"`
65- Subcategories []string `toml:"subcategories"`
66- Explicit bool `toml:"explicit"`
67- Language string `toml:"lang"`
68- Author string `toml:"author"`
69- Title string `toml:"title"`
70- Description string `toml:"description"`
71- OwnerName string `toml:"ownerName"`
72- OwnerEmail string `toml:"ownerEmail"`
73- }
74-
75- type Server struct {
19+ type ServerConfig struct {
7620 // Hostname to use for download links
7721 Hostname string `toml:"hostname"`
7822 // Port is a server port to listen to
@@ -88,24 +32,6 @@ type Server struct {
8832 DataDir string `toml:"data_dir"`
8933}
9034
91- type Database struct {
92- // Dir is a directory to keep database files
93- Dir string `toml:"dir"`
94- Badger * Badger `toml:"badger"`
95- }
96-
97- // Badger represents BadgerDB configuration parameters
98- // See https://github.com/dgraph-io/badger#memory-usage
99- type Badger struct {
100- Truncate bool `toml:"truncate"`
101- FileIO bool `toml:"file_io"`
102- }
103-
104- type Cleanup struct {
105- // KeepLast defines how many episodes to keep
106- KeepLast int `toml:"keep_last"`
107- }
108-
10935type Log struct {
11036 // Filename to write the log to (instead of stdout)
11137 Filename string `toml:"filename"`
@@ -119,28 +45,20 @@ type Log struct {
11945 Compress bool `toml:"compress"`
12046}
12147
122- // Downloader is a youtube-dl related configuration
123- type Downloader struct {
124- // SelfUpdate toggles self update every 24 hour
125- SelfUpdate bool `toml:"self_update"`
126- // Timeout in minutes for youtube-dl process to finish download
127- Timeout int `toml:"timeout"`
128- }
129-
13048type Config struct {
13149 // Server is the web server configuration
132- Server Server `toml:"server"`
50+ Server ServerConfig `toml:"server"`
13351 // Log is the optional logging configuration
13452 Log Log `toml:"log"`
13553 // Database configuration
136- Database Database `toml:"database"`
54+ Database db. Config `toml:"database"`
13755 // Feeds is a list of feeds to host by this app.
13856 // ID will be used as feed ID in http://podsync.net/{FEED_ID}.xml
139- Feeds map [string ]* Feed
57+ Feeds map [string ]* feed. Config
14058 // Tokens is API keys to use to access YouTube/Vimeo APIs.
14159 Tokens map [model.Provider ][]string `toml:"tokens"`
14260 // Downloader (youtube-dl) configuration
143- Downloader Downloader `toml:"downloader"`
61+ Downloader ytdl. Config `toml:"downloader"`
14462}
14563
14664// LoadConfig loads TOML configuration from a file path
@@ -155,8 +73,8 @@ func LoadConfig(path string) (*Config, error) {
15573 return nil , errors .Wrap (err , "failed to unmarshal toml" )
15674 }
15775
158- for id , feed := range config .Feeds {
159- feed .ID = id
76+ for id , f := range config .Feeds {
77+ f .ID = id
16078 }
16179
16280 config .applyDefaults (path )
@@ -186,8 +104,8 @@ func (c *Config) validate() error {
186104 result = multierror .Append (result , errors .New ("at least one feed must be specified" ))
187105 }
188106
189- for id , feed := range c .Feeds {
190- if feed .URL == "" {
107+ for id , f := range c .Feeds {
108+ if f .URL == "" {
191109 result = multierror .Append (result , errors .Errorf ("URL is required for %q" , id ))
192110 }
193111 }
0 commit comments