Add cache dir config and add some config env vars to helm chart
This commit is contained in:
parent
a95ff85cdf
commit
2e251e4593
|
@ -10,6 +10,7 @@ env:
|
||||||
YTDL_HTTP_LISTEN: 0.0.0.0
|
YTDL_HTTP_LISTEN: 0.0.0.0
|
||||||
YTDL_HTTP_PORT: 80
|
YTDL_HTTP_PORT: 80
|
||||||
# YTDL_HTTP_BASEPATH: /example
|
# YTDL_HTTP_BASEPATH: /example
|
||||||
|
YTDL_COOKIES_FILEPATH: /etc/ytdl-web/cookies.txt
|
||||||
|
|
||||||
service:
|
service:
|
||||||
main:
|
main:
|
||||||
|
@ -17,75 +18,10 @@ service:
|
||||||
http:
|
http:
|
||||||
port: 80
|
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:
|
persistence:
|
||||||
config:
|
config:
|
||||||
enabled: false
|
enabled: false
|
||||||
mountPath: /etc/ytdl-web/config.yaml
|
mountPath: /etc/ytdl-web
|
||||||
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"
|
|
||||||
|
|
||||||
ingress:
|
ingress:
|
||||||
main:
|
main:
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
# For prod environments use Production
|
# For prod environments use Production
|
||||||
# For staging envronments use Staging
|
# For staging envronments use Staging
|
||||||
env: Production
|
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:
|
http:
|
||||||
# The port to listen on
|
# The port to listen on
|
||||||
port: 8080
|
port: 8080
|
||||||
|
@ -16,9 +18,6 @@ http:
|
||||||
# A list of proxy servers to trust for security purposes
|
# A list of proxy servers to trust for security purposes
|
||||||
# Only needed when accessing app behind a proxy
|
# Only needed when accessing app behind a proxy
|
||||||
trustedProxies: []
|
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:
|
cookies:
|
||||||
# Whether to use cookies when fetching the video metadata
|
# Whether to use cookies when fetching the video metadata
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
|
@ -7,10 +7,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Env string `mapstructure:"env"`
|
Env string `mapstructure:"env"`
|
||||||
HTTP ConfigHTTP `mapstructure:"http"`
|
BinaryPath string `mapstructure:"binaryPath"`
|
||||||
Ytdlp ConfigYtdlp `mapstructure:"ytdlp"`
|
Cache ConfigCache `mapstructure:"cache"`
|
||||||
Cookies ConfigCookies `mapstructure:"cookies"`
|
HTTP ConfigHTTP `mapstructure:"http"`
|
||||||
|
Cookies ConfigCookies `mapstructure:"cookies"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) IsProduction() bool {
|
func (c *Config) IsProduction() bool {
|
||||||
|
@ -32,13 +33,9 @@ type ConfigHTTP struct {
|
||||||
TrustedProxies []string `mapstructure:"trustedProxies"`
|
TrustedProxies []string `mapstructure:"trustedProxies"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigYtdlp struct {
|
type ConfigCache struct {
|
||||||
BinaryPath string `mapstructure:"binaryPath"`
|
TTL time.Duration `mapstructure:"ttl"`
|
||||||
Cache ConfigYtdlpCache `mapstructure:"cache"`
|
DirPath string `mapstructure:"dirPath"`
|
||||||
}
|
|
||||||
|
|
||||||
type ConfigYtdlpCache struct {
|
|
||||||
TTL time.Duration `mapstructure:"ttl"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigCookies struct {
|
type ConfigCookies struct {
|
||||||
|
@ -61,15 +58,14 @@ func DefaultConfig() *Config {
|
||||||
Listen: "127.0.0.1",
|
Listen: "127.0.0.1",
|
||||||
BasePath: "/",
|
BasePath: "/",
|
||||||
},
|
},
|
||||||
Ytdlp: ConfigYtdlp{
|
BinaryPath: "yt-dlp",
|
||||||
BinaryPath: "yt-dlp",
|
Cache: ConfigCache{
|
||||||
Cache: ConfigYtdlpCache{
|
TTL: time.Hour,
|
||||||
TTL: time.Hour,
|
DirPath: "/tmp/ytdl-web",
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Cookies: ConfigCookies{
|
Cookies: ConfigCookies{
|
||||||
Enabled: false,
|
Enabled: false,
|
||||||
FilePath: "/tmp/ytdl-web.cookies",
|
FilePath: "./cookies.txt",
|
||||||
FromBrowser: nil,
|
FromBrowser: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ func Serve(cfg *config.Config) error {
|
||||||
|
|
||||||
db, err := badger.Open(
|
db, err := badger.Open(
|
||||||
badger.
|
badger.
|
||||||
DefaultOptions("/tmp/badger").
|
DefaultOptions(cfg.Cache.DirPath).
|
||||||
WithLogger(utils.NewBadgerLogger(slog.With("module", "badger"))),
|
WithLogger(utils.NewBadgerLogger(slog.With("module", "badger"))),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -69,12 +69,12 @@ func (y *ytdlImpl) GetMetadata(url string) (*metadata.Metadata, error) {
|
||||||
WithDumpJson(meta),
|
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()))
|
y.logger.Error("failed to get metadata", slog.String("url", url), slog.String("error", err.Error()))
|
||||||
return nil, err
|
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()))
|
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))
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue