A simple youtube-dl library for C#.
See the main page for youtube-dl for more information.
-
Search for
NYoutubeDL
in you project's Nuget Manager and click install. -
In the Nuget package manager console, run
PM> Install-Package NYoutubeDL
-
Manually download nupkg from NuGet Gallery.
See the documentation for youtube-dl first to understand what it does and how it does it.
-
Create a new YoutubeDL client:
var youtubeDl = new YoutubeDL();
-
Options are grouped according to the youtube-dl documentation:
youtubeDl.Options.FileSystem.Output = "/path/to/downloads/video.mp4"; youtubeDl.Options.PostProcessing.ExtractAudio = true; youtubeDl.VideoUrl = "http://www.somevideosite.com/videoUrl"; // Or update the binary youtubeDl.Options.General.Update = true; // Optional, required if binary is not in $PATH youtubeDl.YoutubeDlPath = "/path/to/youtube-dl";
-
Options can also be saved and loaded. Only changed options will be saved.
File.WriteAllText("options.config", youtubeDl.Options.Serialize()); youtubeDl.Options = Options.Deserialize(File.ReadAllText("options.config"));
-
Subscribe to the console output (optional, but recommended):
youtubeDl.StandardOutputEvent += (sender, output) => Console.WriteLine(output); youtubeDl.StandardErrorEvent += (sender, errorOutput) => Console.WriteLine(errorOutput);
-
Subscribe to download information updates. Hard subscription is optional, the DownloadInfo class implements INotifyPropertyChanged.
youtubeDl.Info.PropertyChanged += delegate { <your code here> };
-
Start the download:
// Prepare the download (in case you need to validate the command before starting the download) string commandToRun = await youtubeDl.PrepareDownloadAsync(); // Alternatively string commandToRun = youtubeDl.PrepareDownload(); // Just let it run youtubeDl.DownloadAsync(); // Wait for it youtubeDl.Download(); // Or provide video url youtubeDl.Download("http://videosite.com/videoUrl");