Skip to content

Commit

Permalink
Merge branch 'release/2.1.0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SKProCH committed Jan 15, 2021
2 parents 7bf02f2 + ca740f2 commit fb47318
Show file tree
Hide file tree
Showing 48 changed files with 1,394 additions and 143 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
env:
YandexProxy: ${{secrets.YANDEXPROXYURL}}
# - name: Test
# run: dotnet test --no-build --verbosity normal
# env:
# YandexProxy: ${{secrets.YANDEXPROXYURL}}
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
env:
YandexProxy: ${{secrets.YANDEXPROXYURL}}
# - name: Test
# run: dotnet test --no-build --verbosity normal
# env:
# YandexProxy: ${{secrets.YANDEXPROXYURL}}
publish:
needs: [build_and_test]
runs-on: ubuntu-latest
Expand Down
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<table align="center"><tr><td align="center" width="9999">
<img src="https://download.cdn.yandex.net/from/yandex.ru/support/ru/music/files/icon_main.png" align="center" alt="Project icon" height="150">

<h1 style="margin:-30px auto auto auto">YandexMusicResolver</h1>

A library aimed at searching, resolving and getting direct links to tracks, playlists or albums in Yandex.Music. Can work without authorization.
</td></tr>
</table>

## Getting started

<ol type="1">

<li>

Add [nuget package](https://www.nuget.org/packages/YandexMusicResolver/) to your project:

```
dotnet add package YandexMusicResolver
```
or
```
Install-Package YandexMusicResolver -Version 2.0.0
```
</li>

<li>

Create configuration instance (`FileYandexConfig` this is the default implementation to save the config to a file) :

```c#
var config = new FileYandexConfig("path to store config");
```
or use empty config (if you don't want save anything):
```c#
var config = new EmptyYandexConfig();
```
After that call `Load` to load config:
```c#
config.Load();
```
</li>

<li>

Create an instance of `YandexMusicMainResolver` and pass config to it
```c#
var yandexMusicMainResolver = new YandexMusicMainResolver(config);
```
After that we can use `YandexMusicMainResolver` methods and other loaders methods.
</li>

</ol>

Example code for getting direct track download url:
```c#
var fileYandexConfig = new FileYandexConfig("yandex.config");
fileYandexConfig.Load();
var yandexMusicMainResolver = new YandexMusicMainResolver(fileYandexConfig);
var directUrl = await yandexMusicMainResolver.DirectUrlLoader.GetDirectUrl("55561798", "mp3");
Console.WriteLine(directUrl);
```
**Warn:** 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).

Methods to assist with authorization can be found in `YandexMusicAuth`.

For additional examples you can take a look at unit test project.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v2.1.0
- Add public members documentation

# v2.0.0
- Add new config system
- Query parser in yandex searches now separated
Expand Down
3 changes: 2 additions & 1 deletion YandexMusicResolver.Tests/EnvironmentConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#nullable enable
using System;
using System.Net;
using YandexMusicResolver.Config;

Expand Down
5 changes: 1 addition & 4 deletions YandexMusicResolver.Tests/YandexMusicPlaylistLoaderTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Threading.Tasks;
using Xunit;
using Xunit;
using YandexMusicResolver.AudioItems;
using YandexMusicResolver.Loaders;

namespace YandexMusicResolver.Tests {
public class YandexMusicPlaylistLoaderTest : YandexTestBase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#nullable enable
using System;
using System.Runtime.InteropServices.ComTypes;
using Xunit;
using YandexMusicResolver.AudioItems;
using YandexMusicResolver.Loaders;

namespace YandexMusicResolver.Tests {
Expand Down Expand Up @@ -46,7 +43,9 @@ public void DoPlaylistSearch() {
[InlineData("")]
[InlineData("myprefix")]
public void TestPrefixes(string? prefix) {
#pragma warning disable 8625
var yandexMusicSearchResultLoader = new YandexMusicSearchResultLoader(null, prefix);
#pragma warning restore 8625
prefix ??= "ymsearch";
var correctQuery = $"{prefix}:playlist:25:take over";
Assert.True(yandexMusicSearchResultLoader.TryParseQuery(correctQuery, out var text1, out var type1, out var limit1));
Expand Down
1 change: 0 additions & 1 deletion YandexMusicResolver.Tests/YandexTestBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.IO;
using Xunit.Abstractions;
using YandexMusicResolver.AudioItems;
using YandexMusicResolver.Config;

Expand Down
14 changes: 9 additions & 5 deletions YandexMusicResolver/ApiResponceError.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
using System;
using System.Runtime.Serialization;
using YandexMusicResolver.Responces;

namespace YandexMusicResolver {
/// <summary>
/// Represents errors that returned from yandex api.
/// </summary>
[Serializable]
public class YandexApiResponseException : Exception {
/// <summary>
/// Contains info about error from yandex api
/// </summary>
public MetaError ApiMetaError { get; private set; }

/// <inheritdoc />
public YandexApiResponseException(MetaError apiMetaError) {
ApiMetaError = apiMetaError;
}

/// <inheritdoc />
public YandexApiResponseException(string message, MetaError apiMetaError) : base(message) {
ApiMetaError = apiMetaError;
}

protected YandexApiResponseException(
SerializationInfo info,
StreamingContext context) : base(info, context) { }
}
}
24 changes: 22 additions & 2 deletions YandexMusicResolver/AudioItems/YandexMusicPlaylist.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;

namespace YandexMusicResolver.AudioItems {
/// <summary>
/// Represents playlist from Yandex Music
/// </summary>
public class YandexMusicPlaylist : IAudioItem {
/// <summary>
/// Initializes a new instance of the <see cref="YandexMusicPlaylist"/> class.
/// </summary>
/// <param name="title">Playlist title</param>
/// <param name="tracks">Collection with tracks</param>
/// <param name="isSearchResult">Is this playlist is search result</param>
public YandexMusicPlaylist(string title, ReadOnlyCollection<YandexMusicTrack> tracks, bool isSearchResult) {
Title = title;
Tracks = tracks;
IsSearchResult = isSearchResult;
}

/// <summary>
/// Playlist title
/// </summary>
public string Title { get; }

/// <summary>
/// Collection with tracks in playlist
/// </summary>
public ReadOnlyCollection<YandexMusicTrack> Tracks { get; }

/// <summary>
/// Is this playlist a search result
/// </summary>
public bool IsSearchResult { get; }
}
}
31 changes: 29 additions & 2 deletions YandexMusicResolver/AudioItems/YandexMusicSearchResult.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Collections.ObjectModel;
using Newtonsoft.Json;
using YandexMusicResolver.Loaders;
using YandexMusicResolver.Responces;

namespace YandexMusicResolver.AudioItems {
/// <summary>
/// Represents YandexMusic search result
/// </summary>
public class YandexMusicSearchResult : IAudioItem {
public YandexMusicSearchResult(string query, int limit, YandexSearchType type, ReadOnlyCollection<MetaAlbumSignature>? albums,
ReadOnlyCollection<MetaPlaylistSignature>? playlists, ReadOnlyCollection<MetaTrack>? tracks) {
Expand All @@ -15,11 +16,37 @@ public YandexMusicSearchResult(string query, int limit, YandexSearchType type, R
Tracks = tracks;
}

/// <summary>
/// Search query text
/// </summary>
public string Query { get; }

/// <summary>
/// Tracks limit count
/// </summary>
public int Limit { get; }

/// <summary>
/// Search data type
/// </summary>
public YandexSearchType Type { get; }

/// <summary>
/// Albums list.
/// Will be <code>null</code> if the search should not search for albums
/// </summary>
public ReadOnlyCollection<MetaAlbumSignature>? Albums { get; set; }

/// <summary>
/// Playlists list.
/// Will be <code>null</code> if the search should not search for playlists
/// </summary>
public ReadOnlyCollection<MetaPlaylistSignature>? Playlists { get; set; }

/// <summary>
/// Tracks list.
/// Will be <code>null</code> if the search should not search for tracks
/// </summary>
public ReadOnlyCollection<MetaTrack>? Tracks { get; set; }
}
}
21 changes: 19 additions & 2 deletions YandexMusicResolver/AudioItems/YandexMusicTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,38 @@
using System.Threading.Tasks;

namespace YandexMusicResolver.AudioItems {
/// <summary>
/// AudioTrackInfo wrapper to resolve track direct url
/// </summary>
public class YandexMusicTrack : IAudioItem {
/// <summary>
/// Get track info
/// </summary>
public AudioTrackInfo TrackInfo { get; }

private YandexMusicMainResolver _mainResolver;
private readonly Lazy<Task<string>> _directUrlLoader;


/// <summary>
/// Initializes a new instance of the <see cref="YandexMusicTrack"/> class.
/// </summary>
/// <param name="trackInfo">Track info</param>
/// <param name="mainResolver">Resolver for direct url getting</param>
public YandexMusicTrack(AudioTrackInfo trackInfo, YandexMusicMainResolver mainResolver) {
_mainResolver = mainResolver;
TrackInfo = trackInfo;
_directUrlLoader = new Lazy<Task<string>>(GetDirectUrlInternal, LazyThreadSafetyMode.ExecutionAndPublication);
}

/// <summary>
/// Get direct url to track
/// </summary>
/// <remarks>If you not authorized will return 30s track version. This is YandexMusic restriction</remarks>
/// <returns>Direct url to download track</returns>
public Task<string> GetDirectUrl() {
return _directUrlLoader.Value;
}

private async Task<string> GetDirectUrlInternal() {
return await _mainResolver.DirectUrlLoader.GetDirectUrl(TrackInfo.Identifier, "mp3");
}
Expand Down
30 changes: 30 additions & 0 deletions YandexMusicResolver/AudioTrackInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,43 @@
using System.Collections.Generic;

namespace YandexMusicResolver {
/// <summary>
/// Contains info about track
/// </summary>
public class AudioTrackInfo {
/// <summary>
/// Track title
/// </summary>
public string Title { get; }

/// <summary>
/// Track author
/// </summary>
public string Author { get; }

/// <summary>
/// Track lenght
/// </summary>
public TimeSpan Length { get; }

/// <summary>
/// Track identifier
/// </summary>
public string Identifier { get; }

/// <summary>
/// Is track live stream
/// </summary>
public bool IsStream { get; }

/// <summary>
/// Track link
/// </summary>
public string Uri { get; }

/// <summary>
/// Additional track metadata
/// </summary>
public Dictionary<string, string> Metadata { get; }

public AudioTrackInfo(string title, string author, TimeSpan length, string identifier, bool isStream, string uri, Dictionary<string, string> metadata) {
Expand Down
20 changes: 14 additions & 6 deletions YandexMusicResolver/Config/EmptyYandexConfig.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
using System.Net;

namespace YandexMusicResolver.Config {
/// <summary>
/// Represents <see cref="IYandexConfig"/> implementation placeholder
/// </summary>
public class EmptyYandexConfig : IYandexConfig {
public void Load() {

}
/// <inheritdoc />
public void Load() { }

public void Save() {

}
/// <inheritdoc />
public void Save() { }

/// <inheritdoc />
public string? YandexLogin { get; set; }

/// <inheritdoc />
public string? YandexPassword { get; set; }

/// <inheritdoc />
public string? YandexToken { get; set; }

/// <inheritdoc />
public IWebProxy? YandexProxy { get; set; }
}
}
Loading

0 comments on commit fb47318

Please sign in to comment.