How to ignore YouTube's bandwidth limit and download movies at high speed?



If you try to download a movie from YouTube without using a download tool such as ``

youtube-dl '' or `` yt-dlp '', a strong bandwidth limit will be triggered and it will take about 6 and a half hours to download a 10-minute movie. It will take. Hacker Vedado explains how the download tool breaks through these restrictions.

How They Bypass YouTube Video Download Throttling | 0x7D0
https://blog.0x7d0.dev/history/how-they-bypass-youtube-video-download-throttling/


The first step in downloading a movie is finding the actual URL to access the movie. In this step, it is OK to access '/youtubei/v1/player' which is the endpoint of YouTube API. You can get the URL for each resolution of the movie in addition to the title, detailed description, thumbnail.



However, if you try to download the movie using the URL obtained here, the transfer speed will be suppressed to 40 kB / s to 70 kB / s as shown in the figure below, and it will take about 6 hours to download the 10 minute movie. It takes half as long. When watching on the web, it is clear that there are some restrictions, as you will not have to wait 6 and a half hours to watch a 10-minute movie.



According to Mr. Vedado, there is a parameter 'n' in the parameters of the URL of the movie, and YouTube uses this 'n' to distinguish whether it is an official client. For the official client, 'n' is converted according to a specific algorithm, and the new 'n' is set as a parameter to download. If 'n' is wrong, bandwidth limit will be triggered.



The transformation algorithm for 'n' is obfuscated and changes frequently, making it impractical to attempt to decipher it. However, due to the specifications of JavaScript that runs on the client side, the algorithm code itself can be accessed by anyone. Therefore, many download libraries use a solution that downloads YouTube's JavaScript, extracts the entire algorithm code, and converts 'n'.

By removing the bandwidth limit in this way, it is now possible to download movies at a speed of 4 MB / s. However, Mr. Vedado says that a second bandwidth limit is being done here. Since YouTube is a streaming platform, it will automatically limit the bandwidth when the speed is sufficient for streaming. As a guideline, it is adjusted so that the download is completed in half the time of the entire movie.



Since the second bandwidth limit occurs after a while after the download starts, it is OK if you divide the download finely using the HTTP header `` Range '' and always make a new connection. For example, if you change the script to download 10MB at a time, you can download at a speed of 60MB/s to 80MB/s as shown in the figure below.



YouTube movies are saved as separate files for video and audio, so after downloading both, use an editing tool such as ffmpeg to integrate them into one file, and the download is complete. The download script created by Mr. Vedado this time is published on Mr. Vedado's blog , so please check it if you are interested.

in Software,   Web Service, Posted by log1d_ts