If you download YouTube videos, there’s a real chance you’re using yt-dlp, the long-running and widely-used command-line program for downloading YouTube videos. Even if you’re not using it directly, many other tools for downloading YouTube videos are built on top of yt-dlp, and even some media players which offer YouTube playback use it in the background. Now, yt-dlp has always had a built-in basic JavaScript “interpreter”, but due to changes at YouTube, yt-dlp will soon require a proper JavaScript runtime in order to function.
Up until now, yt-dlp has been able to use its built-in JavaScript “interpreter” to solve the JavaScript challenges that are required for YouTube downloads. But due to recent changes on YouTube’s end, the built-in JS interpreter will soon be insufficient for this purpose. The changes are so drastic that yt-dlp will need to leverage a proper JavaScript runtime in order to solve the JS challenges.
↫ Yt-dlp’s announcement on GitHub
The yt-dlp team suggests using Deno, but compatibility with some alternatives has been added as well. The issue is that the “interpreter” yt-dlp already includes consists of a massive set of very complex regex patterns to solve JS challenges, and those are difficult to maintain and no longer sufficient, so a real runtime is necessary for YouTube downloads. Deno is advised because it’s entirely self-contained and sandboxed, and has no network or filesystem access of any kind. Deno also happens to be a single, portable executable.
As time progresses, it seems yt-dlp is slowly growing into a web browser just to be able to download YouTube videos. I wonder what kind of barriers YouTube will throw up next, and what possible solutions from yt-dlp might look like.
Thom Holwerda,
The end game is actually quite clear. Google can (and probably eventually will) perform any and all tests to check that a browser exists. Ultimately this will go farther than just testing for javascript, but testing a myriad of browser functions including the DOM, APIs like Canvas, websockets, etc. In theory a program like yt-dlp could try to fake all of these tests, but in the long run it will be easier and more reliable to actually use a real FOSS browse engine than to fake it.
Running a real browser means that yt-dlp will be able to pass the browser tests and there’s not much google can do about that. If you recall google was planning to add web DRM to the browser, this is why. DRM would help certify unmodified browsers and plugins status and block projects like this one from working. Google could conceivably try to bring back web DRM. The problem is that firefox is unlikely to support it and blocking firefox could have bad antitrust ramifications for google. Then again a well placed “bribe” might do the trick both in terms of government regulations as well as getting mozilla to support the DRM.
I bought Video DownloadHelper (premium), best $30 I’ve spent in my life:
https://www.downloadhelper.net/
It captures the video URL as your browser renders the page, so you don’t need to use external command-line utilities, just a convenient button right there in the browser. It’s compatible with both HLS and DASH, and for the case of DASH, it merges the video and audio stream and gives you a nice single mp4 or webm file.
Now back on topic, of course YouTube will use more JavaScript to try and block yt-dlp, considering they charge for the video download feature as part of YouTube Premium. My gripe is with Mozilla for not making something like Video DownloadHelper a part of Firefox, I mean, offering what Chrome doesn’t should be Firefox’s “edge” over Chrome. Then again, Chrome has banned Video DownloadHelper from downloading YouTube videos, so even as things are now Firefox is already offering something Chrome doesn’t, I just wish it was integrated as a first-party feature so more people knew about it.