diff --git a/Dockerfile b/Dockerfile index 2aa6fd3..5cbdd98 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ RUN wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /us chmod 755 /usr/local/bin/yt-dlp RUN apk update && apk upgrade && apk add --no-cache ffmpeg COPY --from=builder /app/yt-dlp-telegram-bot /app/yt-dlp-telegram-bot +COPY --from=builder /app/yt-dlp.conf /root/yt-dlp.conf ENTRYPOINT ["/app/yt-dlp-telegram-bot"] -ENV API_ID= API_HASH= BOT_TOKEN= ALLOWED_USERIDS= ADMIN_USERIDS= ALLOWED_GROUPIDS= +ENV API_ID= API_HASH= BOT_TOKEN= ALLOWED_USERIDS= ADMIN_USERIDS= ALLOWED_GROUPIDS= YTDLP_COOKIES= diff --git a/README.md b/README.md index 590c3fc..eeafbd5 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,12 @@ variable. Available OS environment variables are: - `ALLOWED_USERIDS` - `ADMIN_USERIDS` - `ALLOWED_GROUPIDS` +- `YTDLP_COOKIES` + +The contents of the `YTDLP_COOKIES` environment variable will be written to the +file `/tmp/ytdlp-cookies.txt`. This will be used by `yt-dlp` if it is running +in a docker container, as the `yt-dlp.conf` file in the container points to this +cookie file. ## Supported commands diff --git a/params.go b/params.go index f18476c..c67e8e0 100644 --- a/params.go +++ b/params.go @@ -127,5 +127,19 @@ func (p *paramsType) Init() error { p.AllowedGroupIDs = append(p.AllowedUserIDs, id) } + // Writing env. var YTDLP_COOKIES contents to a file. + // In case a docker container is used, the yt-dlp.conf points yt-dlp to this cookie file. + if cookies := os.Getenv("YTDLP_COOKIES"); cookies != "" { + f, err := os.Create("/tmp/ytdlp-cookies.txt") + if err != nil { + return fmt.Errorf("couldn't create cookies file: %w", err) + } + _, err = f.WriteString(cookies) + if err != nil { + return fmt.Errorf("couldn't write cookies file: %w", err) + } + f.Close() + } + return nil } diff --git a/yt-dlp.conf b/yt-dlp.conf new file mode 100644 index 0000000..70252c1 --- /dev/null +++ b/yt-dlp.conf @@ -0,0 +1 @@ +--cookies=/tmp/ytdlp-cookies.txt