-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Randomly slow youtube download speed #964
Comments
I've experienced this with other ytdl libraries as well, such as the one linked above. |
Been looking at this. What I have found is that when there is a slow download, and I cancel downloading and restart some seconds later it then downloads at full steam. So what is needed is some kind of download speed threshold below which the download is cancelled and after a short pause restarted. But it also needs a counter, so that the number of restarts is limited to prevent an infinite restart loop. In the thread https://github.com/ytdl-org/youtube-dl/issues/29326 there is the suggestion of manipulation of the n parameter, but if you look at the Dea function it is extremely obfuscated, much more so than the decipher methods. I would think you would have to execute the original code in base.js directly for this to be a solution. Edit: Not easy to test. I used a threshold of 100KB/s. The problem seems to be completely random. Restarting immediately will result in another slow download. For most cases a 20-30 second delay before restarting the download seems to work. But I had one instance where it took over a minute before it would download at full speed. Still testing... |
I’ve encountered the same issue as well in my development of youtube-archiver. I initially thought that the issue was isolated to a codec, and I eliminated the one problem child, but then I saw it randomly happened to any of them. My best guess is it may be something on YouTube’s end, perhaps it finds something fishy with the request to googlevideo and ratelimits it to prevent a bot attack. The best mitigation for now it seems is to monitor the readable stream. If the completion rate is too slow, cancel the download and restart it. |
[EDIT] This solution is no longer valid This was giving me a lot of headaches a while ago. I found a way to mitigate it doe, not the most elegant way but it works fine for me. However, if you're on a slow internet connection you might end up in an infinite loop, so I suggest you to play around with the code a bit. const downloadVideo = (link) => {
const output_video = './temp/video.mp4';
return new Promise(function (resolve, reject) {
const start = () => {
const stream = ytdl(link, {
filter: (format) => format.container === "mp4",
requestOptions: {
headers: {
cookie: YT_COOKIE
},
},
});
stream.pipe(fs.createWriteStream(output_video));
stream.once("response", () => {
starttime = Date.now();
});
stream.on("progress", (chunkLength, downloaded, total) => {
const percent = downloaded / total;
const downloaded_minutes = (Date.now() - starttime) / 1000 / 60;
const estimated_download_time = downloaded_minutes / percent - downloaded_minutes;
// if the estimated download time is more than 1.5 minutes then we cancel and restart the download, this value works fine for me but you may need to change it based on your server/internet speed.
if (estimated_download_time.toFixed(2) >= 1.5) {
console.warn("Seems like YouTube is limiting our download speed, restarting the download to mitigate the problem..");
stream.destroy();
start();
}
});
stream.on("end", () => {
resolve(output_video);
});
stream.on("error", (error) => {
reject(error);
});
};
start();
});
}; |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
To overcome this throttling problem, ytdl-core may have to run the n transform function in the base.js player code. I do this in my innertube library and do not experience any throttled downloads. The n transform is a lot more complex than the signature decipher function. I've seen other libraries try to emulate the n transform but it differs substantially from yt player to yt player, so this approach is very cumbersome and not very reliable. Another successful approach I have seen is to emulate an android phone, where this throttling is apparently not being applied (perhaps a reward for using Google's OS). |
Hey there. Is there a chance of getting an update to this issue? I've been noticing this a lot more recently and seems to happen with most videos I try. I may try to make a patch myself if I have time however I imagine my progress would end up being slow compared to someone else who is more familiar with the issue / code base. |
I have also developed an Innertube based library, and your implementation helped me a lot while working on it, thanks! Plus I can confirm that yes, transforming the n value fixes the throttling problem. |
This seems to be the approach currently working on yt-dlp:
|
Both yt-dlp and youtube-dl are constantly slow last several days. |
My understanding is that the yt-dlp android workaround only works on videos that can be embedded. It also requires a move to using the innertube api for getInfo. |
Running into the same problem :( consistent 50-60 kbps download speeds, even after setting a higher rate via the -r flag. |
This problem used to be random, but now seems to be on every video I try without solving the n-transform challenge. I have made a PR. Hope it can be accepted. The alternative to running the Google code directly is to attempt to emulate the n-parameter challenge code. But it is hugely more complex than the decipher code and way above my ability. Looking around at other YT projects, those emulation attempts have generally worked for a few days and then failed with newer player versions. Projects that are working around the problem are using the ANDROID fix, but then they are having to jump through some hoops to overcome the limitations of the ANDROID fix. And it seems almost inevitable to me that Google will close this bypass soon. |
Yup, Edit: |
Same here... Download speeds from youtube consistently at about 40 kb/s. :( |
Here too. Would love a fix. |
YouTube/Google has made a change to make youtube-dl downloading incrediby slow, the only fix is the fork known as yt-dlp but that doesn't have a node version yet. |
yt-dlp has no such issue |
same problem. Using youtube-dl with smtTube, cant watch any video in realtime |
Yup I have the same issue, the download speed never exceeds 82kB/s which is very problematic |
#964 (comment) You need to use yt-dlp now. |
yt-dlp affected too. :-( |
This is likely caused by an update to YouTube's API if it's affecting multiple interpretations of this. |
After updating yt-dlp to version 2021.10.10 my downloads processed very quickly. |
That means you are running an outdated yt-dlp, the latest yt-dlp has this issue fixed. |
|
Hello. |
That's because IDM has multithreaded downloads, so downloading 10 segments simultaneously = 10x70 KB/s =700 KB/s. The innertube library ytcog and CLI ytcog-dl are unthrottled using the same n-parameter solution as proposed in PR #1022. Might help some people while they wait for a fix. |
I'm interested in what makes yt-dlp work, while we wait. It's a long shot but could it be that YouTube has multiple ways of delivery and our format choices correspond with a way they don't prefer? Like what if the speeds we get are because of connecting to an obscure origin datacenter and for files they turned off the CDN for. When visiting the website it's fast not because of multiple threads but because of a different format maybe. I'm guessing but maybe while youtube-dl prefers the separate video and audio file way/format, perhaps YT switched to m3u8 segmenting but the previous is still available just not "near you" on a CDN? |
I have noticed yesterday that it went from 50 kB/s to a around 8MB/s for a fragment of time. However it was kinda broken because everytime it was going fast, it seems like youtube-dl was crashing Is this can help you understand what is going on or not? PS : I have noticed that it was happening 2 weeks ago, before the "limitation" of 50kB/s was set |
Want to use/test this fix immediately before it is merged into a release? Run this to install the PR that addresses this issue: npm i fent/node-ytdl-core#pull/1022/head
rm -rf node_modules && npm i |
Same in Karlsruhe (Germany) between 50-80 KiB/s though 100MiB stable connection. |
Same in my United States server. between 50-80 KiB/s though 2000MiB stable connection. |
same here , it stucks at 40-50KiB/s with 1000+MiB super stable connection. |
now version 4.10.0 too slow |
Same for me since yesterday evening (Austria (Main IP) / Germany (ISP Proxies) / Netherlands (ISP Proxies)) |
This is a new but small obstacle from YouTube in their base player files. PR #1055 |
yep, fixed with #1055 |
Hello,
Important: The problem is random, maybe 1 chance on 8 to produce it. You have to download several videos in a row (about 10) to notice it.
Since a few weeks, randomly a youtube video can be slowed down to 48 Kio/s, so it takes 5-10 minutes to download a short video of 5 minutes instead of 4, 5 seconds, often the download does not succeed and stops after a few minutes.
This happens on several servers, several internet providers as well as with my private connection.
base on this: ytdl-org/youtube-dl#29326
The text was updated successfully, but these errors were encountered: