Add config dir env variable

This commit is contained in:
Evan Fiordeliso 2023-07-12 19:16:28 -04:00
parent 3b9d08ebbd
commit 96bffc8fb0
5 changed files with 28 additions and 8 deletions

View File

@ -14,6 +14,7 @@ EXPOSE 8080
ENV YTDL_HTTP_PORT=8080 \
YTDL_HTTP_LISTEN=0.0.0.0 \
YTDL_BINARYPATH=/usr/bin/yt-dlp
YTDL_BINARYPATH=/usr/bin/yt-dlp \
YTDL_CONFIGDIR=/config
ENTRYPOINT [ "./ytdl-web" ]

View File

@ -23,6 +23,7 @@ You can configure the application using environment variables
| Variable Name | Description | Default Value | Accepted Values |
| ---------------------------------- | ----------------------------------------------------------------------------------------------- | --------------- | ------------------------------------------------------------------------------ |
| YTDL_CONFIGDIR | Add a custom config directory to search for the config file | ` ` | |
| YTDL_ENV | The application environment | `Production` | `Development`, `Staging`, `Production` |
| YTDL_BINARYPATH | The path to the yt-dlp binary | `yt-dlp` | |
| YTDL_HTTP_PORT | The tcp port for the web server to listen on | `8080` | |
@ -32,10 +33,10 @@ You can configure the application using environment variables
| YTDL_CACHE_DIRPATH | The path to the directory of where to store the cache | `/tmp/ytdl-web` | |
| YTDL_COOKIES_ENABLED | Whether to use cookies when using yt-dlp | `true` | `true` or `false` |
| YTDL_COOKIES_FILEPATH | The path to the netscape format cookies file | `./cookies.txt` | |
| YTDL_COOKIES_FROMBROWSER_BROWSER | The name of the browser to load cookies from. (if specified, it disables YTDL_COOKIES_FILEPATH) | `` | `brave`, `chrome`, `chromium`, `edge`, `firefox`, `opera`, `safari`, `vivaldi` |
| YTDL_COOKIES_FROMBROWSER_KEYRING | The name of the keyring for decrypting cookies for the chromium browser on linux | `` | `basictext`, `gnomekeyring`, `kwallet` |
| YTDL_COOKIES_FROMBROWSER_PROFILE | The browser profile to load cookies from | `` | |
| YTDL_COOKIES_FROMBROWSER_CONTAINER | The container name (if firefox) top load the cookies from | `` | |
| YTDL_COOKIES_FROMBROWSER_BROWSER | The name of the browser to load cookies from. (if specified, it disables YTDL_COOKIES_FILEPATH) | ` ` | `brave`, `chrome`, `chromium`, `edge`, `firefox`, `opera`, `safari`, `vivaldi` |
| YTDL_COOKIES_FROMBROWSER_KEYRING | The name of the keyring for decrypting cookies for the chromium browser on linux | ` ` | `basictext`, `gnomekeyring`, `kwallet` |
| YTDL_COOKIES_FROMBROWSER_PROFILE | The browser profile to load cookies from | ` ` | |
| YTDL_COOKIES_FROMBROWSER_CONTAINER | The container name (if firefox) top load the cookies from | ` ` | |
## Building from source

View File

@ -1,9 +1,11 @@
package config
import (
"os"
"strings"
"time"
"github.com/adrg/xdg"
"github.com/spf13/viper"
)
@ -88,10 +90,22 @@ func LoadConfig(paths ...string) (*Config, error) {
v.AddConfigPath(path)
}
} else {
envDir := os.Getenv("YTDL_CONFIGDIR")
if envDir != "" {
v.AddConfigPath(envDir)
}
v.AddConfigPath(".")
v.AddConfigPath("/etc/ytdl-web")
v.AddConfigPath("$HOME/.config/ytdl-web")
v.AddConfigPath("$XDG_CONFIG_HOME/ytdl-web")
homeDir, err := os.UserHomeDir()
if err == nil {
v.AddConfigPath(homeDir + "/.config/ytdl-web")
}
v.AddConfigPath(xdg.ConfigHome + "/ytdl-web")
for _, dir := range xdg.ConfigDirs {
v.AddConfigPath(dir + "/ytdl-web")
}
}
if err := v.ReadInConfig(); err != nil {

1
go.mod
View File

@ -3,6 +3,7 @@ module go.fifitido.net/ytdl-web
go 1.20
require (
github.com/adrg/xdg v0.4.0
github.com/dgraph-io/badger/v2 v2.2007.4
github.com/gofiber/fiber/v2 v2.44.0
github.com/gofiber/template v1.8.0

3
go.sum
View File

@ -55,6 +55,8 @@ github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKz
github.com/Joker/jade v1.1.3/go.mod h1:T+2WLyt7VH6Lp0TRxQrUYEs64nRc83wkMQrfeIQKduM=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
@ -657,6 +659,7 @@ golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=