YoutubeExplode

TyrrrzMIT活跃维护

封装 YouTube 内部 API 的 .NET 库,可解析视频元数据、播放流和字幕,并支持下载,省去自行逆向接口的麻烦。

Abstraction layer over YouTube's internal API

6.6.3发布于 2026-10-25 09:36 UTC3,752star +1 / 7 天603fork同步于 2026-11-10 05:39 UTC

怎么上手

README 里没有找到可直接复制的安装命令

README 里没有找到可直接复制的安装命令,请到 README 或官方文档查看安装方式。

硬件要求

README 没有说明硬件要求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

5 个版本6.6.3
  1. 6.6.3最新正式版2026-10-25 · 2026-10-25 09:36 UTC

    What's Changed

    Bugs

    New Contributors

    Full Changelog: https://github.com/Tyrrrz/YoutubeExplode/compare/6.6.2...6.6.3

  2. 6.6.22026-08-25 · 2026-08-25 13:41 UTC
    查看更新说明

    What's Changed

    Bugs

    New Contributors

    Full Changelog: https://github.com/Tyrrrz/YoutubeExplode/compare/6.6.1...6.6.2

  3. 6.6.12026-08-07 · 2026-08-07 11:47 UTC
    查看更新说明

    What's Changed

    Enhancements

    Bugs

    Full Changelog: https://github.com/Tyrrrz/YoutubeExplode/compare/6.6...6.6.1

  4. 6.62026-04-22 · 2026-04-22 11:26 UTC
    查看更新说明

    What's Changed

    Enhancements

    Bugs

    New Contributors

    Full Changelog: https://github.com/Tyrrrz/YoutubeExplode/compare/6.5.7...6.6

  5. 6.5.72026-02-12 · 2026-02-12 09:53 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/Tyrrrz/YoutubeExplode/compare/6.5.6...6.5.7

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    YoutubeExplode

    Status Build Coverage Version Downloads Discord

    Made in 🇺🇦 Ukraine — despite Russia's best efforts. Using this project or its source code comes with the implicit agreement that you condemn Russia's war of aggression against Ukraine, recognize Russia as a terrorist state, and support Ukraine's territorial integrity.

    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, this library works by scraping raw page data and exploiting reverse-engineered internal endpoints.

    See also:

    Install

    • 📦 NuGet: dotnet add package YoutubeExplode

    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 the metadata associated with a YouTube video, call Videos.GetAsync(...):

    using YoutubeExplode;
    
    using var youtube = new YoutubeClient();
    
    // You can specify either the video URL or its ID
    var videoUrl = "https://youtube.com/watch?v=u_yIGGhubZs";
    var video = await youtube.Videos.GetAsync(videoUrl);
    
    var title = video.Title; // "Collections - Blender 2.80 Fundamentals"
    var author = video.Author.ChannelTitle; // "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 parameters. Additionally, the streams are further divided into 3 categories based on their content:

    • Muxed streams — contain both video and audio (no longer provided by YouTube)
    • Audio-only streams — contain only audio
    • Video-only streams — contain only video

    [!WARNING] Muxed streams contain both audio and video, but these streams are limited in quality (up to 720p30). To download the video in the highest available quality, you will need to resolve the best audio-only and video-only streams separately and then mux them together. The muxing process can be performed using FFmpeg with the help of the YoutubeExplode.Converter package.

    [!WARNING] Muxed streams are deprecated by YouTube and are not guaranteed to be available for every video. If possible, avoid relying on them too much and instead perform muxing manually using the provided audio-only and video-only streams.

    You can request the manifest that lists all available streams for a particular video by calling Videos.Streams.GetManifestAsync(...):

    using YoutubeExplode;
    
    using var youtube = new YoutubeClient();
    
    var videoUrl = "https://youtube.com/watch?v=u_yIGGhubZs";
    var streamManifest = await youtube.Videos.Streams.GetManifestAsync(videoUrl);
    

    Once the manifest is obtained, you can filter through the streams and identify the ones you're interested in:

    using YoutubeExplode;
    using YoutubeExplode.Videos.Streams;
    
    // ...
    
    // Get the highest bitrate audio-only stream
    var streamInfo = streamManifest.GetAudioOnlyStreams().GetWithHighestBitrate();
    
    // ...or the 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}");
    

    [!WARNING] While the Url property in the stream metadata can be used to access the underlying content, you need a series of carefully crafted HTTP requests in order to do so. It's highly recommended to use Videos.Streams.GetAsync(...) or Videos.Streams.DownloadAsync(...) instead, as they will perform all the heavy lifting for you.

    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;
    
    using var youtube = new YoutubeClient();
    
    var videoUrl = "https://youtube.com/watch?v=u_yIGGhubZs";
    var trackManifest = await youtube.Videos.ClosedCaptions.GetManifestAsync(videoUrl);
    

    Then retrieve the 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 the SRT file format with Videos.ClosedCaptions.DownloadAsync(...):

    // ...
    
    await youtube.Videos.ClosedCaptions.DownloadAsync(trackInfo, "cc_track.srt");
    

    Playlists

    Retrieving playlist metadata

    You can get the metadata associated with a YouTube playlist by calling the Playlists.GetAsync(...) method:

    using YoutubeExplode;
    
    using var youtube = new YoutubeClient();
    
    var playlistUrl = "https://youtube.com/playlist?list=PLa1F2ddGya_-UvuAqHAksYnB0qL9yWDO6";
    var playlist = await youtube.Playlists.GetAsync(playlistUrl);
    
    var title = playlist.Title; // "First Steps - Blender 2.80 Fundamentals"
    var author = playlist.Author.ChannelTitle; // "Blender"
    
    Retrieving videos included in a playlist

    To get the videos included in a playlist, call Playlists.GetVideosAsync(...):

    using YoutubeExplode;
    using YoutubeExplode.Common;
    
    using var youtube = new YoutubeClient();
    var playlistUrl = "https://youtube.com/playlist?list=PLa1F2ddGya_-UvuAqHAksYnB0qL9yWDO6";
    
    // Get all playlist videos
    var videos = await youtube.Playlists.GetVideosAsync(playlistUrl);
    
    // Get only the first 20 playlist videos
    var videosSubset = await youtube.Playlists.GetVideosAsync(playlistUrl).CollectAsync(20);
    

    You can also enumerate the videos iteratively without waiting for the whole list to load:

    using YoutubeExplode;
    
    using var youtube = new YoutubeClient();
    var playlistUrl = "https://youtube.com/playlist?list=PLa1F2ddGya_-UvuAqHAksYnB0qL9yWDO6";
    
    await foreach (var video in youtube.Playlists.GetVideosAsync(playlistUrl))
    {
        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;
    
    using var youtube = new YoutubeClient();
    var playlistUrl = "https://youtube.com/playlist?list=PLa1F2ddGya_-UvuAqHAksYnB0qL9yWDO6";
    
    // Each batch corresponds to one request
    await foreach (var batch in youtube.Playlists.GetVideoBatchesAsync(playlistUrl))
    {
        foreach (var video in batch.Items)
        {
            var title = video.Title;
            var author = video.Author;
        }
    }
    

    [!NOTE] You can craft playlist IDs to fetch special auto-generated playlists, such as music mixes, popular channel uploads, liked videos, and more. See this reference for more information.

    Channels

    Retrieving channel metadata

    You can get the metadata associated with a YouTube channel by calling the Channels.GetAsync(...) method:

    using YoutubeExplode;
    
    using var youtube = new YoutubeClient();
    
    var channelUrl = "https://youtube.com/channel/UCSMOQeBJ2RAnuFungnQOxLg";
    var channel = await youtube.Channels.GetAsync(channelUrl);
    
    var title = channel.Title; // "Blender"
    

    You can also get the channel metadata by username or profile URL with Channels.GetByUserAsync(...):

    using YoutubeExplode;
    
    using var youtube = new YoutubeClient();
    
    var channelUrl = "https://youtube.com/user/BlenderFoundation";
    var channel = await youtube.Channels.GetByUserAsync(channelUrl);
    
    var id = channel.Id; // "UCSMOQeBJ2RAnuFungnQOxLg"
    

    To get the channel metadata by slug or legacy custom URL, use Channels.GetBySlugAsync(...):

    using YoutubeExplode;
    
    using var youtube = new YoutubeClient();
    
    var channelUrl = "https://youtube.com/c/BlenderFoundation";
    var channel = await youtube.Channels.GetBySlugAsync(channelUrl);
    
    var id = channel.Id; // "UCSMOQeBJ2RAnuFungnQOxLg"
    

    To get the channel metadata by handle or custom URL, use Channels.GetByHandleAsync(...):

    using YoutubeExplode;
    
    using var youtube = new YoutubeClient();
    
    var channelUrl = "https://youtube.com/@BlenderOfficial";
    var channel = await youtube.Channels.GetByHandleAsync(channelUrl);
    
    var id = channel.Id; // "UCSMOQeBJ2RAnuFungnQOxLg"
    
    Retrieving channel uploads

    To get the list of videos uploaded by a channel, call Channels.GetUploadsAsync(...):

    using YoutubeExplode;
    using YoutubeExplode.Common;
    
    using var youtube = new YoutubeClient();
    var channelUrl = "https://youtube.com/channel/UCSMOQeBJ2RAnuFungnQOxLg";
    
    var videos = await youtube.Channels.GetUploadsAsync(channelUrl);
    

    Search

    You can execute a search query by calling the Search.GetResultsAsync(...) method. Each search result may represent either a video, a playlist, or a channel, so you need to apply pattern matching to handle the corresponding cases:

    using YoutubeExplode;
    
    using 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 video:
            {
                var id = video.Id;
                var title = video.Title;
                var duration = video.Duration;
                break;
            }
            case PlaylistSearchResult playlist:
            {
                var id = playlist.Id;
                var title = playlist.Title;
                break;
            }
            case ChannelSearchResult channel:
            {
                var id = channel.Id;
                var title = channel.Title;
                break;
            }
        }
    }
    

    To limit the results to a specific type, use Search.GetVideosAsync(...), Search.GetPlaylistsAsync(...), or Search.GetChannelsAsync(...):

    using YoutubeExplode;
    using YoutubeExplode.Common;
    
    using 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;
    
    using 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:
                {
                    // ...
                }
            }
        }
    }
    

    Authentication

    You can access private videos and playlists by providing cookies that correspond to a pre-authenticated YouTube account. To do that, create an instance of YoutubeClient using a constructor that accepts IReadOnlyList<Cookie>:

    using YoutubeExplode;
    
    // Perform authentication and extract cookies
    var cookies = ...;
    
    // Cookie collection must be of type IReadOnlyList<System.Net.Cookie>
    using var youtube = new YoutubeClient(cookies);
    

    In order to actually perform the authentication, you can use an embedded browser such as WebView to navigate the user to the YouTube login page, let them log in, and then extract the cookies from the browser.

    Etymology

    The "Explode" in YoutubeExplode comes from the name of a PHP function that splits up strings, explode(...). When I was starting the development of this library, most of the reference source code I read was written in PHP, hence the inspiration for the name.