SecretLabNAudio.YouTube 1.0.0

dotnet add package SecretLabNAudio.YouTube --version 1.0.0
                    
NuGet\Install-Package SecretLabNAudio.YouTube -Version 1.0.0
                    
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="SecretLabNAudio.YouTube" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SecretLabNAudio.YouTube" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SecretLabNAudio.YouTube" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SecretLabNAudio.YouTube --version 1.0.0
                    
#r "nuget: SecretLabNAudio.YouTube, 1.0.0"
                    
#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.
#:package SecretLabNAudio.YouTube@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SecretLabNAudio.YouTube&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SecretLabNAudio.YouTube&version=1.0.0
                    
Install as a Cake Tool

SecretLabNAudio.YouTube

This module extends SecretLabNAudio to provide YouTube-based utilities.

SecretLabNAudio is not sponsored nor endorsed by NAudio. SecretLabNAudio.YouTube is not sponsored nor endorsed by YouTube.

This library has a number of open-source dependencies. See Attributions

Installation

  1. Install SecretLabNAudio.FFmpeg version 2.1.2 or higher
    • Choose the single-file installation, or install the FFmpeg module
  2. Download the SecretLabNAudio.YouTube.dll file from the releases page
  3. Download the dependencies.zip file from the releases page
  4. Extract the DLLs from the bin/ folder of the dependencies.zip archive to the dependencies directory
    • Linux: ~/.config/SCP Secret Laboratory/LabAPI/dependencies/<port>/
    • Windows: %appdata%/SCP Secret Laboratory/LabAPI/dependencies/<port>/
  5. Place the SecretLabNAudio.YouTube.dll file into the plugins directory
    • Linux: ~/.config/SCP Secret Laboratory/LabAPI/plugins/<port>/
    • Windows: %appdata%/SCP Secret Laboratory/LabAPI/plugins/<port>/
  6. Restart the server

If you would like to use the demo plugin as well, download the SecretLabNAudio.YouTube.Demo.dll file and place it in the plugins directory.

Plugins Dependencies
SecretLabNAudio.YouTube SecretLabNAudio.YouTube.Demo (optional) AngleSharp System.Text.Encoding.CodePages System.Text.Encodings.Web YoutubeExplode

Development

Simply install the SecretLabNAudio.YouTube package from NuGet. It will automatically install dependencies in the project.

Usage

To simply play a YouTube video, call the UseYouTube extension method.

<details> <summary>Example</summary>

using SecretLabNAudio.Core.Extensions;
using SecretLabNAudio.Core.Pools;
using SecretLabNAudio.YouTube.Extensions;

AudioPlayerPool.RentGloballyAudible()
    .WithVolume(0.5f)
    .UseYouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ") // implicit conversion
    .PoolOnEnd();

</details>

If you want more control over the audio processor, call a method from the CreateYouTubeProcessor class.

Caching

If playing the same video multiple times, it's not ideal to wait for several seconds for YoutubeExplode to be able to resolve the stream.

The YouTubeCache class provides methods to asynchronously cache audio from YouTube videos.

<details> <summary>Example</summary>

Cache the videos you want:

using SecretLabNAudio.FFmpeg.Caches;
using SecretLabNAudio.FFmpeg.Extensions;
using SecretLabNAudio.YouTube.Caches;
using UnityEngine;
using Logger = LabApi.Features.Console.Logger;

// plugin class
public override void Enable()
{
    _ = CacheOrLogAsync("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
    _ = CacheOrLogAsync("https://youtu.be/eR8VEqaaWY8"); // short links work, too
    _ = CacheOrLogAsync("WX9miGKXyrw"); // video ID only
}

private static async Awaitable CacheOrLogAsync(string videoIdOrUrl)
{
    var (_, error) = await YouTubeCache.Shared.CacheIfNotCachedAsync(videoIdOrUrl, OptimizeFor.FileSize);
    if (error is not null)
        Logger.Error($"Failed caching {videoIdOrUrl}: {error.ToHumanReadableString()}");
}

Play a cached video (fallback to YouTube processor if not cached):

using SecretLabNAudio.YouTube.Extensions;

const string url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";

audioPlayer.UseCachedYouTube(url);

The above code basically does this:

using SecretLabNAudio.Core.Extensions;
using SecretLabNAudio.YouTube.Caches;
using SecretLabNAudio.YouTube.Extensions;
using YoutubeExplode.Videos;

// throws on invalid ID
var videoId = VideoId.Parse("https://www.youtube.com/watch?v=dQw4w9WgXcQ");

if (YouTubeCache.Shared.TryGetPath(videoId, out var cachedPath))
    audioPlayer.UseFile(cachedPath);
else
    audioPlayer.UseYouTube(videoId);

</details>

When caching videos based on user input, caches might take up a lot of disk space. You can query the metadata/streams of the video, and decide if it should be skipped due to the video being too long or the original stream's size being too large.

Playlists

You can add YouTube videos to a LazyPlaylist with extension methods.

<details> <summary>Example</summary>

audioPlayer.UsePlaylist(playlist => 
{
    // use cached version if possible
    playlist.AddCachedYouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
        .AddCachedYouTube("https://youtu.be/eR8VEqaaWY8");
    playlist.CurrentItemChanged += BroadcastNowPlaying;
});

</details>

The CurrentVideoId and CurrentVideo extension properties return adequate data if the current item is known to be a YouTube video.

The RemainingVideoIds and RemainingVideos extension properties filter the remaining items and return the known data.

Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 113 9/21/2026