YouTubeMusicAPI 3.0.0
See the version list below for details.
dotnet add package YouTubeMusicAPI --version 3.0.0
NuGet\Install-Package YouTubeMusicAPI -Version 3.0.0
<PackageReference Include="YouTubeMusicAPI" Version="3.0.0" />
<PackageVersion Include="YouTubeMusicAPI" Version="3.0.0" />
<PackageReference Include="YouTubeMusicAPI" />
paket add YouTubeMusicAPI --version 3.0.0
#r "nuget: YouTubeMusicAPI, 3.0.0"
#:package YouTubeMusicAPI@3.0.0
#addin nuget:?package=YouTubeMusicAPI&version=3.0.0
#tool nuget:?package=YouTubeMusicAPI&version=3.0.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 access to an authenticated user's library, all with minimal effort.
⚠️ Major Update in Progress: v4 Recode
A complete overhaul of YouTubeMusicAPI is currently underway!
Originally, this library wasn’t intended to be a fully-fledged API wrapper for YouTube Music. My goal was only to implement basic search functionality so I could add yet another platform to my multi-music downloader, Melora.
This recode is my effort to turn YouTubeMusicAPI into a clean, consistent, and fully-featured API wrapper that does justice to everything YouTube Music has to offer - including library management, more detailed information, playback support, and explore endpoints - all while improving performance, efficiency, and code maintainability.
📌 You can track development progress in the
recode
branch and view planned features in the Project Board.
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, visitorData, poToken, cookies);
Usage
Search
// Search for songs directly
PaginatedAsyncEnumerable<SearchResult> searchResults = client.SearchAsync(query, SearchCategory.Songs);
IReadOnlyList<SearchResult> bufferedSearchResults = await searchResults.FetchItemsAsync(0, 20);
foreach (SongSearchResult song in bufferedSearchResults.Cast<SongSearchResult>())
Console.WriteLine($"{song.Name}, {string.Join(", ", song.Artists.Select(artist => artist.Name))} - {song.Album.Name}");
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);
Console.WriteLine($"{info.Name}, {info.SongCount} songs, {info.Description}");
// Community Playlist Songs
PaginatedAsyncEnumerable<CommunityPlaylistSong> playlistSongs = client.GetCommunityPlaylistSongsAsync(browseId);
IReadOnlyList<CommunityPlaylistSong> bufferedPlaylistSongs = await playlistSongs.FetchItemsAsync(0, 20);
foreach (CommunityPlaylistSongInfo song in bufferedPlaylistSongs)
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
In some cases (e.g. when using cookie authentication), getting streaming URLs requires deciphering. Sometimes, YouTube also enforces a "Proof of Origin Token" (PoToken), which is generated by an Anti-Bot-System.
PoToken generation requires JavaScript execution and a full DOM, which isn't feasible in a pure .NET environment. While JavaScript execution can be handled using interpreters like Jint, a full browser engine (e.g. Puppeteer, CefSharp) is required to generate the token.
To avoid this, PoTokens are not automatically generated by this library. However, you can manually provide a valid token using the YouTubeMusicClient
constructor when necessary. For more details on PoTokens and how to generate them, check out this guide.
⚠️ Note:
It may occurr that you get a
403 Forbidden
error when trying to get streaming data. This is usually caused by YouTube flagging your IP-Address as suspicious, e.g. when using a VPN or spaming the API in the past.You are then required to provide cookie authentication and a poToken to testify your request "comes from a valid client".
// 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>()
.OrderByDescending(info => info.Bitrate)
.First();
Stream stream = await highestAudioStreamInfo.GetStreamAsync();
using FileStream fileStream = new("audio.m4a", FileMode.Create, FileAccess.Write);
await stream.CopyToAsync(fileStream);
Access to a user's library
In order to access a user's library you first need to authenticate the user by using pre-authenticated cookies.
To obtain the necessary cookies, you'll need to present the official YouTube Music login page to your users. You could use an embedded browser like WebView2 in your application and then extract the cookies for the site ".youtube.com".
// Get saved/created community playlists
IEnumerable<LibraryCommunityPlaylist> communityPlaylists = await client.GetLibraryCommunityPlaylistsAsync();
foreach (LibraryCommunityPlaylist playlist in communityPlaylists)
Console.WriteLine($"{playlist.Name}, {playlist.SongCount} songs");
// Get saved songs
IEnumerable<LibrarySong> songs = await client.GetLibrarySongsAsync();
foreach (LibrarySong song in songs)
Console.WriteLine($"{song.Name}, {string.Join(", ", song.Artists.Select(artist => artist.Name))} - {song.Album.Name}");
// Get saved albums
IEnumerable<LibraryAlbum> albums = await client.GetLibraryAlbumsAsync();
foreach (LibraryAlbum album in albums)
Console.WriteLine($"{album.Name}, {album.ReleaseYear}");
// Get artists with saved songs
IEnumerable<LibraryArtist> artists = await client.GetLibraryArtistsAsync();
foreach (LibraryArtist artist in artists)
Console.WriteLine($"{artist.Name}, {artist.SongCount} saved songs");
// Get subscribed artists
IEnumerable<LibrarySubscription> subscriptions = await client.GetLibrarySubscriptionsAsync();
foreach (LibrarySubscription subscription in subscriptions)
Console.WriteLine($"{subscription.Name}, {subscription.SubscribersInfo}");
// Get saved podcasts
IEnumerable<LibraryPodcast> podcasts = await client.GetLibraryPodcastsAsync();
foreach (LibraryPodcast podcast in podcasts)
Console.WriteLine($"{podcast.Name}, {podcast.Host.Name}");
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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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
- Jint (>= 4.4.1)
- Microsoft.Bcl.AsyncInterfaces (>= 9.0.7)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.7)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on YouTubeMusicAPI:
Repository | Stars |
---|---|
TypNull/Tubifarry
Tubifarry is a Lidarr plugin that enhances your music library by fetching music from YouTube, integrating with Slskd for Soulseek access, automating Spotify playlist imports, converting files, and retrieving soundtracks from Radarr and Sonarr.
|
Version | Downloads | Last Updated |
---|---|---|
3.0.3-alpha | 141 | 6/2/2025 |
3.0.2-alpha | 192 | 4/29/2025 |
3.0.1-alpha | 190 | 4/14/2025 |
3.0.0 | 95 | 7/29/2025 |
3.0.0-alpha | 128 | 4/13/2025 |
2.2.8 | 374 | 4/3/2025 |
2.2.7 | 151 | 3/28/2025 |
2.2.6 | 185 | 3/1/2025 |
2.2.5 | 114 | 2/25/2025 |
2.2.4 | 114 | 2/23/2025 |
2.2.3 | 117 | 2/21/2025 |
2.2.2 | 170 | 2/14/2025 |
2.2.1 | 115 | 2/7/2025 |
2.2.0 | 218 | 1/11/2025 |
2.1.1 | 206 | 1/5/2025 |
2.1.0 | 157 | 1/1/2025 |
2.0.0 | 168 | 12/21/2024 |
1.3.1 | 163 | 9/29/2024 |
1.3.0 | 168 | 8/13/2024 |
1.2.0 | 137 | 8/11/2024 |
1.1.4 | 141 | 7/20/2024 |
1.1.3 | 126 | 7/14/2024 |
1.1.2 | 138 | 7/4/2024 |
1.1.1 | 139 | 7/4/2024 |
1.1.0 | 137 | 7/4/2024 |
1.0.1 | 137 | 6/5/2024 |
1.0.0 | 125 | 6/5/2024 |
CONTAINS BREAKING CHANGES, PLEASE READ RELEASE NOTES
- Introduced pagination system:
- PaginatedAsyncEnumerable
- Removed “Shelves” to search
- Introduced ability to get 100+ songs for playlists (Fix #10)
- Introduced ability to get infinite songs for auto generated playlists (e.g. radios)
- Project restructue:
- Removed YouTubeMusicItem & IYouTubeMusicItem
- Added NamedEntity base model
- Added base classes for models (SearchResult, LibraryEntity, EntityInfo)
- New cleaner namespaces
- Renamed classes:
- Removed "Info" suffix for info sub-models (e.g. AlbumSongInfo -> AlbumSong)
- MediaStreamInfo -> StreamInfo
- MediaContainer -> StreamContainer
- YouTubeMusicItemKind -> SearchCategory
- Added "IsInfinite" property to CommunityPlaylistInfo
- Introduced ability to set custom HttpClient for requests
- Fixed n-sig deciphering for getting streaming data when authenticated (Fix #19)
- Fixed sig deciphering for getting streaming data
- Optimized getting streaming data when authenticated
- Improved JS parsing performance for getting streaming data
- Fixed Video-Search not being fully implemented
- Fixed various Video-Search parsing issues
- Updated packages
A complete overhaul of YouTubeMusicAPI is currently underway!
You can track development progress in the recode branch (https://github.com/IcySnex/YouTubeMusicAPI/tree/recode) and view planned features in the Project Board (https://github.com/users/IcySnex/projects/1).
This is a mid-way update.