omansak / libvideo

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

How can I download video usign "GetAllVideos(VideoURL)" #213

Closed Dei11 closed 3 years ago

Dei11 commented 3 years ago
                var videos = youtube.GetAllVideos(VideoURL);
                var resolution = videos.FirstOrDefault(v => v.Resolution == 480);
Areoxy commented 3 years ago

Hey,

i had the same problem like yours and found a solution.

var youtube = YouTube.Default;
var video = youtube.GetVideo(url);

string title = video.Title;
var videos = youtube.GetAllVideosAsync(url).GetAwaiter().GetResult();

var maxResolution = videos.First(i => i.Resolution == 1080);
var bytes = maxResolution.GetBytesAsync();

var contents = await maxResolution.GetBytesAsync();

File.WriteAllBytes(path + "/" + title + "mp4", contents);

(Note that you replace the path with your path!)

Regards