refactor: use json for config to reach zero deps
All checks were successful
build / build (push) Successful in 1m30s

This commit is contained in:
Viktor Varland 2025-04-15 08:27:02 +02:00
parent e75c7873d9
commit c92fb61410
Signed by: varl
GPG key ID: 7459F0B410115EE8
7 changed files with 73 additions and 64 deletions

View file

@ -38,34 +38,35 @@ RUN addgroup --gid 1000 subsyt \
RUN mkdir /data
RUN mkdir /data/vids
RUN touch /data/config.toml
RUN touch /data/config.json
RUN touch /data/opml.xml
RUN chown --recursive subsyt:subsyt /data
USER subsyt
RUN mkdir -p /data/vids
COPY <<-EOT /data/config.toml
dry_run = false
out_dir = "/data/vids"
daemon = true
[provider]
[provider.youtube]
cmd = "/home/subsyt/.local/bin/yt-dlp"
opml_file = "/data/opml.xml"
url = "https://www.youtube.com"
quality = "res:1080"
output_path_template = "s%(upload_date>%Y)s/%(channel)s.s%(upload_date>%Y)Se%(upload_date>%m%d)S.%(title)s.%(id)s-1080p.%(ext)s"
throttle = 5
range = "1:5:1"
after_date = ""
cookies_file = ""
po_token = ""
bgutil_server = "http://bgutil:4416"
COPY <<-EOT /data/config.json
{
"daemon": true,
"dry_run": false,
"out_dir": "/data/vids",
"provider": {
"youtube": {
"verbose": false,
"cmd": "/home/subsyt/.local/bin/yt-dlp",
"quality": "res:1080",
"output_path_template": "s%(upload_date>%Y)s/%(channel)s.s%(upload_date>%Y)Se%(upload_date>%m%d)S.%(title)s.%(id)s-1080p.%(ext)s",
"url": "https://www.youtube.com",
"throttle": 5,
"range": "1:5:1",
"after_date": "",
"cookies_file": "",
"opml_file": "/data/opml.xml",
"po_token": "",
"bgutil_server": "http://bgutil:4416"
}
}
}
EOT
WORKDIR /app
@ -79,4 +80,4 @@ RUN pipx inject yt-dlp bgutil-ytdlp-pot-provider
COPY --from=builder --chown=subsyt:subsyt /src/build/subsyt /app/subsyt
CMD [ "/app/subsyt", "--config=/data/config.toml" ]
CMD [ "/app/subsyt", "--config=/data/config.json" ]

View file

@ -50,11 +50,11 @@ variable `CONFIG` or `--config` flag.
The `--config` flag has priority over `CONFIG` environment variable.
```
CONFIG="/path/to/config.toml" ./subsyt
CONFIG="/path/to/config.json" ./subsyt
./subsyt --config="/patch/to/config"
./subsyt # assumes "./config.toml"
./subsyt # assumes "./config.json"
```
## build
@ -67,26 +67,47 @@ CGO_ENABLED=0 go build
## config
Full `config.toml`:
Full `config.json`:
```toml
dry_run = true # set to `false` for real run
out_dir = "./vids" # path to archive vids
daemon = true # true to run scheduler, false to run once
```json
{
"daemon": true,
"dry_run": true,
"out_dir": "./vids",
"provider": {
"youtube": {
"verbose": false,
"cmd": "./yt-dlp",
"quality": "res:1080",
"output_path_template": "s%(upload_date>%Y)s/%(channel)s.s%(upload_date>%Y)Se%(upload_date>%m%d)S.%(title)s.%(id)s-1080p.%(ext)s",
"url": "https://www.youtube.com",
"throttle": 5,
"range": "1:1:1",
"after_date": "",
"cookies_file": "",
"opml_file": "./youtube_subs.opml",
"po_token": "",
"schedule": "",
"bgutil_server": "http://127.0.0.1:4416"
}
}
}
```
[provider]
[provider.youtube]
cmd = "./yt-dlp" # path to yt-dlp binary
quality = "res:1080" # set the preferred quality, blank for 1080
output_path_template = "s%(upload_date>%Y)s/%(channel)s.s%(upload_date>%Y)Se%(upload_date>%m%d)S.%(title)s.%(id)s-1080p.%(ext)s" # yt-dlp output template
url = "https://www.youtube.com" # full yt url
throttle = 5 # throttle yt request, 5s works well
range = "1:5:1" # downloads last 5 videos: [START][:STOP][:STEP]
after_date = "20250326" # only download videos after date
cookies_file = "" # pass user cookies to yt, blank to disable
opml_file = "./opml.xml" # the opml file to use
po_token = "" # manually pass a proof-of-origin token, blank to disable
verbose = true # debug info for provider
Minimal `config.json`:
```json
{
"out_dir": "./vids",
"provider": {
"youtube": {
"cmd": "./yt-dlp",
"throttle": 5,
"range": "1:1:1",
"opml_file": "./youtube_subs.opml"
}
}
}
```
## generate opml
@ -129,7 +150,7 @@ The steps for the browser is:
1. go to youtube.com and login using a (throw-away) account
1. export the cookies using extension, save to disk
1. close private browsing session
1. point `cookies_file` in `config.toml` to the cookies-file
1. point `cookies_file` in `config.json` to the cookies-file
Cookies may need to be refreshed if/when they expire, if so, repeat
steps 2-5.

4
go.mod
View file

@ -1,7 +1,3 @@
module git.meatbag.se/varl/subsyt
go 1.24.1
require github.com/pelletier/go-toml/v2 v2.2.3
require github.com/bmatcuk/doublestar v1.3.4 // indirect

12
go.sum
View file

@ -1,12 +0,0 @@
github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=
github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View file

@ -1,10 +1,9 @@
package config
import (
"encoding/json"
"log"
"os"
toml "github.com/pelletier/go-toml/v2"
)
type Provider struct {
@ -37,7 +36,7 @@ func Load(filepath string) (Config, error) {
cfg := Config{}
err = toml.Unmarshal(data, &cfg)
err = json.Unmarshal(data, &cfg)
if err != nil {
panic(err)
}

View file

@ -43,6 +43,10 @@ func Youtube(d Download, p config.Provider) {
log.Fatal("no channel !")
}
if p.Url == "" {
p.Url = "https://www.youtube.com"
}
fullUrl, err := url.Parse(p.Url)
if err != nil {
panic(err)

View file

@ -48,7 +48,7 @@ func main() {
} else if configEnv != "" {
configPath = configEnv
} else {
configPath = "./config.toml"
configPath = "./config.json"
}
log.Println("resolved config file", configPath)