SecretLabNAudio.YouTube
1.0.0
dotnet add package SecretLabNAudio.YouTube --version 1.0.0
NuGet\Install-Package SecretLabNAudio.YouTube -Version 1.0.0
<PackageReference Include="SecretLabNAudio.YouTube" Version="1.0.0" />
<PackageVersion Include="SecretLabNAudio.YouTube" Version="1.0.0" />
<PackageReference Include="SecretLabNAudio.YouTube" />
paket add SecretLabNAudio.YouTube --version 1.0.0
#r "nuget: SecretLabNAudio.YouTube, 1.0.0"
#:package SecretLabNAudio.YouTube@1.0.0
#addin nuget:?package=SecretLabNAudio.YouTube&version=1.0.0
#tool nuget:?package=SecretLabNAudio.YouTube&version=1.0.0
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
- Install SecretLabNAudio.FFmpeg version 2.1.2 or higher
- Choose the single-file installation, or install the
FFmpegmodule
- Choose the single-file installation, or install the
- Download the
SecretLabNAudio.YouTube.dllfile from the releases page - Download the
dependencies.zipfile from the releases page - Extract the DLLs from the
bin/folder of thedependencies.ziparchive to the dependencies directory- Linux:
~/.config/SCP Secret Laboratory/LabAPI/dependencies/<port>/ - Windows:
%appdata%/SCP Secret Laboratory/LabAPI/dependencies/<port>/
- Linux:
- Place the
SecretLabNAudio.YouTube.dllfile into the plugins directory- Linux:
~/.config/SCP Secret Laboratory/LabAPI/plugins/<port>/ - Windows:
%appdata%/SCP Secret Laboratory/LabAPI/plugins/<port>/
- Linux:
- 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>
See also: YoutubeExplode examples demo project
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net48 is compatible. net481 was computed. |
-
.NETFramework 4.8
- SecretLabNAudio.FFmpeg (>= 2.1.2)
- YoutubeExplode (>= 6.6.2)
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 |