YoutubeExplode.Converter
6.0.8
See the version list below for details.
dotnet add package YoutubeExplode.Converter --version 6.0.8
NuGet\Install-Package YoutubeExplode.Converter -Version 6.0.8
<PackageReference Include="YoutubeExplode.Converter" Version="6.0.8" />
paket add YoutubeExplode.Converter --version 6.0.8
#r "nuget: YoutubeExplode.Converter, 6.0.8"
// Install YoutubeExplode.Converter as a Cake Addin #addin nuget:?package=YoutubeExplode.Converter&version=6.0.8 // Install YoutubeExplode.Converter as a Cake Tool #tool nuget:?package=YoutubeExplode.Converter&version=6.0.8
YoutubeExplode
⚠️ Project status: maintenance mode. What does it mean?
YoutubeExplode is a library that provides an interface to query metadata of YouTube videos, playlists and channels, as well as to resolve and download video streams and closed caption tracks. Behind a layer of abstraction, the library parses raw page content and uses reverse-engineered requests to retrieve information. As it doesn't use the official API, there's also no need for an API key and there are no usage quotas.
✨ This library is used in YoutubeDownloader -- a desktop application for downloading YouTube videos.
💬 If you want to chat, join my Discord server.
Download
- 📦 NuGet:
dotnet add package YoutubeExplode
(main package) - 📦 NuGet:
dotnet add package YoutubeExplode.Converter
(FFmpeg integration)
Screenshots
Usage
YoutubeExplode exposes its functionality through a single entry point -- the YoutubeClient
class.
Create an instance of this class and use the provided operations on Videos
, Playlists
, Channels
, and Search
properties to send requests.
Videos
Retrieving video metadata
To retrieve metadata associated with a YouTube video, call Videos.GetAsync(...)
:
using YoutubeExplode;
var youtube = new YoutubeClient();
// You can specify both video ID or URL
var video = await youtube.Videos.GetAsync("https://youtube.com/watch?v=u_yIGGhubZs");
var title = video.Title; // "Collections - Blender 2.80 Fundamentals"
var author = video.Author.Title; // "Blender"
var duration = video.Duration; // 00:07:20
Downloading video streams
Every YouTube video has a number of streams available, differing in containers, video quality, bitrate, framerate, and other properties. Additionally, depending on the content of the stream, the streams are further divided into 3 categories:
- Muxed streams -- contain both video and audio
- Audio-only streams -- contain only audio
- Video-only streams -- contain only video
You can request the manifest that lists all available streams for a particular video by calling Videos.Streams.GetManifestAsync(...)
:
using YoutubeExplode;
var youtube = new YoutubeClient();
var streamManifest = await youtube.Videos.Streams.GetManifestAsync("u_yIGGhubZs");
Once you get the manifest, you can filter through the streams and select the ones you're interested in:
using YoutubeExplode;
using YoutubeExplode.Videos.Streams;
// ...
// Get highest quality muxed stream
var streamInfo = streamManifest.GetMuxedStreams().GetWithHighestVideoQuality();
// ...or highest bitrate audio-only stream
var streamInfo = streamManifest.GetAudioOnlyStreams().GetWithHighestBitrate();
// ...or highest quality MP4 video-only stream
var streamInfo = streamManifest
.GetVideoOnlyStreams()
.Where(s => s.Container == Container.Mp4)
.GetWithHighestVideoQuality()
Finally, you can resolve the actual stream represented by the specified metadata using Videos.Streams.GetAsync(...)
or download it directly to a file with Videos.Streams.DownloadAsync(...)
:
// ...
// Get the actual stream
var stream = await youtube.Videos.Streams.GetAsync(streamInfo);
// Download the stream to a file
await youtube.Videos.Streams.DownloadAsync(streamInfo, $"video.{streamInfo.Container}");
⚠ While it may be tempting to always rely on muxed streams, given that they contain both audio and video, it's important to note that they are very limited in quality (up to 720p30). If you want to download a video in highest available quality, you need to resolve the best audio-only and video-only streams separately and then mux them together, which can be accomplished by using the YoutubeExplode.Converter package (see below).
Downloading video with muxing or conversion
⚠ Downloading with muxing or conversion requires YoutubeExplode.Converter.
⚠ This package also relies on FFmpeg CLI, which can be downloaded here. Ensure that the FFmpeg binary is located in your application's probe directory or on the system's
PATH
, or use one of the overloads to provide a custom location directly.
You can download a video with muxing or conversion through one of the extension methods provided on VideoClient
.
For example, to download a video in the specified format using highest quality streams, simply call DownloadAsync(...)
with the video ID and the destination file path:
using YoutubeExplode;
using YoutubeExplode.Converter;
var youtube = new YoutubeClient();
await youtube.Videos.DownloadAsync("https://youtube.com/watch?v=u_yIGGhubZs", "video.mp4");
Under the hood, this resolves the video's media streams and selects the best candidates based on format, bitrate, quality, and framerate.
If the specified output format is a known audio-only container (e.g. mp3
or ogg
) then only the audio stream is downloaded.
⚠ Stream muxing is a CPU-heavy process. You can reduce resource usage and execution time by using streams that don't require transcoding to the output format (e.g.
mp4
audio/video streams formp4
output format). Currently, YouTube only provides adaptive streams inmp4
orwebm
containers, with highest quality video streams (e.g. 4K) only available inwebm
.
To configure various aspects related to the conversion process, use one of the overloads of DownloadAsync(...)
:
using YoutubeExplode;
using YoutubeExplode.Converter;
var youtube = new YoutubeClient();
await youtube.Videos.DownloadAsync("https://youtube.com/watch?v=u_yIGGhubZs", "video.mp4", o => o
.SetFormat("webm") // override format
.SetPreset(ConversionPreset.UltraFast) // change preset
.SetFFmpegPath("path/to/ffmpeg") // custom FFmpeg location
);
If you need precise control over which streams are used for muxing, you can also provide them yourself:
using YoutubeExplode;
using YoutubeExplode.Videos.Streams;
using YoutubeExplode.Converter;
var youtube = new YoutubeClient();
// Get stream manifest
var streamManifest = await youtube.Videos.Streams.GetManifestAsync("u_yIGGhubZs");
// Select streams (1080p60 / highest bitrate audio)
var audioStreamInfo = streamManifest.GetAudioStreams().GetWithHighestBitrate();
var videoStreamInfo = streamManifest.GetVideoStreams().First(s => s.VideoQuality.Label == "1080p60");
var streamInfos = new IStreamInfo[] { audioStreamInfo, videoStreamInfo };
// Download and process them into one file
await youtube.Videos.DownloadAsync(streamInfos, new ConversionRequestBuilder("video.mp4").Build());
Downloading closed captions
Closed captions can be downloaded in a similar way to media streams.
To get the list of available closed caption tracks, call Videos.ClosedCaptions.GetManifestAsync(...)
:
using YoutubeExplode;
var youtube = new YoutubeClient();
var trackManifest = await youtube.Videos.ClosedCaptions.GetManifestAsync("u_yIGGhubZs");
Then retrieve metadata for a particular track:
// ...
// Find closed caption track in English
var trackInfo = trackManifest.GetByLanguage("en");
Finally, use Videos.ClosedCaptions.GetAsync(...)
to get the actual content of the track:
// ...
var track = await youtube.Videos.ClosedCaptions.GetAsync(trackInfo);
// Get the caption displayed at 0:35
var caption = track.GetByTime(TimeSpan.FromSeconds(35));
var text = caption.Text; // "collection acts as the parent collection"
You can also download the closed caption track in SRT file format with Videos.ClosedCaptions.DownloadAsync(...)
:
// ...
await youtube.Videos.ClosedCaptions.DownloadAsync(trackInfo, "cc_track.srt");
Playlists
Retrieving playlist metadata
You can get metadata associated with a YouTube playlist by calling Playlists.GetAsync(...)
method:
using YoutubeExplode;
var youtube = new YoutubeClient();
var playlist = await youtube.Playlists.GetAsync("PLa1F2ddGya_-UvuAqHAksYnB0qL9yWDO6");
var title = playlist.Title; // "First Steps - Blender 2.80 Fundamentals"
var author = playlist.Author.Title; // "Blender"
Getting videos included in a playlist
To get the videos included in a playlist, call Playlists.GetVideosAsync(...)
:
using YoutubeExplode;
using YoutubeExplode.Common;
var youtube = new YoutubeClient();
// Get all playlist videos
var videos = await youtube.Playlists.GetVideosAsync("PLa1F2ddGya_-UvuAqHAksYnB0qL9yWDO6");
// Get the first 20 playlist videos
var videosSubset = await youtube.Playlists
.GetVideosAsync(playlist.Id)
.CollectAsync(20);
You can also enumerate videos lazily without waiting for the whole list to load:
using YoutubeExplode;
var youtube = new YoutubeClient();
await foreach (var video in youtube.Playlists.GetVideosAsync("PLa1F2ddGya_-UvuAqHAksYnB0qL9yWDO6"))
{
var title = video.Title;
var author = video.Author;
}
If you need precise control over how many requests you send to YouTube, use Playlists.GetVideoBatchesAsync(...)
which returns videos wrapped in batches:
using YoutubeExplode;
var youtube = new YoutubeClient();
// Each batch corresponds to one request
await foreach (var batch in youtube.Playlists.GetVideoBatchesAsync("PLa1F2ddGya_-UvuAqHAksYnB0qL9yWDO6"))
{
foreach (var video in batch.Items)
{
var title = video.Title;
var author = video.Author;
}
}
Channels
Retrieving channel metadata
You can get metadata associated with a YouTube channel by calling Channels.GetAsync(...)
method:
using YoutubeExplode;
var youtube = new YoutubeClient();
var channel = await youtube.Channels.GetAsync("UCSMOQeBJ2RAnuFungnQOxLg");
var title = channel.Title; // "Blender"
You can also get channel metadata by username with Channels.GetByUserAsync(...)
:
using YoutubeExplode;
var youtube = new YoutubeClient();
var channel = await youtube.Channels.GetByUserAsync("Blender");
var id = channel.Id; // "UCSMOQeBJ2RAnuFungnQOxLg"
Getting channel uploads
To get a list of videos uploaded by a channel, call Channels.GetUploadsAsync(...)
:
using YoutubeExplode;
using YoutubeExplode.Common;
var youtube = new YoutubeClient();
var videos = await youtube.Channels.GetUploadsAsync("UCSMOQeBJ2RAnuFungnQOxLg");
Searching
You can execute a search query and get the results by calling Search.GetResultsAsync(...)
.
Each result may represent either a video, a playlist, or a channel, so you need to use pattern matching to handle corresponding cases:
using YoutubeExplode;
var youtube = new YoutubeClient();
await foreach (var result in youtube.Search.GetResultsAsync("blender tutorials"))
{
// Use pattern matching to handle different results (videos, playlists, channels)
switch (result)
{
case VideoSearchResult videoResult:
{
var id = videoResult.Id;
var title = videoResult.Title;
var duration = videoResult.Duration;
break;
}
case PlaylistSearchResult playlistResult:
{
var id = playlistResult.Id;
var title = playlistResult.Title;
break;
}
case ChannelSearchResult channelResult:
{
var id = channelResult.Id;
var title = channelResult.Title;
break;
}
}
}
To limit results to a specific type, use Search.GetVideosAsync(...)
, Search.GetPlaylistsAsync(...)
, or Search.GetChannelsAsync(...)
:
using YoutubeExplode;
using YoutubeExplode.Common;
var youtube = new YoutubeClient();
var videos = await youtube.Search.GetVideosAsync("blender tutorials");
var playlists = await youtube.Search.GetPlaylistsAsync("blender tutorials");
var channels = await youtube.Search.GetChannelsAsync("blender tutorials");
Similarly to playlists, you can also enumerate results in batches by calling Search.GetResultBatchesAsync(...)
:
using YoutubeExplode;
var youtube = new YoutubeClient();
// Each batch corresponds to one request
await foreach (var batch in youtube.Search.GetResultBatchesAsync("blender tutorials"))
{
foreach (var result in batch.Items)
{
switch (result)
{
case VideoSearchResult videoResult:
{
// ...
}
case PlaylistSearchResult playlistResult:
{
// ...
}
case ChannelSearchResult channelResult:
{
// ...
}
}
}
}
Etymology
The "Explode" in YoutubeExplode comes from the name of a PHP function that splits up strings, explode()
. When I was just starting development on this library, most of the reference source code I read was written in PHP, hence the inspiration for the name.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 is compatible. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.0
- CliWrap (>= 3.3.3)
- YoutubeExplode (>= 6.0.8)
-
.NETFramework 4.6.1
- CliWrap (>= 3.3.3)
- YoutubeExplode (>= 6.0.8)
-
.NETStandard 2.0
- CliWrap (>= 3.3.3)
- YoutubeExplode (>= 6.0.8)
-
.NETStandard 2.1
- CliWrap (>= 3.3.3)
- YoutubeExplode (>= 6.0.8)
-
net5.0
- CliWrap (>= 3.3.3)
- YoutubeExplode (>= 6.0.8)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on YoutubeExplode.Converter:
Package | Downloads |
---|---|
MP3DL.lib
Package Description |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on YoutubeExplode.Converter:
Repository | Stars |
---|---|
Tyrrrz/YoutubeDownloader
Downloads videos and playlists from YouTube
|
|
crobibero/jellyfin-plugin-tmdb-trailers
|
Version | Downloads | Last updated |
---|---|---|
6.4.4 | 124 | 11/13/2024 |
6.4.3 | 2,253 | 10/3/2024 |
6.4.2 | 1,392 | 9/27/2024 |
6.4.1 | 820 | 9/18/2024 |
6.4.0 | 3,219 | 7/25/2024 |
6.3.16 | 4,547 | 5/21/2024 |
6.3.15 | 233 | 5/18/2024 |
6.3.14 | 1,566 | 4/27/2024 |
6.3.13 | 2,249 | 2/22/2024 |
6.3.12 | 3,823 | 1/18/2024 |
6.3.11 | 863 | 1/4/2024 |
6.3.10 | 640 | 12/27/2023 |
6.3.9 | 1,238 | 11/29/2023 |
6.3.8 | 924 | 11/23/2023 |
6.3.7 | 912 | 11/9/2023 |
6.3.6 | 1,150 | 10/17/2023 |
6.3.5 | 1,000 | 9/28/2023 |
6.3.4 | 1,294 | 9/6/2023 |
6.3.3 | 1,327 | 8/31/2023 |
6.3.2 | 1,018 | 8/18/2023 |
6.3.2-alpha1 | 599 | 7/30/2023 |
6.3.1 | 1,448 | 7/23/2023 |
6.3.0 | 681 | 7/20/2023 |
6.2.17 | 1,164 | 7/12/2023 |
6.2.16 | 1,224 | 6/28/2023 |
6.2.15 | 1,627 | 5/25/2023 |
6.2.14 | 1,982 | 5/2/2023 |
6.2.13 | 1,054 | 4/27/2023 |
6.2.12 | 1,769 | 3/31/2023 |
6.2.11 | 979 | 3/24/2023 |
6.2.10 | 816 | 3/17/2023 |
6.2.9 | 1,007 | 3/10/2023 |
6.2.8 | 5,304 | 3/1/2023 |
6.1.0 | 107,947 | 2/19/2022 |
6.0.8 | 13,622 | 2/10/2022 |
6.0.7 | 119,103 | 12/10/2021 |
6.0.6 | 4,650 | 12/9/2021 |
2.1.0 | 342,591 | 4/18/2021 |
2.0.2 | 2,559 | 12/26/2020 |
2.0.1 | 890 | 12/26/2020 |
2.0.0 | 2,641 | 10/14/2020 |
1.5.1 | 3,673 | 4/22/2020 |
1.5.0 | 1,243 | 4/13/2020 |
1.4.4 | 971 | 4/12/2020 |
1.4.3 | 3,948 | 7/27/2019 |
1.4.2 | 1,794 | 5/12/2019 |
1.4.1 | 1,698 | 3/3/2019 |
1.4.0 | 1,764 | 1/17/2019 |
1.3.0 | 1,194 | 1/16/2019 |
1.2.0 | 1,220 | 1/9/2019 |
1.1.0 | 1,153 | 1/8/2019 |
1.0.3 | 1,350 | 12/20/2018 |
1.0.2 | 1,217 | 12/17/2018 |
1.0.1 | 1,825 | 10/27/2018 |
1.0.0 | 1,278 | 10/27/2018 |