YouTubeMusicAPI 2.1.0
See the version list below for details.
dotnet add package YouTubeMusicAPI --version 2.1.0
NuGet\Install-Package YouTubeMusicAPI -Version 2.1.0
<PackageReference Include="YouTubeMusicAPI" Version="2.1.0" />
paket add YouTubeMusicAPI --version 2.1.0
#r "nuget: YouTubeMusicAPI, 2.1.0"
// Install YouTubeMusicAPI as a Cake Addin #addin nuget:?package=YouTubeMusicAPI&version=2.1.0 // Install YouTubeMusicAPI as a Cake Tool #tool nuget:?package=YouTubeMusicAPI&version=2.1.0
YouTubeMusicAPI is a simple and efficient C# wrapper for the YouTube Music Web API, enabling easy search and retrieval of songs, videos, albums, artists, podcasts, and more. It also provides streaming data and URLs, all with minimal effort.
Getting Started
To install YouTubeMusicAPI, add the following package to your project:
dotnet add package YouTubeMusicAPI
To start using YouTube Music in your project, just create a new YouTubeMusicClient
.
YouTubeMusicClient client = new(logger, geographicalLocation, cookies);
Usage
Search
Using this wrapper, you can search in two ways: directly for items or via "shelves." A shelf is a container for search results like songs or videos. Each shelf has a type (e.g., "Songs") and a "Next Continuation Token" to load more results dynamically (e.g., for infinite scrolling on a page).
If this seems complicated, no worries! You can simply use the search method with a generic type SearchAsync<IYouTubeMusicItem>()
instead, which also contains a property to limit the search result so you dont have to deal with any of the shelf or token stuff.
// Search for songs directly
IEnumerable<SongSearchResult> searchResults = await client.SearchAsync<SongSearchResult>(query);
foreach (SongSearchResult song in searchResults)
Console.WriteLine($"{song.Name}, {string.Join(", ", song.Artists.Select(artist => artist.Name))} - {song.Album.Name}");
// Search for the songs using shelves
IEnumerable<Shelf> shelves = await client.SearchAsync(query, null, YouTubeMusicItemKind.Songs);
foreach (Shelf shelf in shelves)
{
Console.WriteLine($"{shelf.Kind}: Next Continuation Token-{shelf.NextContinuationToken}");
foreach (IYouTubeMusicItem item in shelf.Items)
{
SongSearchResult song = (SongSearchResult)item;
Console.WriteLine($"{song.Name}, {string.Join(", ", song.Artists.Select(artist => artist.Name))} - {song.Album.Name}");
}
}
// Search for all kinds directly
IEnumerable<IYouTubeMusicItem> searchResults = await client.SearchAsync<IYouTubeMusicItem>(query, limit);
foreach (IYouTubeMusicItem item in searchResults)
Console.WriteLine($"{item.Kind}: {item.Name} - {item.Id}");
// Search for shelves including all kinds
IEnumerable<Shelf> shelves = await client.SearchAsync(query, null, null);
foreach (Shelf shelf in shelves)
{
Console.WriteLine($"{shelf.Kind}: Next Continuation Token-{shelf.NextContinuationToken}");
foreach (IYouTubeMusicItem item in shelf.Items)
Console.WriteLine($"{item.Kind}: {item.Name} - {item.Id}");
}
Getting more information
// Song/Video
SongVideoInfo info = await client.GetSongVideoInfoAsync(id);
Console.WriteLine($"{info.Name}, {string.Join(", ", info.Artists.Select(artist => artist.Name))} - {info.Description}");
// Album
string browseId = await client.GetAlbumBrowseIdAsync(id);
AlbumInfo info = await client.GetAlbumInfoAsync(browseId);
foreach (AlbumSongInfo song in info.Songs)
Console.WriteLine($"{song.Name}, {song.SongNumber}/{info.SongCount}");
// Community Playlist
string browseId = client.GetCommunityPlaylistBrowseId(id);
CommunityPlaylistInfo info = await client.GetCommunityPlaylistInfoAsync(browseId);
foreach (CommunityPlaylistSongInfo song in info.Songs)
Console.WriteLine($"{song.Name}, {string.Join(", ", song.Artists.Select(artist => artist.Name))} - {song.Album?.Name}");
// Artist
ArtistInfo info = await client.GetArtistInfoAsync(id);
foreach (ArtistSongInfo song in info.Songs)
Console.WriteLine($"{song.Name}, {string.Join(", ", song.Artists.Select(artist => artist.Name))} - {song.Album?.Name}");
Streaming & Downloading
// Getting streaming data of a song
StreamingData streamingData = await client.GetStreamingDataAsync(id);
Console.WriteLine($"Expires in: {streamingData.ExpiresIn}");
Console.WriteLine($"Hls Manifest URL: {streamingData.HlsManifestUrl}");
foreach(MediaStreamInfo streamInfo in streamingData.StreamInfo)
{
if (streamInfo is VideoStreamInfo videoStreamInfo)
Console.WriteLine($"Video ({videoStreamInfo.Quality}): {videoStreamInfo.Url}");
else if (streamInfo is AudioStreamInfo audioStreamInfo)
Console.WriteLine($"Audio ({audioStreamInfo.SampleRate}): {audioStreamInfo.Url}");
}
// Download highest quality audio stream
StreamingData streamingData = await client.GetStreamingDataAsync(id);
MediaStreamInfo highestAudioStreamInfo = streamingData.StreamInfo
.OfType<AudioStreamInfo>()
.OrderBy(info => info.Bitrate)
.First();
Stream stream = await highestAudioStreamInfo.GetStreamAsync();
using FileStream fileStream = new("audio.m4a", FileMode.Create, FileAccess.Write);
await stream.CopyToAsync(fileStream);
License
This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.
Contact
For questions, suggestions or problems, please open an issue with a detailed description.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. 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. |
-
.NETStandard 2.0
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Newtonsoft.Json (>= 13.0.3)
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 |
---|---|---|
2.2.3 | 33 | 2/21/2025 |
2.2.2 | 93 | 2/14/2025 |
2.2.1 | 78 | 2/7/2025 |
2.2.0 | 176 | 1/11/2025 |
2.1.1 | 179 | 1/5/2025 |
2.1.0 | 127 | 1/1/2025 |
2.0.0 | 144 | 12/21/2024 |
1.3.1 | 144 | 9/29/2024 |
1.3.0 | 153 | 8/13/2024 |
1.2.0 | 121 | 8/11/2024 |
1.1.4 | 128 | 7/20/2024 |
1.1.3 | 114 | 7/14/2024 |
1.1.2 | 126 | 7/4/2024 |
1.1.1 | 121 | 7/4/2024 |
1.1.0 | 126 | 7/4/2024 |
1.0.1 | 125 | 6/5/2024 |
1.0.0 | 115 | 6/5/2024 |
-Introduced ability to add custom cookies for authentication