omansak / libvideo

A lightweight .NET library to download YouTube videos.
BSD 2-Clause "Simplified" License
553 stars 163 forks source link

Downloading audio (.webm) only is very slow? #202

Closed StefH closed 3 years ago

StefH commented 3 years ago

I'm using this code:

var youTube = YouTube.Default; // starting point for YouTube actions
var videos = await youTube.GetAllVideosAsync("https://www.youtube.com/watch?v=spVJOzF0EJ0");
var v = videos.ToList();

var audio = v.Where(vi => vi.AdaptiveKind == AdaptiveKind.Audio).OrderByDescending(vi => vi.AudioBitrate).First();

Console.WriteLine(DateTime.Now.ToString("O"));
var bytes = await audio.GetBytesAsync();
Console.WriteLine(DateTime.Now.ToString("O"));

await File.WriteAllBytesAsync("c:\\dev\\" + audio.FullName, bytes);

And downloading a 7 MB audio file takes ~ 50 seconds ?:

2021-04-17T09:56:46.2859815+02:00
2021-04-17T09:57:36.2790347+02:00
omansak commented 3 years ago

try download with chunks.

Chunk : https://stackoverflow.com/questions/13566302/download-large-file-in-small-chunks-in-c-sharp

Sample Project for UWP (u can extract chunk) : https://github.com/omansak/UWP-Download-in-Chunks

nycr0x commented 3 years ago

I'm using this code:

var youTube = YouTube.Default; // starting point for YouTube actions
var videos = await youTube.GetAllVideosAsync("https://www.youtube.com/watch?v=spVJOzF0EJ0");
var v = videos.ToList();

var audio = v.Where(vi => vi.AdaptiveKind == AdaptiveKind.Audio).OrderByDescending(vi => vi.AudioBitrate).First();

Console.WriteLine(DateTime.Now.ToString("O"));
var bytes = await audio.GetBytesAsync();
Console.WriteLine(DateTime.Now.ToString("O"));

await File.WriteAllBytesAsync("c:\\dev\\" + audio.FullName, bytes);

And downloading a 7 MB audio file takes ~ 50 seconds ?:

2021-04-17T09:56:46.2859815+02:00
2021-04-17T09:57:36.2790347+02:00

bro did u fixed ?

StefH commented 3 years ago

Hello @nycr0x, for now I use https://github.com/Tyrrrz/YoutubeExplode which is faster.

For my example project see: https://github.com/StefH/Blazor.YouTubeDownloader.

omansak commented 3 years ago

I wrote a custom client , you can take a reference it

https://github.com/omansak/libvideo/blob/master/src/libvideo.debug/CustomYoutubeClient.cs