Thanks,
Get's get back to our original code.
Since we enable users for partial content download, so there are some possiblities that we to consider. Like for example, they (user/client) could use the link as video source in some video player. and then they click somewhere in between of video, which will lead to browser requesting the content from certain bytes range. Let's say browser is requesting contect from 1248576th byte, So our server should able to serve that, but sadly stream_media only allows getting partial content from telegram in chunks. So in our example, browser wants 1248576th byte, so it byte must exist & start from 2nd chunk (since each chuck is 1024*1024 bytes or 1 megabytes).
First and foremost, we can find total number of chunks by first of all getting file size by message.video.file_size then divide that file size by 1024*1024, then do ceil round off, means if number is 104.24 or 104.88 or 104.01 then total chunks are 105!
So you need to code some logic here, First check request range, then think of way on how we can locate chunk (in our example, byte exist in 2nd chunk, we can get starting chunk number by dividing starting byte range by 1024*1024, like 1248576 / (1024 x 1024) is 1.190 so offset is 1) where starting byte exists, once offset caluculation is done, now we will locate last chunk where ending byte exists. Let's say ending byte is 4194400th byte, so it exists in 4th chunk. now we will do calcutions and we should get limit 3...so that our stream_media will yeild 2nd, 3rd and 4th chunk!
Now here's the important part, here in these three chunks, first and last chunk cannot be served directly because browser requested range's starting byte exists somwhere inside first chunk (here it's 2nd chunk). Since browser requested 1248576th byte which resides inside first chunk (2nd chunk), what we will do is that first we will divide byte number by 10241024 the we convert resulting floating number into integer, like 2.03 or 2.94 will become integer 2. then we will subtract byte number by (10241024*resulting integer number here). Now, we will get a number which is starting byte number to start from inside first chunk (2nd byte). In our example, this starting number is 200000, so we will read chunk from 200000 byte to end of the current (i.e. 2nd chunk or first chunk) and then server that procceded chunk.
Now we will move to chunks between first and last chunk if any, (in our example, it's chunks between 2nd and 4th chunk), we will serve these chunks as it is. means, just serve yielded chunk from stream_media directly.
Now once all in-between chunk are served. we will come to last chunk, where we will do same process as we did for first chunk but in this time we will try to find last byte we need to serve which resides somewhere inside last chunk, so apply similar calculation tactics and get resulting last byte number and then read this chunk from 0 or starting, till resulting last byte number, in our example, resulting last byte number is 96, so we will read last yielded chunk from byte 0 to byte 96 then serve it.