feat: load config from flag/env/fallback
All checks were successful
build / build (push) Successful in 1m53s
All checks were successful
build / build (push) Successful in 1m53s
This commit is contained in:
parent
8c91c20fb2
commit
b8ab0fa2bb
25
README.md
25
README.md
|
|
@ -6,6 +6,21 @@
|
||||||
go install git.meatbag.se/varl/subsyt@latest
|
go install git.meatbag.se/varl/subsyt@latest
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## running
|
||||||
|
|
||||||
|
Configuration can be loaded from a file specified either by the env
|
||||||
|
variable `CONFIG` or `--config` flag.
|
||||||
|
|
||||||
|
The `--config` flag has priority over `CONFIG` environment variable.
|
||||||
|
|
||||||
|
```
|
||||||
|
CONFIG="/path/to/config.toml" ./subsyt
|
||||||
|
|
||||||
|
./subsyt --config="/patch/to/config"
|
||||||
|
|
||||||
|
./subsyt # assumes "./config.toml"
|
||||||
|
```
|
||||||
|
|
||||||
## config
|
## config
|
||||||
|
|
||||||
`config.toml`:
|
`config.toml`:
|
||||||
|
|
@ -53,7 +68,7 @@ opml_file = "./opml.xml" # the opml file to use
|
||||||
CGO_ENABLED=0 go build
|
CGO_ENABLED=0 go build
|
||||||
```
|
```
|
||||||
|
|
||||||
## Cookies
|
## cookies
|
||||||
|
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
> Your account **MAY** be banned when using cookies !
|
> Your account **MAY** be banned when using cookies !
|
||||||
|
|
@ -64,7 +79,7 @@ E.g. from Chromium:
|
||||||
yt-dlp --cookies-from-browser chromium --cookies cookies.txt
|
yt-dlp --cookies-from-browser chromium --cookies cookies.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
## Scheduling
|
## scheduling
|
||||||
|
|
||||||
### systemd
|
### systemd
|
||||||
|
|
||||||
|
|
@ -96,7 +111,7 @@ RandomizedDelaySec=30
|
||||||
WantedBy=timers.target
|
WantedBy=timers.target
|
||||||
```
|
```
|
||||||
|
|
||||||
## Container
|
## container
|
||||||
|
|
||||||
```
|
```
|
||||||
podman run --rm \
|
podman run --rm \
|
||||||
|
|
@ -107,7 +122,7 @@ podman run --rm \
|
||||||
registry.meatbag.se/varl/subsyt
|
registry.meatbag.se/varl/subsyt
|
||||||
```
|
```
|
||||||
|
|
||||||
## Result
|
## result
|
||||||
|
|
||||||
```
|
```
|
||||||
.
|
.
|
||||||
|
|
@ -135,6 +150,6 @@ podman run --rm \
|
||||||
│ └── tvshow.nfo
|
│ └── tvshow.nfo
|
||||||
```
|
```
|
||||||
|
|
||||||
## Generate OPML
|
## generate opml
|
||||||
|
|
||||||
E.g. https://github.com/jeb5/YouTube-Subscriptions-RSS
|
E.g. https://github.com/jeb5/YouTube-Subscriptions-RSS
|
||||||
|
|
|
||||||
15
main.go
15
main.go
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -12,12 +13,22 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
configPath := os.Getenv("CONFIG")
|
configPtr := flag.String("config", "", "path to config file")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
if configPath == "" {
|
configEnv := os.Getenv("CONFIG")
|
||||||
|
|
||||||
|
var configPath string
|
||||||
|
if *configPtr != "" {
|
||||||
|
configPath = *configPtr
|
||||||
|
} else if configEnv != "" {
|
||||||
|
configPath = configEnv
|
||||||
|
} else {
|
||||||
configPath = "./config.toml"
|
configPath = "./config.toml"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("resolved config file", configPath)
|
||||||
|
|
||||||
cfg, err := config.Load(configPath)
|
cfg, err := config.Load(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue