Skip to content

Commit ba0d638

Browse files
committed
add support for passing cookies
1 parent e387b1c commit ba0d638

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ services:
88
- /path/to/musiclibrary/explo:/data/ # has to be in the same path you have your music system pointed to (it's recommended to put explo under a subfolder)
99
# - /path/to/slskd/downloads:/slskd/ # if using slskd and MIGRATE_DOWNLOADS is set to true in .env
1010
# - $PLAYLIST_DIR:$PLAYLIST_DIR # for MPD. Both paths should be as defined in .env (e.g /my/playlists/:/my/playlists/)
11+
12+
# - /path/to/cookies.txt:/opt/explo/cookies.txt # Path to optional cookies file (for yt-dlp)
1113
environment:
1214
- TZ=UTC # Change this to the timezone set in ListenBrainz (default is UTC)
1315

sample.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ YOUTUBE_API_KEY=
4545
# FFMPEG_PATH=
4646
# Custom path to yt-dlp binary (default: defined in $PATH)
4747
# YTDLP_PATH=
48+
# Path to (optional) cookies file (default ./cookies.txt)
49+
# COOKIES_PATH=./cookies.txt
4850
# Comma-separated (without spaces) keywords to exclude from YouTube results (default: live,remix,instrumental,extended,clean,acapella)
4951
# FILTER_LIST=live,remix,instrumental,extended
5052

src/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type Youtube struct {
8787
APIKey string `env:"YOUTUBE_API_KEY"`
8888
FfmpegPath string `env:"FFMPEG_PATH"`
8989
YtdlpPath string `env:"YTDLP_PATH"`
90+
CookiesPath string `env:"COOKIES_PATH" env-default:"./cookies.txt"`
9091
Filters Filters
9192
}
9293

src/downloader/youtube.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,16 @@ func getTopic(cfg cfg.Youtube, videos Videos, track models.Track) string { // ge
144144
}
145145

146146
func getVideo(ctx context.Context, c Youtube, videoID string) (*goutubedl.DownloadResult, error) { // gets video stream using yt-dlp
147-
148147
if c.Cfg.YtdlpPath != "" {
149148
goutubedl.Path = c.Cfg.YtdlpPath
150149
}
151150

152-
result, err := goutubedl.New(ctx, videoID, goutubedl.Options{})
151+
var opts goutubedl.Options
152+
if _, err := os.Stat(c.Cfg.CookiesPath); err == nil {
153+
opts.Cookies = c.Cfg.CookiesPath
154+
}
155+
156+
result, err := goutubedl.New(ctx, videoID, opts)
153157
if err != nil {
154158
return nil, fmt.Errorf("could not create URL for video download (ID: %s): %s", videoID, err.Error())
155159
}

0 commit comments

Comments
 (0)