feat: load config from flag/env/fallback
All checks were successful
build / build (push) Successful in 1m53s

This commit is contained in:
Viktor Varland 2025-04-08 13:07:49 +02:00
parent 8c91c20fb2
commit b8ab0fa2bb
Signed by: varl
GPG key ID: 7459F0B410115EE8
2 changed files with 33 additions and 7 deletions

View file

@ -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
View file

@ -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)