Add cache dir config and add some config env vars to helm chart

This commit is contained in:
Evan Fiordeliso 2023-05-23 20:07:48 -04:00
parent a95ff85cdf
commit 2e251e4593
5 changed files with 21 additions and 90 deletions

View File

@ -10,6 +10,7 @@ env:
YTDL_HTTP_LISTEN: 0.0.0.0
YTDL_HTTP_PORT: 80
# YTDL_HTTP_BASEPATH: /example
YTDL_COOKIES_FILEPATH: /etc/ytdl-web/cookies.txt
service:
main:
@ -17,75 +18,10 @@ service:
http:
port: 80
secrets:
cookies:
enabled: true
data:
cookies.txt: ""
configMaps:
config:
enabled: true
data:
config.yaml: |-
# The server environment
# For dev environments use Development
# For prod environments use Production
# For staging envronments use Staging
env: Production
http:
# The port to listen on
port: 8080
# The address to listen on
# For local only access use 127.0.0.1
# For public access use 0.0.0.0
listen: 0.0.0.0
# The base path of the application, useful for reverse proxies
basePath: ""
# A list of proxy servers to trust for security purposes
# Only needed when accessing app behind a proxy
trustedProxies: []
ytdlp:
# The path to the yt-dlp binary, if it is already in your $PATH just yt-dlp will work.
binaryPath: yt-dlp
cookies:
# Whether to use cookies when fetching the video metadata
enabled: false
# The path to the netscape formatted cookies file
# See: https://www.reddit.com/r/youtubedl/wiki/cookies/ for details.
filePath: ~/.cookies
# Settings for using cookies from a browser's cookies store
fromBrowser:
# The name of the browser to load cookies from.
# Currently supported browsers are: brave, chrome, chromium, edge, firefox, opera, safari, vivaldi.
browser: firefox
# The keyring used for decrypting Chromium cookies on Linux
# Currently supported keyrings are: basictext, gnomekeyring, kwallet
keyring: basictext
# The profile to load cookies from (Firefox)
profile: default
# The container to load cookies from (Firefox)
container: none
persistence:
config:
enabled: false
mountPath: /etc/ytdl-web/config.yaml
subPath: config.yaml
type: configMap
name: "{{.Release.Name}}-config"
cookies:
enabled: false
mountPath: /etc/ytdl-web/cookies.txt
subPath: cookies.txt
type: secret
name: "{{.Release.Name}}-cookies"
mountPath: /etc/ytdl-web
ingress:
main:

View File

@ -3,6 +3,8 @@
# For prod environments use Production
# For staging envronments use Staging
env: Production
# The path to the yt-dlp binary, if it is already in your $PATH just yt-dlp will work.
binaryPath: yt-dlp
http:
# The port to listen on
port: 8080
@ -16,9 +18,6 @@ http:
# A list of proxy servers to trust for security purposes
# Only needed when accessing app behind a proxy
trustedProxies: []
ytdlp:
# The path to the yt-dlp binary, if it is already in your $PATH just yt-dlp will work.
binaryPath: yt-dlp
cookies:
# Whether to use cookies when fetching the video metadata
enabled: false

View File

@ -7,10 +7,11 @@ import (
)
type Config struct {
Env string `mapstructure:"env"`
HTTP ConfigHTTP `mapstructure:"http"`
Ytdlp ConfigYtdlp `mapstructure:"ytdlp"`
Cookies ConfigCookies `mapstructure:"cookies"`
Env string `mapstructure:"env"`
BinaryPath string `mapstructure:"binaryPath"`
Cache ConfigCache `mapstructure:"cache"`
HTTP ConfigHTTP `mapstructure:"http"`
Cookies ConfigCookies `mapstructure:"cookies"`
}
func (c *Config) IsProduction() bool {
@ -32,13 +33,9 @@ type ConfigHTTP struct {
TrustedProxies []string `mapstructure:"trustedProxies"`
}
type ConfigYtdlp struct {
BinaryPath string `mapstructure:"binaryPath"`
Cache ConfigYtdlpCache `mapstructure:"cache"`
}
type ConfigYtdlpCache struct {
TTL time.Duration `mapstructure:"ttl"`
type ConfigCache struct {
TTL time.Duration `mapstructure:"ttl"`
DirPath string `mapstructure:"dirPath"`
}
type ConfigCookies struct {
@ -61,15 +58,14 @@ func DefaultConfig() *Config {
Listen: "127.0.0.1",
BasePath: "/",
},
Ytdlp: ConfigYtdlp{
BinaryPath: "yt-dlp",
Cache: ConfigYtdlpCache{
TTL: time.Hour,
},
BinaryPath: "yt-dlp",
Cache: ConfigCache{
TTL: time.Hour,
DirPath: "/tmp/ytdl-web",
},
Cookies: ConfigCookies{
Enabled: false,
FilePath: "/tmp/ytdl-web.cookies",
FilePath: "./cookies.txt",
FromBrowser: nil,
},
}

View File

@ -27,7 +27,7 @@ func Serve(cfg *config.Config) error {
db, err := badger.Open(
badger.
DefaultOptions("/tmp/badger").
DefaultOptions(cfg.Cache.DirPath).
WithLogger(utils.NewBadgerLogger(slog.With("module", "badger"))),
)
if err != nil {

View File

@ -69,12 +69,12 @@ func (y *ytdlImpl) GetMetadata(url string) (*metadata.Metadata, error) {
WithDumpJson(meta),
)
if err := Exec(y.cfg.Ytdlp.BinaryPath, url, options...); err != nil {
if err := Exec(y.cfg.BinaryPath, url, options...); err != nil {
y.logger.Error("failed to get metadata", slog.String("url", url), slog.String("error", err.Error()))
return nil, err
}
if err := y.cache.Set(url, meta, y.cfg.Ytdlp.Cache.TTL); err != nil {
if err := y.cache.Set(url, meta, y.cfg.Cache.TTL); err != nil {
y.logger.Warn("failed to cache metadata", slog.String("url", url), slog.String("error", err.Error()))
}
@ -93,7 +93,7 @@ func (y *ytdlImpl) Download(w io.Writer, url, format string, index int) error {
options = append(options, WithPlaylistIndex(index))
}
if err := Exec(y.cfg.Ytdlp.BinaryPath, url, options...); err != nil {
if err := Exec(y.cfg.BinaryPath, url, options...); err != nil {
return err
}