YandexMusicApi 2.0.4

dotnet add package YandexMusicApi --version 2.0.4
NuGet\Install-Package YandexMusicApi -Version 2.0.4
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="YandexMusicApi" Version="2.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add YandexMusicApi --version 2.0.4
#r "nuget: YandexMusicApi, 2.0.4"
#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.
// Install YandexMusicApi as a Cake Addin
#addin nuget:?package=YandexMusicApi&version=2.0.4

// Install YandexMusicApi as a Cake Tool
#tool nuget:?package=YandexMusicApi&version=2.0.4

YandexMusicApi

Cross-platform Yandex Music API for C#

Nuget API NET. Standard 2.0 PR-s welcome Follow in Mastodon Stars in GitLab

Description⚡

The YandexMusicApi library in C# allows for easy and convenient use of the Yandex.Music API to develop various music-related projects. It supports .NET Standard 2.0 and is available in a NuGet package that has been downloaded over 4,000 times.

With this library, developers can access a wide range of Yandex.Music API functions, such as searching for songs, albums, artists, playlists, obtaining track information, obtaining links for streaming playback, and more. All API functions are provided in a user-friendly and easy-to-use form.

In addition, this library is a fork of the original library written in Python by Marshal, which allows it to be used on C# for developing music projects.

The development of the library was based on the website of Alexandr Cherkashin, where the Yandex.Music API is presented in the form of OpenAPI.

Overall, the YandexMusicApi library in C# is a powerful tool for developing applications and projects related to music on the Yandex.Music platform.

How to install✨

Installation instructions for YandexMusicApi:

  1. Install the .NET Core SDK on your computer if it is not already installed. You can download it from the official website: https://dotnet.microsoft.com/download

  2. Open the terminal or command prompt on your computer.

  3. Enter the following command in the terminal or command prompt:

    • dotnet add package YandexMusicApi
  4. Wait for the installation to complete. After that, you can use the YandexMusicApi library in your C# project.

That's it! Now you can use the YandexMusicApi library to access the functions of the Yandex.Music API in your C# project.

Example of use🍏

Let's look at examples of using the library😁

Receiving a token

All logic will be written in the comments, see there 😃. For now there is a two-factor authorization only by SMS

public static async Task Main()
{
   NetworkParams networkParams = new NetworkParams() { }; // Creating an object of class NetworkParams, if necessary you can specify there proxy and UserAgent to use in requests.
   Token tokenObject = new Token("Login", "Password", networkParams);
   var result = await tokenObject.LoginUsername(); // Send Username to get authorization options

   if (result.Data["preferred_auth_method"].ToString() == "password") // If the best authorization option is a password
   {
       result = await tokenObject.LoginPassword(); // Starting authorization by password
       if (result.Data["errors"][0].ToString().Trim() == "redirect") // If you have two-factor authorization enabled
       {
           result = await tokenObject.CheckChallenge(); // Checking what Yandex needs for authorization
           if (result.Data["challenge"]["challengeType"].ToString().Trim() == "phone_confirmation") // If Yandex needs an SMS to confirm authorization
           {
               string phoneId = result.Data["challenge"]["phoneId"].ToString(); // Get phoneId to receive sms later
               result = await tokenObject.ValidatePhoneById(phoneId); // Check the received phoneId
               if (result.Data["status"].ToString().Trim() == "ok") // If all is well
               {
                   await tokenObject.PhoneConfirmCodeSubmit(phoneId); // Sending sms to phone

                   Console.WriteLine("Write SMS code");
                   string smsCode = Console.ReadLine();

                   await tokenObject.PhoneConfirmCode(smsCode); // Send the code to Yandex
                   result = await tokenObject.ChallengeCommit("phone_confirmation"); // Talking to Yandex about the end of two-factor authentication
                   var token = await tokenObject.GetToken(result.Data["retpath"].ToString()); // Getting a token

                   Console.WriteLine(token);
               }
           }
       }
   }
}

Get a direct link to a demo track of the top 3 tracks from the Evolve - Imagine Dragons album (30 second segment). All the logic of the work in the comments

public static void Main()
{
   NetworkParams networkParams = new NetworkParams() { };
   Album albumApi = new Album(networkParams);
   Track trackApi = new Track(networkParams);

   var bestsTrack = albumApi.GetTracks(5568718).Result["result"]["bests"].ToList(); // Get the top 5 tracks from the Evolve - Imagine Dragons album
   foreach (var i in bestsTrack)
   {
       var downloadInfo = trackApi.GetDownloadInfo(i.ToString()).Result; // Get a list of available codecs and bitrates
       var downloadInfoUrl = downloadInfo["result"][0]["downloadInfoUrl"].ToString(); // Get the necessary string to get a direct link to the track
       var directLink = trackApi.GetDirectLink(downloadInfoUrl).Result; // Getting a direct link to the track (30 second demo)
       Console.WriteLine(directLink);
   }
}

An example with album search for your search query and parsing the API output. All logic in the comments

public static void Main()
{
   NetworkParams networkParams = new NetworkParams() { };
   Default defaultApi = new Default(networkParams);

   Console.Write("Enter your search term: ");
   var searchRequest = Console.ReadLine();
   var searchResult = defaultApi.Search(searchRequest, typeSearch: "album").Result["result"]["albums"]["results"]; // Send a search query with a selection of albums from page 1 of the output and select from there the data for subsequent parsing
   foreach (var i in searchResult)
   {
       Console.WriteLine($"Title: {i["title"]}\nArtist: {i["artists"][0]["name"]}\nAlbum image link: {"https://" + i["coverUri"].ToString().Replace("%%", "100x100")}\n");
   }
}

Documentation

There is no online documentation for this project yet. But the documentation is in the code itself, you can look there😉

Community

My channel on Telegram: https://t.me/kirmozorChannel

There is also a mirror in the Mastodon: https://mastodon.social/@kirmozor

We also have a chat room, the link is in the attached message of the channel😁

Sponsors

This project is sponsored by JetBrains and GitLab. Thanks to them, I have a license for the IDE and all the features of GitLab Ultimate🙂

Helping the channel and development

If you want to help this project as well as my channels, the details are below:

  • Ton - UQAt_Dl_TAOCJVe09oXMS1XeMHz2DXX2JrCdA0cSyJaCRd1Q
  • Btc - 1CNBs7r8NpwvZXanw5fx7h6ggrBwGzZVkS
  • Tether (TRC20) - TDskFXZUFG3UCvAmaCxkdtyudWzYs5t7yf
  • Tether (BEP20) - 0x51d5a4530670d81a2382edf266f4d5975e83d377
  • BNB (BEP20) - 0x51d5a4530670d81a2382edf266f4d5975e83d377
  • Visa - 4400430240807740
Product 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. 
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
2.0.4 354 8/1/2023
2.0.2 142 6/19/2023
2.0.0 127 6/8/2023
1.2.6 139 6/8/2023
1.2.4 1,184 7/19/2022
1.2.2 429 7/10/2022
1.2.0 480 7/1/2022
1.1.8 402 6/30/2022
1.1.6 407 6/30/2022
1.1.4 393 6/30/2022
1.1.2 398 6/29/2022
1.1.0 390 6/29/2022
1.0.8 404 6/25/2022
1.0.6 406 6/14/2022
1.0.4 406 5/29/2022
1.0.2 398 5/15/2022