YoutubeExplode 6.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package YoutubeExplode --version 6.0.4                
NuGet\Install-Package YoutubeExplode -Version 6.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="YoutubeExplode" Version="6.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add YoutubeExplode --version 6.0.4                
#r "nuget: YoutubeExplode, 6.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install YoutubeExplode as a Cake Addin
#addin nuget:?package=YoutubeExplode&version=6.0.4

// Install YoutubeExplode as a Cake Tool
#tool nuget:?package=YoutubeExplode&version=6.0.4                

YoutubeExplode

Build Coverage Version Downloads Donate

⚠️ Project status: maintenance mode (bug fixes only).

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 and converting YouTube videos.

Download

📦 NuGet: dotnet add package YoutubeExplode

See also YoutubeExplode.Converter for an extension package that combines YoutubeExplode with FFmpeg.

Screenshots

demo

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:

// ...

// 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}");

Note that while it may be tempting to just always use muxed streams, given that they contain both audio and video, it's important to note that they are limited in quality and don't go beyond 720p30. If you want to download the video in maximum quality, you need to download the audio-only and video-only streams separately and then mux them together on your own using tools like FFmpeg. You can also use YoutubeExplode.Converter which wraps FFmpeg and provides an extension point for YoutubeExplode to download videos directly.

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (13)

Showing the top 5 NuGet packages that depend on YoutubeExplode:

Package Downloads
YoutubeExplode.Converter

Extension for YoutubeExplode that provides an interface to download and convert videos using FFmpeg

Soenneker.YouTube.Client

An async thread-safe singleton for the YouTube client YouTubeExplode

N3O.Umbraco.Video.YouTube

TODO

SpiderSharp

Web Crawling and Scraping Framework

StaticSharp.Core

Package Description

GitHub repositories (16)

Showing the top 5 popular GitHub repositories that depend on YoutubeExplode:

Repository Stars
Tyrrrz/YoutubeDownloader
Downloads videos and playlists from YouTube
Tyrrrz/DiscordChatExporter
Exports Discord chat logs to a file
shaked6540/YoutubePlaylistDownloader
A tool to download whole playlists, channels or single videos from youtube and also optionally convert them to almost any format you would like
Rise-Software/Rise-Media-Player
One media player for everything you own or stream; whether it's music or videos, online or offline Rise Media Player does it all. And it's beautiful and native with the latest version of WinUI.
MediaPortal/MediaPortal-2
Development of MediaPortal 2
Version Downloads Last updated
6.4.4 2,129 11/13/2024
6.4.3 11,210 10/3/2024
6.4.2 4,911 9/27/2024
6.4.1 3,087 9/18/2024
6.4.0 17,695 7/25/2024
6.3.16 20,784 5/21/2024
6.3.15 813 5/18/2024
6.3.14 9,174 4/27/2024
6.3.13 19,428 2/22/2024
6.3.12 16,411 1/18/2024
6.3.11 4,519 1/4/2024
6.3.10 3,770 12/27/2023
6.3.9 5,574 11/29/2023
6.3.8 3,905 11/23/2023
6.3.7 4,506 11/9/2023
6.3.6 6,129 10/17/2023
6.3.5 4,601 9/28/2023
6.3.4 8,284 9/6/2023
6.3.3 3,874 8/31/2023
6.3.2 7,454 8/18/2023
6.3.2-alpha1 1,478 7/30/2023
6.3.1 12,506 7/23/2023
6.3.0 1,904 7/20/2023
6.3.0-alpha1 970 7/15/2023
6.2.17 3,767 7/12/2023
6.2.16 4,558 6/28/2023
6.2.15 10,080 5/25/2023
6.2.14 19,664 5/2/2023
6.2.13 22,832 4/27/2023
6.1.0 117,018 2/19/2022
6.0.8 16,164 2/10/2022
6.0.7 129,554 12/10/2021
6.0.6 5,514 12/9/2021
6.0.5 21,527 7/28/2021
6.0.4 2,875 7/2/2021
6.0.3 2,462 6/21/2021
6.0.2 7,969 5/28/2021
6.0.1 2,950 5/21/2021
6.0.0 347,831 4/17/2021
6.0.0-alpha2 292,574 4/1/2021
6.0.0-alpha 1,700 2/25/2021
5.1.9 31,352 11/28/2020
5.1.8 13,156 10/25/2020
5.1.7 2,954 10/12/2020
5.1.6 2,882 9/29/2020
5.1.5 3,081 9/12/2020
5.1.4 3,940 8/14/2020
5.1.3 3,164 7/29/2020
5.1.2 2,214 7/21/2020
5.1.1 6,084 6/21/2020
5.1.0 2,410 6/14/2020
5.0.5 2,722 5/23/2020
5.0.4 2,394 5/10/2020
5.0.3 2,045 5/1/2020
5.0.2 1,712 4/24/2020
5.0.1 3,301 4/13/2020
5.0.0 2,258 4/12/2020
4.7.16 8,088 3/16/2020
4.7.15 2,600 3/11/2020
4.7.14 1,481 3/10/2020
4.7.13 3,605 2/10/2020
4.7.12 7,941 12/29/2019
4.7.11 2,519 12/15/2019
4.7.10 7,815 9/24/2019
4.7.9 13,286 8/15/2019
4.7.8 2,133 8/8/2019
4.7.7 2,115 7/30/2019
4.7.6 3,425 7/10/2019
4.7.5 1,648 7/4/2019
4.7.4 1,715 6/24/2019
4.7.3 1,604 6/21/2019
4.7.2 1,776 6/13/2019
4.7.1 2,502 5/16/2019
4.7.0 2,554 5/12/2019
4.7.0-beta2 1,273 5/6/2019
4.7.0-beta 1,371 4/25/2019
4.7.0-alpha 1,352 4/21/2019
4.6.8 2,750 3/30/2019
4.6.7 1,890 3/16/2019
4.6.6 2,991 2/24/2019
4.6.5 1,771 2/16/2019
4.6.4 3,738 1/16/2019
4.6.3 1,704 1/13/2019
4.6.2 3,326 1/4/2019
4.6.1 3,421 12/3/2018
4.6.0 1,941 11/22/2018
4.5.3 18,745 11/7/2018
4.5.2 1,835 11/2/2018
4.5.1 3,189 10/24/2018
4.5.0 1,766 10/20/2018
4.4.0 1,515 10/20/2018
4.3.4 1,773 10/16/2018
4.3.3 2,194 9/26/2018
4.3.2 2,149 9/10/2018
4.3.1 1,925 8/28/2018
4.3.0 16,313 7/25/2018
4.2.8 6,155 6/14/2018
4.2.7 1,964 6/9/2018
4.2.6 1,839 6/9/2018
4.2.5 2,213 5/20/2018
4.2.4 2,119 5/2/2018
4.2.3 1,970 4/22/2018
4.2.2 2,243 3/31/2018
4.2.1 1,803 3/28/2018
4.2.0 2,070 3/24/2018
4.1.1 2,864 2/20/2018
4.1.0 6,707 2/2/2018
4.1.0-alpha4 1,735 1/29/2018
4.1.0-alpha3 1,622 1/28/2018
4.1.0-alpha2 1,940 12/24/2017
4.1.0-alpha 1,822 12/16/2017
4.0.0 3,348 12/15/2017
4.0.0-alpha 1,927 12/10/2017
3.4.0-workaround404 1,595 11/28/2017
3.3.0 3,664 10/19/2017
3.2.5 2,279 8/29/2017
3.2.4 1,898 8/28/2017
3.2.3 2,208 8/11/2017
3.2.2 1,875 8/8/2017
3.2.1 1,874 8/5/2017
3.2.0 2,323 7/4/2017
3.1.1 2,238 6/8/2017
3.1.0 2,043 6/1/2017
3.0.2 1,937 5/12/2017
3.0.1 1,817 5/8/2017
3.0.0 1,834 4/24/2017
2.5.0 1,870 3/26/2017
2.4.0 1,706 3/24/2017
2.3.0 1,794 3/10/2017
2.2.2 1,691 3/8/2017
2.2.1 1,695 3/7/2017
2.2.0 1,695 3/6/2017
2.1.3 1,780 3/5/2017
2.1.2 1,699 3/3/2017
2.1.1 1,651 3/3/2017
2.1.0 1,745 3/2/2017
2.0.1 1,711 3/2/2017
2.0.0 1,684 3/2/2017
1.1.0 1,857 2/24/2017
1.0.4 1,735 2/19/2017
1.0.3 1,702 2/2/2017
1.0.2 1,756 1/28/2017
1.0.1 1,730 1/26/2017
1.0.0 2,038 1/25/2017