Skip to content

Commit

Permalink
Merge branch 'release/2.2.0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SKProCH committed Jan 28, 2021
2 parents fb47318 + 225f698 commit 5f14657
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
with:
PROJECT_FILE_PATH: YandexMusicResolver/YandexMusicResolver.csproj
NUGET_KEY: ${{secrets.NUGETAPIKEY}}
NUGET_SOURCE: https://api.nuget.org/v3
THOW_ERROR_IF_VERSION_EXISTS: false
- name: Publish Github Packages
uses: Rebel028/[email protected]
Expand Down
8 changes: 8 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v2.2.0
- Add ArtworkUrl to TrackInfo and mark Metadata obsolete, mark IsStream obsolete
- Add default codec to GetDirectUrl
- Remove unnecessary albumId from track loader
- Album load method now actually called LoadAlbum
- Make meta json properties private, classes internal
- Make YandexMusicMainResolver DI suitable

# v2.1.0
- Add public members documentation

Expand Down
2 changes: 1 addition & 1 deletion YandexMusicResolver.Tests/YandexTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public YandexTestBase() {
}

Config.Load();
MainResolver = new YandexMusicMainResolver(Config);
MainResolver = new YandexMusicMainResolver(Config, true);
TrackFactory = info => new YandexMusicTrack(info, MainResolver);
}
}
Expand Down
24 changes: 24 additions & 0 deletions YandexMusicResolver/AudioTrackInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class AudioTrackInfo {
/// <summary>
/// Is track live stream
/// </summary>
[Obsolete("There is no streams support in library. \nWill removed in 3.0")]
public bool IsStream { get; }

/// <summary>
Expand All @@ -39,8 +40,14 @@ public class AudioTrackInfo {
/// <summary>
/// Additional track metadata
/// </summary>
[Obsolete("Metadata used only for image uri storing. Use ArtworkUrl property instead. \nWill be removed in 3.0")]
public Dictionary<string, string> Metadata { get; }

/// <summary>
/// Track image uri
/// </summary>
public string? ArtworkUrl { get; }

public AudioTrackInfo(string title, string author, TimeSpan length, string identifier, bool isStream, string uri, Dictionary<string, string> metadata) {
Title = title;
Author = author;
Expand All @@ -49,6 +56,23 @@ public AudioTrackInfo(string title, string author, TimeSpan length, string ident
IsStream = isStream;
Uri = uri;
Metadata = metadata;
if (Metadata.TryGetValue("artworkUrl", out var artworkUrl)) {
ArtworkUrl = artworkUrl;
}
}

public AudioTrackInfo(string title, string author, TimeSpan length, string identifier, bool isStream, string uri, string? artworkUrl = null) {
Title = title;
Author = author;
Length = length;
Identifier = identifier;
IsStream = isStream;
Uri = uri;
Metadata = new Dictionary<string, string>();
if (artworkUrl != null) {
Metadata.Add("artworkUrl", artworkUrl);
ArtworkUrl = artworkUrl;
}
}
}
}
2 changes: 1 addition & 1 deletion YandexMusicResolver/Loaders/YandexMusicDirectUrlLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public YandexMusicDirectUrlLoader(IYandexConfig config) {
/// <param name="codec">Target codec. mp3 by default</param>
/// <returns>Direct url to download track</returns>
/// <exception cref="Exception">Couldn't find supported track format</exception>
public async Task<string> GetDirectUrl(string trackId, string codec) {
public async Task<string> GetDirectUrl(string trackId, string codec = "mp3") {
var trackDownloadInfos = await new YandexCustomRequest(_config).Create(string.Format(TrackDownloadInfoFormat, trackId))
.GetResponseAsync<List<MetaTrackDownloadInfo>>();
var track = trackDownloadInfos.FirstOrDefault(downloadInfo => downloadInfo.Codec == codec);
Expand Down
11 changes: 11 additions & 0 deletions YandexMusicResolver/Loaders/YandexMusicPlaylistLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,20 @@ public YandexMusicPlaylistLoader(IYandexConfig config) : base(config) { }
/// <param name="albumId">Target album id</param>
/// <param name="trackFactory">Track factory to create YandexMusicTrack from AudioTrackInfo</param>
/// <returns>Playlist instance</returns>
[Obsolete("For album loading use LoadAlbum method. \nWill be removed in 3.0")]
public Task<YandexMusicPlaylist?> LoadPlaylist(string albumId, Func<AudioTrackInfo, YandexMusicTrack> trackFactory) {
return LoadPlaylistUrl(string.Format(AlbumInfoFormat, albumId), trackFactory);
}

/// <summary>
/// Loads the album from Yandex Music
/// </summary>
/// <param name="albumId">Target album id</param>
/// <param name="trackFactory">Track factory to create YandexMusicTrack from AudioTrackInfo</param>
/// <returns>Playlist instance</returns>
public Task<YandexMusicPlaylist?> LoadAlbum(string albumId, Func<AudioTrackInfo, YandexMusicTrack> trackFactory) {
return LoadPlaylistUrl(string.Format(AlbumInfoFormat, albumId), trackFactory);
}

private async Task<YandexMusicPlaylist?> LoadPlaylistUrl(string url, Func<AudioTrackInfo, YandexMusicTrack> trackFactory) {
var playlistData = await new YandexCustomRequest(Config).Create(url).GetResponseAsync<MetaPlaylist>();
Expand Down
29 changes: 25 additions & 4 deletions YandexMusicResolver/Loaders/YandexMusicTrackLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,19 @@ public YandexMusicTrackLoader(IYandexConfig config) {
/// <param name="trackId">Target track id</param>
/// <param name="trackFactory">Track factory to create YandexMusicTrack from AudioTrackInfo</param>
/// <returns>Instance of <see cref="YandexMusicTrack"/></returns>
public async Task<YandexMusicTrack?> LoadTrack(string albumId, string trackId, Func<AudioTrackInfo, YandexMusicTrack?> trackFactory) {
return trackFactory((await LoadTrackInfo(albumId, trackId))!);
[Obsolete("We do not need an album ID to load track information. \nWill be removed in 3.0")]
public Task<YandexMusicTrack?> LoadTrack(string albumId, string trackId, Func<AudioTrackInfo, YandexMusicTrack?> trackFactory) {
return LoadTrack(trackId, trackFactory);
}

/// <summary>
/// Load track
/// </summary>
/// <param name="trackId">Target track id</param>
/// <param name="trackFactory">Track factory to create YandexMusicTrack from AudioTrackInfo</param>
/// <returns>Instance of <see cref="YandexMusicTrack"/></returns>
public async Task<YandexMusicTrack?> LoadTrack(string trackId, Func<AudioTrackInfo, YandexMusicTrack?> trackFactory) {
return trackFactory((await LoadTrackInfo(trackId))!);
}

/// <summary>
Expand All @@ -44,8 +55,18 @@ public YandexMusicTrackLoader(IYandexConfig config) {
/// <param name="albumId">Album id with track</param>
/// <param name="trackId">Target track id</param>
/// <returns>Instance of <see cref="AudioTrackInfo"/></returns>
public async Task<AudioTrackInfo?> LoadTrackInfo(string albumId, string trackId) {
var response = await new YandexCustomRequest(Config).Create(TracksInfoFormat + $"{trackId}:{albumId}").GetResponseAsync<List<MetaTrack>>();
[Obsolete("We do not need an album ID to load track information. \nWill be removed in 3.0")]
public Task<AudioTrackInfo?> LoadTrackInfo(string albumId, string trackId) {
return LoadTrackInfo(trackId);
}

/// <summary>
/// Load track info
/// </summary>
/// <param name="trackId">Target track id</param>
/// <returns>Instance of <see cref="AudioTrackInfo"/></returns>
public async Task<AudioTrackInfo?> LoadTrackInfo(string trackId) {
var response = await new YandexCustomRequest(Config).Create(TracksInfoFormat + trackId).GetResponseAsync<List<MetaTrack>>();
var entry = response.First();
return await entry.ToAudioTrackInfo(this);
}
Expand Down
6 changes: 2 additions & 4 deletions YandexMusicResolver/Responces/MetaPlaylist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ internal class MetaPlaylist {
public bool Available { get; set; } = true;

[JsonProperty("tracks")]
[Obsolete]
public List<MetaPlaylistTrackContainer> PlaylistTracks {
private List<MetaPlaylistTrackContainer> PlaylistTracks {
set => Tracks = value.Select(container => container.Track).Cast<ITrackInfoContainer>().ToList();
}

[JsonProperty("volumes")]
[Obsolete]
public List<List<MetaTrack>> AlbumVolumes {
private List<List<MetaTrack>> AlbumVolumes {
set => Tracks = value.SelectMany(list => list).Cast<ITrackInfoContainer>().ToList();
}

Expand Down
2 changes: 1 addition & 1 deletion YandexMusicResolver/Responces/MetaPlaylistTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace YandexMusicResolver.Responces {
/// <summary>
/// Represent
/// </summary>
public class MetaPlaylistTrack : ITrackInfoContainer {
internal class MetaPlaylistTrack : ITrackInfoContainer {
/// <summary>
/// Track id
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Newtonsoft.Json;

namespace YandexMusicResolver.Responces {
public class MetaPlaylistTrackContainer {
internal class MetaPlaylistTrackContainer {
[JsonProperty("id")]
public long Id { get; set; }

Expand Down
32 changes: 27 additions & 5 deletions YandexMusicResolver/YandexMusicMainResolver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using YandexMusicResolver.AudioItems;
using YandexMusicResolver.Config;
Expand All @@ -13,9 +14,9 @@ public class YandexMusicMainResolver {
private const string AlbumUrlPattern = "^https?://music\\.yandex\\.[a-zA-Z]+/album/([0-9]+)$";
private const string PlaylistUrlPattern = "^https?://music\\.yandex\\.[a-zA-Z]+/users/(.+)/playlists/([0-9]+)$";

private static Regex TrackUrlRegex = new Regex(TrackUrlPattern);
private static Regex AlbumUrlRegex = new Regex(AlbumUrlPattern);
private static Regex PlaylistUrlRegex = new Regex(PlaylistUrlPattern);
private static readonly Regex TrackUrlRegex = new Regex(TrackUrlPattern);
private static readonly Regex AlbumUrlRegex = new Regex(AlbumUrlPattern);
private static readonly Regex PlaylistUrlRegex = new Regex(PlaylistUrlPattern);

// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
private readonly IYandexConfig _config;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class YandexMusicMainResolver {
/// <param name="trackLoader">Instance of <see cref="YandexMusicTrackLoader"/></param>
/// <param name="directUrlLoader">Instance of <see cref="YandexMusicDirectUrlLoader"/></param>
/// <param name="searchResultLoader">Instance of <see cref="YandexMusicSearchResultLoader"/></param>
[Obsolete("Use another ctor and set AllowSearch property after that. \nWill be removed in 3.0")]
public YandexMusicMainResolver(IYandexConfig config,
bool allowSearch = true,
YandexMusicPlaylistLoader? playlistLoader = null,
Expand All @@ -62,11 +64,31 @@ public YandexMusicMainResolver(IYandexConfig config,
SearchResultLoader = searchResultLoader ?? new YandexMusicSearchResultLoader(_config);
AllowSearch = allowSearch;
}

/// <summary>
/// Initializes a new instance of the <see cref="YandexMusicMainResolver"/> class.
/// </summary>
/// <param name="config">Yandex config instance</param>
/// <param name="playlistLoader">Instance of <see cref="YandexMusicPlaylistLoader"/></param>
/// <param name="trackLoader">Instance of <see cref="YandexMusicTrackLoader"/></param>
/// <param name="directUrlLoader">Instance of <see cref="YandexMusicDirectUrlLoader"/></param>
/// <param name="searchResultLoader">Instance of <see cref="YandexMusicSearchResultLoader"/></param>
public YandexMusicMainResolver(IYandexConfig config,
YandexMusicPlaylistLoader? playlistLoader = null,
YandexMusicTrackLoader? trackLoader = null,
YandexMusicDirectUrlLoader? directUrlLoader = null,
YandexMusicSearchResultLoader? searchResultLoader = null) {
_config = config;
PlaylistLoader = playlistLoader ?? new YandexMusicPlaylistLoader(_config);
TrackLoader = trackLoader ?? new YandexMusicTrackLoader(_config);
DirectUrlLoader = directUrlLoader ?? new YandexMusicDirectUrlLoader(_config);
SearchResultLoader = searchResultLoader ?? new YandexMusicSearchResultLoader(_config);
}

/// <summary>
/// Is query in <see cref="ResolveQuery"/> can be resolved with search
/// </summary>
public bool AllowSearch { get; }
public bool AllowSearch { get; set; } = true;

/// <summary>
/// Resolves yandex query. Can directly resolve playlists, albums, tracks by url and search queries
Expand Down
2 changes: 1 addition & 1 deletion YandexMusicResolver/YandexMusicResolver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Description>A library aimed at searching, resolving and getting direct links to tracks, playlists or albums in Yandex.Music. Can work without authorization.</Description>
<RepositoryType>Git</RepositoryType>
<PackageProjectUrl>https://github.com/SKProCH/YandexMusicResolver</PackageProjectUrl>
<Version>2.1.0</Version>
<Version>2.2.0</Version>
<PackageLicenseUrl>https://github.com/SKProCH/YandexMusicResolver/blob/master/LICENSE</PackageLicenseUrl>
<PackageReleaseNotes>Please write the package release notes in “RELEASE NOTES.md”</PackageReleaseNotes>

Expand Down
20 changes: 20 additions & 0 deletions YandexMusicResolver/YandexMusicResolver.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5f14657

Please sign in to comment.