Youtubeexplode: Is there any way to stream the file while downloading it?

Created on 29 Jan 2019  路  10Comments  路  Source: Tyrrrz/YoutubeExplode

Is there a way to stream the file while downloading it? For example I download a chunk of file and I stream it back via api

question

Most helpful comment

You will need a background worker for that, most likely entirely separate from your web service

All 10 comments

Asp.net example:
https://github.com/SlowLogicBoy/YoutubeExplode.AspNetCore.Mvc
This line:
https://github.com/SlowLogicBoy/YoutubeExplode.AspNetCore.Mvc/blob/master/Controllers/YoutubeController.cs#L20

It get's a stream from youtube and passes that to File() method.

FFMpeg example:
https://gist.github.com/SlowLogicBoy/63037d655cf8c667ae09ccebcf1164aa

This get's video and audio streams and combines them into a single video with audio.
FFMpeg get's bytes ether as soon as it requests or as soon as we get bytes from youtube.

Basically if you get a stream using GetMediaStreamAsync you can do whatever you want with it

Asp.net example:
https://github.com/SlowLogicBoy/YoutubeExplode.AspNetCore.Mvc
This line:
https://github.com/SlowLogicBoy/YoutubeExplode.AspNetCore.Mvc/blob/master/Controllers/YoutubeController.cs#L20

It get's a stream from youtube and passes that to File() method.

FFMpeg example:
https://gist.github.com/SlowLogicBoy/63037d655cf8c667ae09ccebcf1164aa

This get's video and audio streams and combines them into a single video with audio.
FFMpeg get's bytes ether as soon as it requests or as soon as we get bytes from youtube.

Shouldnt that controller return the file once it gets fully downloaded? To be more clear i wanted to download it but while downloading it i want to stream it piece by piece!

It does not download whole file before sending, it sends that file as it get's downloaded or downloads as much as it needs to send (depends if sending is slower then download or sending was canceled).

Asp.net example:
https://github.com/SlowLogicBoy/YoutubeExplode.AspNetCore.Mvc
This line:
https://github.com/SlowLogicBoy/YoutubeExplode.AspNetCore.Mvc/blob/master/Controllers/YoutubeController.cs#L20
It get's a stream from youtube and passes that to File() method.
FFMpeg example:
https://gist.github.com/SlowLogicBoy/63037d655cf8c667ae09ccebcf1164aa
This get's video and audio streams and combines them into a single video with audio.
FFMpeg get's bytes ether as soon as it requests or as soon as we get bytes from youtube.

Shouldnt that controller return the file once it gets fully downloaded? To be more clear i wanted to download it but while downloading it i want to stream it piece by piece!

Ah ok i thought he was awaiting for the whole file but that was the stream. Another thing if i can ask since i already opened that ticket.. Is there a way to still wait the full downloaded file even tho the user already quitted the request? For example somebody join the stream by id, it gets back the stream and while streaming i save the file on download complete (a king of cache)? But the problem is if the user leaves in theory when if the user quit the api before everything is saved the thread will be aborted.
Thanks :D

You will need a background worker for that, most likely entirely separate from your web service

You will need a background worker for that, most likely entirely separate from your web service

Thanks again for the answer, i never have worked with streams etc.. Do the download from stream i send back to the client gets executed in my backend or from the client? I explain why, i have already something like a background worker but now i was thinking about a problem.. The bg worker can download the file from the stream and cache it, do the returned stream to the client download again the same file on my backend? i want somehow to share the same downloaded file

Depends on how you did it.

Depends on how you did it.

Can you explain better?

the return File(await ...stream) from the example of SlowLogicBoy the file is download by chunk from my backend and sent to the client or the file is downloaded from the client?

It's downloaded by the server then sent to client where it's downloaded by the client, all in chunks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ac-lap picture ac-lap  路  7Comments

vsjtechnologies picture vsjtechnologies  路  7Comments

jvitoroc picture jvitoroc  路  8Comments

spoikbr picture spoikbr  路  5Comments

SlowLogicBoy picture SlowLogicBoy  路  7Comments