Joystream / youtube-synch

YouTube Synchronization
11 stars 10 forks source link

Pre-ensure that downloading a file wont exceed the configured/available disk space #196

Open zeeshanakram3 opened 1 year ago

zeeshanakram3 commented 1 year ago

Problem

A few definitions first:

Right now youtube-synch downloads videos in a batch (of 50, which is configurable) for postprocessing, i.e. merging audio/video, calculating hash, etc. And before start downloading the batch it only ensures that some space is available (i.e. spaceUsed < spaceAvailable)

The problem with the above approach is that the size of the prepared batch might actually exceed not only the availableSpace but all the system disk space too, and it could lead to service crash.

Fix

Pre-calculate the size of the batch & only queue it for downloading if the space would not exceed even after all the videos have been downloaded. i.e. (spaceUsed + batchSize <= spaceAvailable)