Ytdlp.NET
1.4.0
dotnet add package Ytdlp.NET --version 1.4.0
NuGet\Install-Package Ytdlp.NET -Version 1.4.0
<PackageReference Include="Ytdlp.NET" Version="1.4.0" />
<PackageVersion Include="Ytdlp.NET" Version="1.4.0" />
<PackageReference Include="Ytdlp.NET" />
paket add Ytdlp.NET --version 1.4.0
#r "nuget: Ytdlp.NET, 1.4.0"
#:package Ytdlp.NET@1.4.0
#addin nuget:?package=Ytdlp.NET&version=1.4.0
#tool nuget:?package=Ytdlp.NET&version=1.4.0
Ytdlp.NET
Ytdlp.NET is a fluent, strongly-typed .NET wrapper around the powerful yt-dlp command-line tool. It provides an intuitive and customizable interface to download videos, extract audio, retrieve metadata, and process media from YouTube and hundreds of other supported platforms.
Importanant Note
External JS Scripts Setup Guide
- To download from YouTube, yt-dlp needs to solve JavaScript challenges presented by YouTube using an external JavaScript runtime.
- Supports downloading EJS script dependencies from npm (--remote-components ejs:npm)
To use this:
await ytdlp
.SetOutputFolder("c:\video")
.SetFormat("b")
.AddCustomCommand("--restrict-filenames")
.AddCustomCommand("--remote-components ejs:npm")
.ExecuteAsync(YoutubeUrl, cancellationToken);
π Features
- Fluent API: Easily construct
yt-dlpcommands with chainable methods. - Progress & Events: Real-time progress tracking, completion, and error callbacks.
- Format Listing: Retrieve and parse all available formats for any video.
- Batch Downloads: Download multiple videos with sequential or parallel execution.
- Custom Command Injection: Use
AddCustomCommandto include advanced or new options. - Validated Options: Rejects invalid yt-dlp commands with a built-in option whitelist.
- Cross-Platform: Works on Windows, macOS, and Linux (where
yt-dlpis supported). - Output Templates: Customize naming patterns with standard
yt-dlpplaceholders. - Update: Implements update method to update latest yt-dlp version.
π¦ Prerequisites
- .NET: Requires .NET 8.0 or later.
- yt-dlp: The
yt-dlpcommand-line tool must be installed and accessible in your systemβs PATH or specified explicitly.- Install
yt-dlpvia pip:pip install -U yt-dlp - Verify installation:
yt-dlp --version
- Install
- FFmpeg (optional): Required for certain operations like merging formats or extracting audio. Install via your package manager or download from FFmpeg.org.
β¨ Basic Usage
π½ Download a Single Video
Download a video with the best quality to a specified folder:
var ytdlp = new Ytdlp("yt-dlp", new ConsoleLogger());
await ytdlp
.SetFormat("best")
.SetOutputFolder("downloads")
.DownloadThumbnails()
.ExecuteAsync("https://www.youtube.com/watch?v=RGg-Qx1rL9U");
π΅ Extract Audio + Embed Metadata
await ytdlp
.ExtractAudio("mp3")
.EmbedMetadata()
.SetOutputFolder("audio")
.ExecuteAsync("https://www.youtube.com/watch?v=RGg-Qx1rL9U");
π§Ύ List Available Formats
var formats = await ytdlp.GetAvailableFormatsAsync("https://youtube.com/watch?v=abc123");
foreach (var f in formats)
{
Console.WriteLine($"ID: {f.ID}, Resolution: {f.Resolution}, VCodec: {f.VCodec}");
}
π§ͺ Get Video Metadata Only
var metadata = await ytdlp.GetVideoMetadataJsonAsync("https://youtube.com/watch?v=abc123");
Console.WriteLine($"Title: {metadata?.Title}, Duration: {metadata?.Duration}");
π¦ Batch Download
Sequential (one after another)
await ytdlp
.SetFormat("best")
.SetOutputFolder("batch")
.ExecuteBatchAsync(new[] {
"https://youtu.be/vid1", "https://youtu.be/vid2"
});
Parallel (max 3 at a time)
await ytdlp
.SetFormat("best")
.SetOutputFolder("batch")
.ExecuteBatchAsync(new[] {
"https://youtu.be/vid1", "https://youtu.be/vid2"
}, maxConcurrency: 3);
βοΈ Configuration & Options
β Common Fluent Methods
- .SetFormat(string format)
- .SetOutputFolder(string path)
- .ExtractAudio(string format)
- .EmbedMetadata()
- .DownloadThumbnails()
- .DownloadSubtitles("en")
- .UseCookies("cookies.txt")
- .SetUserAgent("MyApp/1.0")
- .Simulate()
- .DisableAds()
- .SetDownloadTimeout("30")
- .SetAuthentication(username, password)
- .PostProcessFiles("--audio-quality 0")
- .AddCustomCommand(string command)
π§© Add Custom yt-dlp Option
ytdlp.AddCustomCommand("--sponsorblock-mark all");
Will be validated against internal whitelist. Invalid commands will trigger error logging via ILogger.
π‘ Events
ytdlp.OnProgressMessage += (s, msg) => Console.WriteLine($"Progress: {msg}");
ytdlp.OnErrorMessage += (s, err) => Console.WriteLine($"Error: {err}");
ytdlp.OnCommandCompleted += (success, message) => Console.WriteLine($"Finished: {message}");
ytdlp.OnOutputMessage += (s, msg) => Console.WriteLine(msg);
ytdlp.OnPostProcessingComplete += (s, msg) => Console.WriteLine($"Postprocessing: {msg}");
π Output Template
You can customize file naming using yt-dlp placeholders:
ytdlp.SetOutputTemplate("%(title)s-%(id)s.%(ext)s");
π§ͺ Validation & Safety
All AddCustomCommand(...) calls are validated against a known safe set of yt-dlp options, minimizing the risk of malformed or unsupported commands.
To preview what command will run:
string preview = ytdlp.PreviewCommand();
Console.WriteLine(preview);
β Error Handling
All exceptions are wrapped in YtdlpException:
try
{
await ytdlp.ExecuteAsync("https://invalid-url");
}
catch (YtdlpException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
π§ͺ Version Check
string version = await ytdlp.GetVersionAsync();
Console.WriteLine($"yt-dlp version: {version}");
π‘ Tips
- For livestreams, use:
.DownloadLivestream(true) - To skip already-downloaded videos:
.SkipDownloaded()
π Custom Logging
Implement your own ILogger:
public class ConsoleLogger : ILogger
{
public void Log(LogType type, string message)
{
Console.WriteLine($"[{type}] {message}");
}
}
π€ Contributing
Contributions are welcome! Please submit issues or pull requests to the GitHub repository. Ensure code follows the projectβs style guidelines and includes unit tests.
π License
This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.