YouTubeMusicAPI 1.1.1
See the version list below for details.
dotnet add package YouTubeMusicAPI --version 1.1.1
NuGet\Install-Package YouTubeMusicAPI -Version 1.1.1
<PackageReference Include="YouTubeMusicAPI" Version="1.1.1" />
paket add YouTubeMusicAPI --version 1.1.1
#r "nuget: YouTubeMusicAPI, 1.1.1"
// Install YouTubeMusicAPI as a Cake Addin #addin nuget:?package=YouTubeMusicAPI&version=1.1.1 // Install YouTubeMusicAPI as a Cake Tool #tool nuget:?package=YouTubeMusicAPI&version=1.1.1
YouTubeMusicAPI is a simple and efficient wrapper for the internal YouTube Music Web API for dotnet & C# developers. This library allows you to easily search for songs, videos, albums, community playlists, artists, podcasts, podcast episodes & profiles on YouTube Music.
Installation
To install YouTubeMusicAPI, add the following package to your project:
dotnet add package YouTubeMusicAPI
Usage
Search
// Search for items directly
YouTubeMusicClient client = new();
IEnumerable<IShelfItem> searchResults = await client.SearchAsync<IShelfItem>(query);
foreach (IShelfItem item in searchResults)
Console.WriteLine($"{item.Kind}: {item.Name} - {item.Id}");
// Search for shelves
YouTubeMusicClient client = new();
IEnumerable<Shelf> shelves = await client.SearchAsync(query, null);
foreach (Shelf shelf in shelves)
{
Console.WriteLine($"{shelf.Kind} - Query: {shelf.Query}, Params: {shelf.Params}");
foreach (IShelfItem item in shelf.Items)
Console.WriteLine($"{item.Kind}: {item.Name} - {item.Id}");
}
Search for specific item only (songs, videos, albums, community playlists, artists, podcasts, podcast episodes profiles)
// Search for songs directly
YouTubeMusicClient client = new();
IEnumerable<Song> searchResults = await client.SearchAsync<Song>(query);
foreach (Song song in searchResults)
Console.WriteLine($"{song.Name}, {string.Join(", ", song.Artists.Select(artist => artist.Name))} - {song.Album.Name}");
// Search for the songs shelves
YouTubeMusicClient client = new();
IEnumerable<Shelf> shelves = await client.SearchAsync(query, ShelfKind.Songs);
foreach (Shelf shelf in shelves)
{
Console.WriteLine($"{shelf.Kind}: Query-{shelf.Query}, Params-{shelf.Params}");
foreach (IShelfItem item in shelf.Items)
{
Song song = (Song)item;
Console.WriteLine($"{song.Name}, {string.Join(", ", song.Artists.Select(artist => artist.Name))} - {song.Album.Name}");
}
}
Get information about a song/video, album, community playlist & artist
// Song/Video
YouTubeMusicClient client = new();
SongVideoInfo info = await client.GetSongVideoInfoAsync(id);
Console.WriteLine($"{info.Name}, {string.Join(", ", info.Artists.Select(artist => artist.Name))} - {info.Description}");
// Album
YouTubeMusicClient client = new();
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
YouTubeMusicClient client = new();
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
YouTubeMusicClient client = new();
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}");
Shelves
In the usage samples you may have noticed there are two ways to search for something via this Wrapper - directly for the items or the "shelf".
But what is a shelf? The internal YouTube Music API returns so called "shelves" when searching. A shelf is like a container for search results like songs, videos etc.
Each shelf has a kind which says what items it contains for example "Songs". A Shelf is also connected to the sent request so it contains properties like "Query" or "Params" which help identify the initial request used for the search.
If all of this sounds kind of useless to you, dont worry! You can just use the search method with a generic type SearchAsync<IShelfItem>()
instead.
This handles all the shelf stuff in the background and returns a list of all your search results.
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. |
.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.
- Fixed typo which caused YouTubeMusicClient-GetCommunityPlaylistBrowseId to return invalid browse id