yt-dlp on Linux VPS works with fresh YouTube cookies, but cookies rotate quickly and video downloads start failing. Any stable solution?
Posted by vazhadval@reddit | programming | View on Reddit | 6 comments
I’m running a small app on a Linux VPS that uses yt-dlp to:
- fetch YouTube transcripts
- download source video
- cut shorts with
ffmpeg
I got most of it working, but I have a recurring problem with YouTube cookies.
Current setup:
- Linux VPS
- yt-dlp
ffmpeg- Node 22
--js-runtimes "node"--remote-components "ejs:github"- cookies exported from my local browser and uploaded to the server as
cookies.txt
What I observed:
- Fresh cookies can work
- Transcript fetching often works more easily than full video download
- Full video download sometimes fails with errors like:
Sign in to confirm you're not a botThe provided YouTube account cookies are no longer valid. They have likely been rotated in the browser as a security measureOnly images are available for downloadRequested format is not available
A manual command like this can work right after I upload fresh cookies:
/usr/local/bin/yt-dlp -v \
--cookies "/root/youtube-cookies.txt" \
--js-runtimes "node" \
--remote-components "ejs:github" \
--list-formats \
"https://www.youtube.com/watch?v=VIDEO_ID"
But after some time, the same cookies stop working and I need to export/upload them again.
I also tried:
- updating Node to v22
- enabling
--remote-components "ejs:github" - using a supported JS runtime
- fresh cookie exports
- testing directly in shell on the server
Question:
- Is there any reliable way to avoid constantly refreshing YouTube cookies on a VPS?
- Is cookie rotation just unavoidable in this setup?
- If cookie rotation is unavoidable is there way to automate it ?
waeeo@reddit
Create a new browser profile/container, log in to YouTube there, and extract and use those cookies for `yt-dlp` only. If you don't use that profile/container to watch YouTube in the browser afterwards, the cookies won't get rotated.
vazhadval@reddit (OP)
so basically, use youtube account's cookies which I do not use ? will try, thanks!
waeeo@reddit
Yes, exactly. I had the same problem with cookie invalidation before, but after switching to cookies from a session that's never used normally, I haven't had to update them in a long time, probably months.
LifeWithoutAds@reddit
I think that the problem is not that the cookies change perse, but having a hosting IP address from which you make the requests triggers an internal system on YouTube server side.
vazhadval@reddit (OP)
yes, this might be reason, is there workaround to this ?
LifeWithoutAds@reddit
Get residential IP addresses.