Skip to content

Commit 388c2a1

Browse files
committed
Add yt-dlp cookies configuration and update documentation (#63)
- Introduced YTDLP_COOKIES_PATH in .env.example, docker-compose files, and config.ts for specifying a cookies file path. - Updated README.md with instructions on using cookies for yt-dlp to access private or premium content. - Enhanced config command to display and modify the ytdlpCookiesPath parameter. - Modified yt-dlp utility to utilize the specified cookies file if provided.
1 parent 86dc6a0 commit 388c2a1

File tree

7 files changed

+51
-0
lines changed

7 files changed

+51
-0
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ ADMIN_IDS = ["YOUR_USER_ID_HERE"] # A list of Discord user IDs that are consider
1010
VIDEOS_DIR = "./videos" # The local path where you store video files
1111
PREVIEW_CACHE_DIR = "./tmp/preview-cache" # The local path where your self-bot will cache video preview thumbnails
1212

13+
# yt-dlp options
14+
YTDLP_COOKIES_PATH = "" # Path to cookies file for yt-dlp (Netscape format). Used for accessing age-restricted, private, or premium content. Leave empty if not needed.
15+
1316
# Stream options
1417
STREAM_RESPECT_VIDEO_PARAMS = "false" # This option is used to respect video parameters such as width, height, fps, bitrate, and max bitrate.
1518
STREAM_WIDTH = "1280" # The width of the video stream in pixels

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ ADMIN_IDS = ["YOUR_USER_ID_HERE"] # A list of Discord user IDs that are consider
143143
VIDEOS_DIR = "./videos" # The local path where you store video files
144144
PREVIEW_CACHE_DIR = "./tmp/preview-cache" # The local path where your self-bot will cache video preview thumbnails
145145

146+
# yt-dlp options
147+
YTDLP_COOKIES_PATH = "" # Path to cookies file for yt-dlp (for accessing age-restricted or premium content)
148+
146149
# Stream options
147150
STREAM_RESPECT_VIDEO_PARAMS = "false" # Respect original video parameters (width, height, fps, bitrate)
148151
STREAM_WIDTH = "1280" # The width of the video stream in pixels
@@ -164,6 +167,30 @@ SERVER_PASSWORD = "admin" # Password for the web interface (bcrypt hash is suppo
164167
SERVER_PORT = "8080" # Port number for the web server
165168
```
166169

170+
### Using Cookies with yt-dlp
171+
172+
To access private, or premium content (like YouTube Premium videos), you can provide a cookies file to yt-dlp:
173+
174+
1. **Export cookies from your browser** using a browser extension like:
175+
- [Get cookies.txt LOCALLY](https://chrome.google.com/webstore/detail/get-cookiestxt-locally/cclelndahbckbenkjhflpdbgdldlbecc) (Chromium based browsers)
176+
- [cookies.txt](https://addons.mozilla.org/en-US/firefox/addon/cookies-txt/) (Firefox based browsers)
177+
178+
2. **Save the cookies file** (usually named `cookies.txt`) to a location accessible by the bot
179+
180+
3. **Configure the path** in one of two ways:
181+
- Set `YTDLP_COOKIES_PATH` in your `.env` file:
182+
```bash
183+
YTDLP_COOKIES_PATH = "./cookies.txt"
184+
```
185+
- Or use the config command while the bot is running:
186+
```
187+
$config ytdlpCookiesPath ./cookies.txt
188+
```
189+
190+
4. **Restart the bot** if you updated the `.env` file
191+
192+
The cookies will be automatically used for all yt-dlp operations, allowing access to restricted content.
193+
167194
## Get Token ?
168195
Check the [Get token wiki](https://github.com/ysdragon/StreamBot/wiki/Get-Discord-user-token)
169196

docker-compose-warp.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ services:
1515
VIDEOS_DIR: "./videos" # The local path where you store video files
1616
PREVIEW_CACHE_DIR: "./tmp/preview-cache" # The local path where your self-bot will cache video preview thumbnails
1717

18+
# yt-dlp options
19+
YTDLP_COOKIES_PATH: "" # Path to cookies file for yt-dlp (for accessing age-restricted or premium content)
20+
1821
# Stream options
1922
STREAM_RESPECT_VIDEO_PARAMS: "false" # This option is used to respect video parameters such as width, height, fps, bitrate, and max bitrate.
2023
STREAM_WIDTH: "1280" # The width of the video stream in pixels

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ services:
1515
VIDEOS_DIR: "./videos" # The local path where you store video files
1616
PREVIEW_CACHE_DIR: "./tmp/preview-cache" # The local path where your self-bot will cache video preview thumbnails
1717

18+
# yt-dlp options
19+
YTDLP_COOKIES_PATH: "" # Path to cookies file for yt-dlp (for accessing age-restricted or premium content)
20+
1821
# Stream options
1922
STREAM_RESPECT_VIDEO_PARAMS: "false" # This option is used to respect video parameters such as width, height, fps, bitrate, and max bitrate.
2023
STREAM_WIDTH: "1280" # The width of the video stream in pixels

src/commands/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ export default class ConfigCommand extends BaseCommand {
5454
`• videosDir: ${config.videosDir}`,
5555
`• previewCacheDir: ${config.previewCacheDir}`,
5656
"",
57+
"**yt-dlp Options:**",
58+
`• ytdlpCookiesPath: ${config.ytdlpCookiesPath || '(not set)'}`,
59+
"",
5760
"Use `config <parameter>` to view a specific parameter",
5861
"Use `config <parameter> <value>` to change a parameter"
5962
].join('\n');
@@ -137,6 +140,7 @@ export default class ConfigCommand extends BaseCommand {
137140
// String parameters
138141
case 'videosDir':
139142
case 'previewCacheDir':
143+
case 'ytdlpCookiesPath':
140144
(config as any)[key] = value;
141145
await this.sendSuccess(context.message, `Set ${key} to \`${value}\``);
142146
logger.info(`Config updated: ${key} = ${value}`);

src/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ export default {
7777
videosDir: process.env.VIDEOS_DIR ? process.env.VIDEOS_DIR : './videos',
7878
previewCacheDir: process.env.PREVIEW_CACHE_DIR ? process.env.PREVIEW_CACHE_DIR : './tmp/preview-cache',
7979

80+
// yt-dlp options
81+
ytdlpCookiesPath: process.env.YTDLP_COOKIES_PATH ? process.env.YTDLP_COOKIES_PATH : '',
82+
8083
// Stream options
8184
respect_video_params: process.env.STREAM_RESPECT_VIDEO_PARAMS ? parseBoolean(process.env.STREAM_RESPECT_VIDEO_PARAMS) : false,
8285
width: process.env.STREAM_WIDTH ? parseInt(process.env.STREAM_WIDTH) : 1280,

src/utils/yt-dlp.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import crypto from "node:crypto";
66
import got from "got";
77
import { YTFlags } from "../types/index.js";
88
import logger from "./logger.js";
9+
import config from "../config.js";
910
import { spawn } from "node:child_process";
1011

1112
let determinedFilename: string;
@@ -43,6 +44,13 @@ const exePath = nodePath.resolve(scriptsPath, filename);
4344

4445
function args(url: string, options: Partial<YTFlags>): string[] {
4546
const optArgs: string[] = [];
47+
48+
// Add cookies file if configured
49+
if (config.ytdlpCookiesPath && existsSync(config.ytdlpCookiesPath)) {
50+
optArgs.push('--cookies');
51+
optArgs.push(config.ytdlpCookiesPath);
52+
}
53+
4654
for (const [key, val] of Object.entries(options)) {
4755
if (val === null || val === undefined) {
4856
continue;

0 commit comments

Comments
 (0)