refactor: use json for config to reach zero deps
All checks were successful
build / build (push) Successful in 1m30s
All checks were successful
build / build (push) Successful in 1m30s
This commit is contained in:
parent
e75c7873d9
commit
c92fb61410
|
|
@ -38,34 +38,35 @@ RUN addgroup --gid 1000 subsyt \
|
||||||
|
|
||||||
RUN mkdir /data
|
RUN mkdir /data
|
||||||
RUN mkdir /data/vids
|
RUN mkdir /data/vids
|
||||||
RUN touch /data/config.toml
|
RUN touch /data/config.json
|
||||||
RUN touch /data/opml.xml
|
RUN touch /data/opml.xml
|
||||||
|
|
||||||
|
|
||||||
RUN chown --recursive subsyt:subsyt /data
|
RUN chown --recursive subsyt:subsyt /data
|
||||||
|
|
||||||
USER subsyt
|
USER subsyt
|
||||||
|
|
||||||
RUN mkdir -p /data/vids
|
COPY <<-EOT /data/config.json
|
||||||
|
{
|
||||||
COPY <<-EOT /data/config.toml
|
"daemon": true,
|
||||||
dry_run = false
|
"dry_run": false,
|
||||||
out_dir = "/data/vids"
|
"out_dir": "/data/vids",
|
||||||
daemon = true
|
"provider": {
|
||||||
|
"youtube": {
|
||||||
[provider]
|
"verbose": false,
|
||||||
[provider.youtube]
|
"cmd": "/home/subsyt/.local/bin/yt-dlp",
|
||||||
cmd = "/home/subsyt/.local/bin/yt-dlp"
|
"quality": "res:1080",
|
||||||
opml_file = "/data/opml.xml"
|
"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"
|
"url": "https://www.youtube.com",
|
||||||
quality = "res:1080"
|
"throttle": 5,
|
||||||
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"
|
"range": "1:5:1",
|
||||||
throttle = 5
|
"after_date": "",
|
||||||
range = "1:5:1"
|
"cookies_file": "",
|
||||||
after_date = ""
|
"opml_file": "/data/opml.xml",
|
||||||
cookies_file = ""
|
"po_token": "",
|
||||||
po_token = ""
|
"bgutil_server": "http://bgutil:4416"
|
||||||
bgutil_server = "http://bgutil:4416"
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
WORKDIR /app
|
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
|
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" ]
|
||||||
|
|
|
||||||
63
README.md
63
README.md
|
|
@ -50,11 +50,11 @@ variable `CONFIG` or `--config` flag.
|
||||||
The `--config` flag has priority over `CONFIG` environment variable.
|
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 --config="/patch/to/config"
|
||||||
|
|
||||||
./subsyt # assumes "./config.toml"
|
./subsyt # assumes "./config.json"
|
||||||
```
|
```
|
||||||
|
|
||||||
## build
|
## build
|
||||||
|
|
@ -67,26 +67,47 @@ CGO_ENABLED=0 go build
|
||||||
|
|
||||||
## config
|
## config
|
||||||
|
|
||||||
Full `config.toml`:
|
Full `config.json`:
|
||||||
|
|
||||||
```toml
|
```json
|
||||||
dry_run = true # set to `false` for real run
|
{
|
||||||
out_dir = "./vids" # path to archive vids
|
"daemon": true,
|
||||||
daemon = true # true to run scheduler, false to run once
|
"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]
|
Minimal `config.json`:
|
||||||
[provider.youtube]
|
|
||||||
cmd = "./yt-dlp" # path to yt-dlp binary
|
```json
|
||||||
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
|
"out_dir": "./vids",
|
||||||
url = "https://www.youtube.com" # full yt url
|
"provider": {
|
||||||
throttle = 5 # throttle yt request, 5s works well
|
"youtube": {
|
||||||
range = "1:5:1" # downloads last 5 videos: [START][:STOP][:STEP]
|
"cmd": "./yt-dlp",
|
||||||
after_date = "20250326" # only download videos after date
|
"throttle": 5,
|
||||||
cookies_file = "" # pass user cookies to yt, blank to disable
|
"range": "1:1:1",
|
||||||
opml_file = "./opml.xml" # the opml file to use
|
"opml_file": "./youtube_subs.opml"
|
||||||
po_token = "" # manually pass a proof-of-origin token, blank to disable
|
}
|
||||||
verbose = true # debug info for provider
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## generate 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. go to youtube.com and login using a (throw-away) account
|
||||||
1. export the cookies using extension, save to disk
|
1. export the cookies using extension, save to disk
|
||||||
1. close private browsing session
|
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
|
Cookies may need to be refreshed if/when they expire, if so, repeat
|
||||||
steps 2-5.
|
steps 2-5.
|
||||||
|
|
|
||||||
4
go.mod
4
go.mod
|
|
@ -1,7 +1,3 @@
|
||||||
module git.meatbag.se/varl/subsyt
|
module git.meatbag.se/varl/subsyt
|
||||||
|
|
||||||
go 1.24.1
|
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
12
go.sum
|
|
@ -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=
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
toml "github.com/pelletier/go-toml/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
|
|
@ -37,7 +36,7 @@ func Load(filepath string) (Config, error) {
|
||||||
|
|
||||||
cfg := Config{}
|
cfg := Config{}
|
||||||
|
|
||||||
err = toml.Unmarshal(data, &cfg)
|
err = json.Unmarshal(data, &cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,10 @@ func Youtube(d Download, p config.Provider) {
|
||||||
log.Fatal("no channel !")
|
log.Fatal("no channel !")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p.Url == "" {
|
||||||
|
p.Url = "https://www.youtube.com"
|
||||||
|
}
|
||||||
|
|
||||||
fullUrl, err := url.Parse(p.Url)
|
fullUrl, err := url.Parse(p.Url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -48,7 +48,7 @@ func main() {
|
||||||
} else if configEnv != "" {
|
} else if configEnv != "" {
|
||||||
configPath = configEnv
|
configPath = configEnv
|
||||||
} else {
|
} else {
|
||||||
configPath = "./config.toml"
|
configPath = "./config.json"
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("resolved config file", configPath)
|
log.Println("resolved config file", configPath)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue