A library aimed at searching, resolving and getting direct links to tracks, playlists or albums in Yandex.Music.
Can work without authorization.
-
Add nuget package to your project:
dotnet add package YandexMusicResolver
-
You need somehow to instantiate
YandexMusicMainResolver
.- If you are using dependency injection, use
.AddYandexMusicResolver()
to yourIServiceCollection
. E.g.:var serviceCollection = new ServiceCollection(); serviceCollection.AddYandexMusicResolver(); var serviceProvider = serviceCollection.BuildServiceProvider(); // Resolve the IYandexMusicMainResolver var yandexMusicMainResolver = serviceProvider.GetRequiredService<IYandexMusicMainResolver>();
- Or instantiate it as usually:
-
Create auth service instance (
YandexMusicAuthService
this is the default implementation):var authService = new YandexMusicAuthService(httpClient);
Actually, preferred way is to use
IHttpClientFactory
to pass it to all services. If you useIHttpClientFactory
default HttpClient name isYandexMusic
. -
Create credentials provider instance (
YandexCredentialsProvider
this is the default implementation):var credentialProvider = new YandexMusicAuthService(authService, "Login", "Pass");
-
Create an instance of
YandexMusicMainResolver
and pass config to itvar yandexMusicMainResolver = new YandexMusicMainResolver(credentialProvider, httpClient);
var httpClient = new HttpClient(); var authService = new YandexMusicAuthService.Create(httpClient); var credentialProvider = new YandexMusicAuthService.Create(authService, "Login", "Pass"); var yandexMusicMainResolver = new YandexMusicMainResolver.Create(credentialProvider, httpClient);
-
- If you are using dependency injection, use
-
After that you can use different methods and properties of
IYandexMusicMainResolver
. Example code for getting direct track download url:var directUrl = await yandexMusicMainResolver.DirectUrlLoader.GetDirectUrl("55561798"); Console.WriteLine(directUrl);
[!IMPORTANT]
Yandex will return a link to a 30-seconds track if you do not log in (do not use a config with a valid token).
You can take a look at unit test project for additional examples.