caffco/get-video-duration

Request: be able to pass in multiple urls at a time

Closed this issue · 1 comments

This library is great!
I was just wondering if there was a way to pass in 2, 3, or 55 URLS at a time to speed up the process at all.

getVideoDurationInSeconds is an asynchronous function so you can run it several times before awaiting for the result to run them concurrently.

For instance, if you have an array of URLs, urls, you could do:

const urls = ['someURL', 'anotherURL'];

const promises = urls.map((url) => getVideoDurationInSeconds(url));

Promise.all(urls).then((durations) => {
  // Do something with the durations
  console.log(durations)
});

I guess per #25 you managed to do something similar.

Take into account that spawning too many getVideoDurationInSeconds calls concurrently could be problematic for several reasons:

  • When providing URLs to getVideoDurationInSeconds you are forcing the machine to perform a network request for each URL to get the video. If you perform several network requests against the same server you might be throttled or even blocked and marked as a malicious actor. Chunk calls to getVideoDurationInSeconds to avoid that. Check out p-limit for that.
  • Getting the duration of a video requires spawning ffprobe, which is not a free in terms of CPU and memory resources. Spawning too many ffprobe processes could run the system out of memory or slow it down too much, which could lead to weird errors, too. Again, p-limit can help you with that.

Anyway since it seems that you manage to do this (and this request is not something that should be implemented in the library itself, to keep it simple and composable) I'm closing the issue.