node-ytdl-core
node-ytdl-core copied to clipboard
How to set a timeout for getInfo request?
Hi, i'm requesting the video info over proxy and some proxies take a lot of time (more than 30s) to finish the request.
Is there a simple way to set the max. time taken for a get info request, so that i can start again with another proxy? I already tried to set "timeout" in the request options but it seems to not have any affect.
Or is there any way to destroy the actual request so that i can set an own timer?
I already googled a lot for setting timeouts for requests over proxy but haven't found a working solution. Maybe someown got it already to work?
try setting the timeout in the request object
let stream ytdl(id);
stream.on('request', (req) => {
req.setTimeout(...);
});
this may be an option in ytdl that's added in the future
Hi @fent, i have a seperate microservice for requesting the info and for downloading the video. So i'm not calling ytdl, instead i'm just calling getInfo().. There is no stream returned or?
I'm doing it that way to prevent double info requests if the download process throws an unhandled error or smth else and needed to restart.
Hi @fent, i have a seperate microservice for requesting the info and for downloading the video. So i'm not calling ytdl, instead i'm just calling getInfo().. There is no stream returned or?
hmm, then it's something that could be added to requestOptions. otherwise, you can also add a timeout to an agent. look at https://nodejs.org/api/http.html#http_new_agent_options
I'm doing it that way to prevent double info requests if the download process throws an unhandled error or smth else and needed to restart.
in that case, you can change the internal cache that ytdl uses for caching info. it's at ytdl.cache.info.timeout, default is 1000 for 1 sec. I guess the cache should be documented.
But the internal cache is not written to any database or file or? So if the node process restarts the cache is empty, or did i got it wrong?
Btw. why the info expiration time (that we get from yt) is not the directive for the timeout?
But the internal cache is not written to any database or file or? So if the node process restarts the cache is empty, or did i got it wrong?
right, it's not written to anything, only memory. you can do something like what ytdl does to save the signature cache to a file
https://github.com/fent/node-ytdl/blob/master/bin/ytdl.js#L50-L66
to do items to make this better are
- document all of the caches and ways to modify them
- customizable storage
- maybe as simple as documenting overwriting
setandget - or providing some basic storage classes that can be inherited and overwritten such as
MemoryStore,FileStore. these may already be on npm
- maybe as simple as documenting overwriting
Btw. why the info expiration time (that we get from yt) is not the directive for the timeout?
the format url expiration time?
Forgive me if I'm missing something, but since ytdl.getInfo()'s options extend miniget, which then extends http.request, couldn't you just pass timeout as an option directly?
ytdl.getInfo options does not extend miniget's options
but close & nice spotting
sth like ytdl('<id>', { requestOptions: { timeout: 420 } }); should work