Skip to content

Commit 318ed28

Browse files
1Git2Cloneclaude
andcommitted
fix(commands,deploy): use node + ejs:github for YouTube n-challenge; set cookies env
yt-dlp now requires an explicit JS runtime (--js-runtimes node) and the EJS challenge solver script (--remote-components ejs:github) to decode YouTube streaming URLs. Without these, all formats are dropped. Also add YT_DLP_COOKIES_PATH to supervisor env — it was never set so the bot was running every download unauthenticated. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5bc58f8 commit 318ed28

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

deploy/supervisor/serenity-bot.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[program:serenity-bot-a-blue]
1616
command=/home/hutao/serenity-discord-bot/target/release/serenity-discord-bot
1717
directory=/home/hutao/serenity-discord-bot
18-
environment=RUST_LOG="warn,serenity_discord_bot=info",TOTAL_SHARDS="16",SHARD_START="0",SHARD_END="7",PATH="/home/%(ENV_USER)s/.deno/bin:/home/%(ENV_USER)s/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
18+
environment=RUST_LOG="warn,serenity_discord_bot=info",TOTAL_SHARDS="16",SHARD_START="0",SHARD_END="7",PATH="/home/%(ENV_USER)s/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",YT_DLP_COOKIES_PATH="/home/%(ENV_USER)s/serenity-discord-bot/cookies.txt"
1919
autostart=true
2020
autorestart=true
2121
stdout_logfile=/var/log/serenity-bot/a-blue-stdout.log
@@ -28,7 +28,7 @@ stderr_logfile_backups=3
2828
[program:serenity-bot-a-green]
2929
command=/home/hutao/serenity-discord-bot/target/release/serenity-discord-bot
3030
directory=/home/hutao/serenity-discord-bot
31-
environment=RUST_LOG="warn,serenity_discord_bot=info",TOTAL_SHARDS="16",SHARD_START="0",SHARD_END="7",PATH="/home/%(ENV_USER)s/.deno/bin:/home/%(ENV_USER)s/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
31+
environment=RUST_LOG="warn,serenity_discord_bot=info",TOTAL_SHARDS="16",SHARD_START="0",SHARD_END="7",PATH="/home/%(ENV_USER)s/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",YT_DLP_COOKIES_PATH="/home/%(ENV_USER)s/serenity-discord-bot/cookies.txt"
3232
autostart=false
3333
autorestart=true
3434
stdout_logfile=/var/log/serenity-bot/a-green-stdout.log
@@ -41,7 +41,7 @@ stderr_logfile_backups=3
4141
[program:serenity-bot-b-blue]
4242
command=/home/hutao/serenity-discord-bot/target/release/serenity-discord-bot
4343
directory=/home/hutao/serenity-discord-bot
44-
environment=RUST_LOG="warn,serenity_discord_bot=info",TOTAL_SHARDS="16",SHARD_START="8",SHARD_END="15",PATH="/home/%(ENV_USER)s/.deno/bin:/home/%(ENV_USER)s/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
44+
environment=RUST_LOG="warn,serenity_discord_bot=info",TOTAL_SHARDS="16",SHARD_START="8",SHARD_END="15",PATH="/home/%(ENV_USER)s/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",YT_DLP_COOKIES_PATH="/home/%(ENV_USER)s/serenity-discord-bot/cookies.txt"
4545
autostart=true
4646
autorestart=true
4747
stdout_logfile=/var/log/serenity-bot/b-blue-stdout.log
@@ -54,7 +54,7 @@ stderr_logfile_backups=3
5454
[program:serenity-bot-b-green]
5555
command=/home/hutao/serenity-discord-bot/target/release/serenity-discord-bot
5656
directory=/home/hutao/serenity-discord-bot
57-
environment=RUST_LOG="warn,serenity_discord_bot=info",TOTAL_SHARDS="16",SHARD_START="8",SHARD_END="15",PATH="/home/%(ENV_USER)s/.deno/bin:/home/%(ENV_USER)s/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
57+
environment=RUST_LOG="warn,serenity_discord_bot=info",TOTAL_SHARDS="16",SHARD_START="8",SHARD_END="15",PATH="/home/%(ENV_USER)s/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",YT_DLP_COOKIES_PATH="/home/%(ENV_USER)s/serenity-discord-bot/cookies.txt"
5858
autostart=false
5959
autorestart=true
6060
stdout_logfile=/var/log/serenity-bot/b-green-stdout.log

src/commands/util/download.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,17 +302,6 @@ pub async fn download(
302302
ctx.say("Downloading media...").await?;
303303

304304
let mut cmd = Command::new("yt-dlp");
305-
306-
// Supervisor strips most of HOME-relative PATH entries. Prepend common
307-
// JS runtime locations so yt-dlp can solve YouTube's n-challenge.
308-
if let Ok(home) = std::env::var("HOME") {
309-
let current = std::env::var("PATH").unwrap_or_default();
310-
cmd.env(
311-
"PATH",
312-
format!("{home}/.deno/bin:{home}/.local/bin:/usr/local/bin:/usr/bin:/bin:{current}"),
313-
);
314-
}
315-
316305
cmd.arg("--no-playlist")
317306
// `--print` alone implies `--simulate` (nothing downloads), and the
318307
// bare `filename` field is the pre-merge name. `--no-simulate` plus
@@ -321,6 +310,10 @@ pub async fn download(
321310
// Prefer mp4/m4a but fall back to whatever's available.
322311
.args(["-S", "+ext:mp4:m4a"])
323312
.args(["--merge-output-format", "mp4"])
313+
// Use node for JS challenge solving (n-challenge + signature).
314+
// ejs:github fetches the required solver script on first use.
315+
.args(["--js-runtimes", "node"])
316+
.args(["--remote-components", "ejs:github"])
324317
.args(["--print", "after_move:filepath"])
325318
.arg("--output")
326319
.arg(source_template.to_string_lossy().to_string());

0 commit comments

Comments
 (0)