Compare commits
5 Commits
v0.0.4
...
50da85be57
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50da85be57 | ||
|
|
699d38da74 | ||
|
|
1779ecaca9 | ||
|
|
8abc6c5074 | ||
|
|
b8f78a5856 |
@@ -1,4 +1,6 @@
|
|||||||
internal class Program
|
using YandexMusic.API.Extensions.API;
|
||||||
|
|
||||||
|
internal class Program
|
||||||
{
|
{
|
||||||
private async static Task Main(string[] args)
|
private async static Task Main(string[] args)
|
||||||
{
|
{
|
||||||
@@ -6,5 +8,9 @@
|
|||||||
var type = await client.Authorize("y0__xDy2budARje-AYg7rmliBc11LbYoMeUiwiO6f6mSCAMDYVIKg");
|
var type = await client.Authorize("y0__xDy2budARje-AYg7rmliBc11LbYoMeUiwiO6f6mSCAMDYVIKg");
|
||||||
var playlists = (await client.GetFavoritesAsync()).Where(t => t.Owner.Uid == client.Account.Uid).ToList();
|
var playlists = (await client.GetFavoritesAsync()).Where(t => t.Owner.Uid == client.Account.Uid).ToList();
|
||||||
var playlist = await client.GetPlaylistAsync("97ae0768-8a40-8485-9fa4-b6c856bc6b21");
|
var playlist = await client.GetPlaylistAsync("97ae0768-8a40-8485-9fa4-b6c856bc6b21");
|
||||||
|
var tracks = playlist.Tracks.Where(t => t.Id == "21696942").Select(t => t.Track).ToArray();
|
||||||
|
var x = await playlist.RemoveTracksAsync(tracks);
|
||||||
|
Console.WriteLine($"TC: {playlist.TrackCount}; {playlist.Title}");
|
||||||
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,6 +129,7 @@ public class YPlaylistAPI : YCommonAPI
|
|||||||
public Task<YResponse<YPlaylist>> DeleteTracksAsync(AuthStorage storage, YPlaylist playlist, IEnumerable<YTrack> tracks)
|
public Task<YResponse<YPlaylist>> DeleteTracksAsync(AuthStorage storage, YPlaylist playlist, IEnumerable<YTrack> tracks)
|
||||||
{
|
{
|
||||||
var distinctTracks = tracks.Distinct().ToList();
|
var distinctTracks = tracks.Distinct().ToList();
|
||||||
|
|
||||||
var changes = distinctTracks
|
var changes = distinctTracks
|
||||||
.Select(t => playlist.Tracks?.FindIndex(ct => ct.Track?.GetKey() == t.GetKey()) ?? -1)
|
.Select(t => playlist.Tracks?.FindIndex(ct => ct.Track?.GetKey() == t.GetKey()) ?? -1)
|
||||||
.Where(i => i != -1)
|
.Where(i => i != -1)
|
||||||
|
|||||||
@@ -11,13 +11,6 @@ public abstract class CommonRequestProvider : IRequestProvider
|
|||||||
/// <summary>Хранилище данных авторизации.</summary>
|
/// <summary>Хранилище данных авторизации.</summary>
|
||||||
protected readonly AuthStorage storage;
|
protected readonly AuthStorage storage;
|
||||||
|
|
||||||
/// <summary>Настройки сериализации JSON (регистронезависимые, поддержка enum-строк).</summary>
|
|
||||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
|
||||||
{
|
|
||||||
PropertyNameCaseInsensitive = true,
|
|
||||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.KebabCaseLower), new IntToStringConverter() }
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>Инициализирует новый экземпляр провайдера.</summary>
|
/// <summary>Инициализирует новый экземпляр провайдера.</summary>
|
||||||
/// <param name="authStorage">Хранилище авторизации.</param>
|
/// <param name="authStorage">Хранилище авторизации.</param>
|
||||||
protected CommonRequestProvider(AuthStorage authStorage)
|
protected CommonRequestProvider(AuthStorage authStorage)
|
||||||
@@ -37,6 +30,16 @@ public abstract class CommonRequestProvider : IRequestProvider
|
|||||||
{
|
{
|
||||||
var json = await response.Content.ReadAsStringAsync();
|
var json = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
JsonSerializerOptions JsonOptions = new()
|
||||||
|
{
|
||||||
|
PropertyNameCaseInsensitive = true,
|
||||||
|
Converters = {
|
||||||
|
new JsonStringEnumConverter(JsonNamingPolicy.KebabCaseLower),
|
||||||
|
new IntToStringConverter(),
|
||||||
|
new YExecutionContextConverter(api, storage),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var error = JsonSerializer.Deserialize<YErrorResponse>(json, JsonOptions);
|
var error = JsonSerializer.Deserialize<YErrorResponse>(json, JsonOptions);
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
namespace YandexMusic.API.Common.Providers
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Провайдер запросов данными из файла
|
|
||||||
/// </summary>
|
|
||||||
public class MockRequestProvider : CommonRequestProvider
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
public MockRequestProvider(AuthStorage authStorage) : base(authStorage)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region IRequestProvider
|
|
||||||
|
|
||||||
public override Task<HttpResponseMessage> GetWebResponseAsync(HttpRequestMessage message,
|
|
||||||
HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion IRequestProvider
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
using YandexMusic.API.Models.Album;
|
|
||||||
|
|
||||||
namespace YandexMusic.API.Extensions.API;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Методы-расширения для альбома
|
|
||||||
/// </summary>
|
|
||||||
public static partial class YAlbumExtensions
|
|
||||||
{
|
|
||||||
public static YAlbum WithTracks(this YAlbum album)
|
|
||||||
{
|
|
||||||
return WithTracksAsync(album).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string AddLike(this YAlbum album)
|
|
||||||
{
|
|
||||||
return AddLikeAsync(album).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string RemoveLike(this YAlbum album)
|
|
||||||
{
|
|
||||||
return RemoveLikeAsync(album).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
using YandexMusic.API.Models.Artist;
|
|
||||||
using YandexMusic.API.Models.Track;
|
|
||||||
|
|
||||||
namespace YandexMusic.API.Extensions.API;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Методы-расширения для исполнителя
|
|
||||||
/// </summary>
|
|
||||||
public static partial class YArtistExtensions
|
|
||||||
{
|
|
||||||
public static YArtistBriefInfo BriefInfo(this YArtist artist)
|
|
||||||
{
|
|
||||||
return BriefInfoAsync(artist).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static YTracksPage GetTracks(this YArtist artist, int page = 0, int pageSize = 20)
|
|
||||||
{
|
|
||||||
return GetTracksAsync(artist, page, pageSize).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<YTrack> GetAllTracks(this YArtist artist)
|
|
||||||
{
|
|
||||||
return GetAllTracksAsync(artist).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string AddLike(this YArtist artist)
|
|
||||||
{
|
|
||||||
return AddLikeAsync(artist).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string RemoveLike(this YArtist artist)
|
|
||||||
{
|
|
||||||
return RemoveLikeAsync(artist).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
using YandexMusic.API.Models.Playlist;
|
|
||||||
using YandexMusic.API.Models.Track;
|
|
||||||
|
|
||||||
namespace YandexMusic.API.Extensions.API;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Методы-расширения для плейлиста
|
|
||||||
/// </summary>
|
|
||||||
public static partial class YPlaylistExtensions
|
|
||||||
{
|
|
||||||
private static bool CheckUser(YPlaylist playlist)
|
|
||||||
{
|
|
||||||
return playlist.Owner.Uid == playlist.Context.Storage.User.Uid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static YPlaylist WithTracks(this YPlaylist playlist)
|
|
||||||
{
|
|
||||||
return WithTracksAsync(playlist).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string AddLike(this YPlaylist playlist)
|
|
||||||
{
|
|
||||||
return AddLikeAsync(playlist).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string RemoveLike(this YPlaylist playlist)
|
|
||||||
{
|
|
||||||
return RemoveLikeAsync(playlist).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static YPlaylist Rename(this YPlaylist playlist, string newName)
|
|
||||||
{
|
|
||||||
return RenameAsync(playlist, newName).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Delete(this YPlaylist playlist)
|
|
||||||
{
|
|
||||||
return DeleteAsync(playlist).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static YPlaylist InsertTracks(this YPlaylist playlist, params YTrack[] tracks)
|
|
||||||
{
|
|
||||||
return InsertTracksAsync(playlist, tracks).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static YPlaylist RemoveTracks(this YPlaylist playlist, params YTrack[] tracks)
|
|
||||||
{
|
|
||||||
return RemoveTracksAsync(playlist, tracks).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool UploadTracks(this YPlaylist playlist, string filePath, string fileName)
|
|
||||||
{
|
|
||||||
return UploadTracksAsync(playlist, filePath, fileName).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,6 +8,11 @@ namespace YandexMusic.API.Extensions.API;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static partial class YPlaylistExtensions
|
public static partial class YPlaylistExtensions
|
||||||
{
|
{
|
||||||
|
private static bool CheckUser(YPlaylist playlist)
|
||||||
|
{
|
||||||
|
return playlist.Owner.Uid == playlist.Context.Storage.User.Uid;
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task<YPlaylist> WithTracksAsync(this YPlaylist playlist)
|
public static async Task<YPlaylist> WithTracksAsync(this YPlaylist playlist)
|
||||||
{
|
{
|
||||||
return playlist.Tracks != null
|
return playlist.Tracks != null
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
using YandexMusic.API.Models.Radio;
|
|
||||||
using YandexMusic.API.Models.Track;
|
|
||||||
|
|
||||||
namespace YandexMusic.API.Extensions.API;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Методы-расширения для радиостанции
|
|
||||||
/// </summary>
|
|
||||||
public static partial class YStationResultExtensions
|
|
||||||
{
|
|
||||||
public static List<YSequenceItem> GetTracks(this YStation station, string prevTrackId = "")
|
|
||||||
{
|
|
||||||
return GetTracksAsync(station, prevTrackId).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string SetSettings2(this YStation station, YStationSettings2 settings)
|
|
||||||
{
|
|
||||||
return SetSettings2Async(station, settings).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string SendFeedBack(this YStation station, YStationFeedbackType type, YTrack track = null, string batchId = "", double totalPlayedSeconds = 0)
|
|
||||||
{
|
|
||||||
return SendFeedBackAsync(station, type, track, batchId, totalPlayedSeconds).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
using YandexMusic.API.Models.Track;
|
|
||||||
|
|
||||||
namespace YandexMusic.API.Extensions.API;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Методы-расширения для трека
|
|
||||||
/// </summary>
|
|
||||||
public static partial class YTrackExtensions
|
|
||||||
{
|
|
||||||
public static string GetLink(this YTrack track)
|
|
||||||
{
|
|
||||||
return GetLinkAsync(track).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Save(this YTrack track, string filePath)
|
|
||||||
{
|
|
||||||
SaveAsync(track, filePath).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int AddLike(this YTrack track)
|
|
||||||
{
|
|
||||||
return AddLikeAsync(track).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int RemoveLike(this YTrack track)
|
|
||||||
{
|
|
||||||
return RemoveLikeAsync(track).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int AddDislike(this YTrack track)
|
|
||||||
{
|
|
||||||
return AddDislikeAsync(track).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int RemoveDislike(this YTrack track)
|
|
||||||
{
|
|
||||||
return RemoveDislikeAsync(track).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string SendPlayTrackInfo(this YTrack track, string from, bool fromCache = false, string playId = "", string playlistId = "", double totalPlayedSeconds = 0, double endPositionSeconds = 0)
|
|
||||||
{
|
|
||||||
return SendPlayTrackInfoAsync(track, from, fromCache, playId, playlistId, totalPlayedSeconds).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static YTrackSupplement Supplement(this YTrack track)
|
|
||||||
{
|
|
||||||
return SupplementAsync(track).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static YTrackSimilar Similar(this YTrack track)
|
|
||||||
{
|
|
||||||
return SimilarAsync(track).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,7 @@ using YandexMusic.API.Common;
|
|||||||
namespace YandexMusic.API.Models.Common;
|
namespace YandexMusic.API.Models.Common;
|
||||||
|
|
||||||
/// <summary>Конвертер для внедрения контекста выполнения (API и хранилище) в модели.</summary>
|
/// <summary>Конвертер для внедрения контекста выполнения (API и хранилище) в модели.</summary>
|
||||||
public class YExecutionContextConverter : JsonConverter<YBaseModel>
|
public class YExecutionContextConverter : JsonConverter<object>
|
||||||
{
|
{
|
||||||
private readonly YandexMusicApi _api;
|
private readonly YandexMusicApi _api;
|
||||||
private readonly AuthStorage _storage;
|
private readonly AuthStorage _storage;
|
||||||
@@ -16,26 +16,27 @@ public class YExecutionContextConverter : JsonConverter<YBaseModel>
|
|||||||
_storage = storage;
|
_storage = storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override YBaseModel? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
public override bool CanConvert(Type typeToConvert) =>
|
||||||
|
typeof(YBaseModel).IsAssignableFrom(typeToConvert);
|
||||||
|
|
||||||
|
public override object? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
{
|
{
|
||||||
// Десериализуем объект без контекста
|
// Убираем этот конвертер из опций, чтобы избежать рекурсии
|
||||||
var obj = (YBaseModel?)JsonSerializer.Deserialize(ref reader, typeToConvert, options);
|
var innerOptions = new JsonSerializerOptions(options);
|
||||||
if (obj != null)
|
innerOptions.Converters.Remove(this);
|
||||||
|
|
||||||
|
var obj = JsonSerializer.Deserialize(ref reader, typeToConvert, innerOptions);
|
||||||
|
if (obj is YBaseModel baseModel)
|
||||||
{
|
{
|
||||||
obj.Context = new YExecutionContext
|
baseModel.Context = new YExecutionContext { API = _api, Storage = _storage };
|
||||||
{
|
|
||||||
API = _api,
|
|
||||||
Storage = _storage
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Write(Utf8JsonWriter writer, YBaseModel value, JsonSerializerOptions options)
|
public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options)
|
||||||
{
|
{
|
||||||
// При сериализации игнорируем контекст
|
var innerOptions = new JsonSerializerOptions(options);
|
||||||
var cloneOptions = new JsonSerializerOptions(options);
|
innerOptions.Converters.Remove(this);
|
||||||
cloneOptions.Converters.Remove(this);
|
JsonSerializer.Serialize(writer, value, innerOptions);
|
||||||
JsonSerializer.Serialize(writer, value, cloneOptions);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,16 @@ public class YTrackAlbumPair : IEquatable<YTrackAlbumPair>
|
|||||||
return string.Join(":", new[] { Id, AlbumId }.Where(s => !string.IsNullOrEmpty(s)));
|
return string.Join(":", new[] { Id, AlbumId }.Where(s => !string.IsNullOrEmpty(s)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(YTrackAlbumPair left, YTrackAlbumPair right)
|
||||||
|
{
|
||||||
|
return Equals(left, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(YTrackAlbumPair left, YTrackAlbumPair right)
|
||||||
|
{
|
||||||
|
return !Equals(left, right);
|
||||||
|
}
|
||||||
|
|
||||||
public bool Equals(YTrackAlbumPair other)
|
public bool Equals(YTrackAlbumPair other)
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(null, other)) return false;
|
if (ReferenceEquals(null, other)) return false;
|
||||||
|
|||||||
@@ -5,15 +5,11 @@ namespace YandexMusic.API.Requests.Common;
|
|||||||
|
|
||||||
internal class YRequest<T>
|
internal class YRequest<T>
|
||||||
{
|
{
|
||||||
#region Поля
|
|
||||||
|
|
||||||
private HttpRequestMessage msg;
|
private HttpRequestMessage msg;
|
||||||
private IRequestProvider provider;
|
private IRequestProvider provider;
|
||||||
|
|
||||||
protected YandexMusicApi api;
|
protected YandexMusicApi api;
|
||||||
|
|
||||||
#endregion Поля
|
|
||||||
|
|
||||||
public YRequest(HttpRequestMessage message, YandexMusicApi yandex, AuthStorage auth)
|
public YRequest(HttpRequestMessage message, YandexMusicApi yandex, AuthStorage auth)
|
||||||
{
|
{
|
||||||
msg = message;
|
msg = message;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public abstract class YRequestBuilder<TResponse, TParams>
|
|||||||
?? throw new NotImplementedException($"Отсутствует атрибут {nameof(YRequestAttribute)}");
|
?? throw new NotImplementedException($"Отсутствует атрибут {nameof(YRequestAttribute)}");
|
||||||
api = yandex;
|
api = yandex;
|
||||||
storage = auth;
|
storage = auth;
|
||||||
device = $"os=CSharp; os_version=; manufacturer=K1llM@n; model=Yandex Music API; clid=; device_id={storage.DeviceId}; uuid=random";
|
device = $"os=CSharp; os_version=; manufacturer=FrigaT; model=Yandex Music API; clid=; device_id={storage.DeviceId}; uuid=random";
|
||||||
|
|
||||||
_jsonOptions = new JsonSerializerOptions
|
_jsonOptions = new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,7 +35,19 @@ public class YandexMusicApi
|
|||||||
/// <summary>Создаёт экземпляр API с инициализацией всех подсистем.</summary>
|
/// <summary>Создаёт экземпляр API с инициализацией всех подсистем.</summary>
|
||||||
public YandexMusicApi()
|
public YandexMusicApi()
|
||||||
{
|
{
|
||||||
foreach (var property in GetType().GetProperties())
|
Album = new YAlbumAPI(this);
|
||||||
property.SetValue(this, Activator.CreateInstance(property.PropertyType, this));
|
Artist = new YArtistAPI(this);
|
||||||
|
Label = new YLabelAPI(this);
|
||||||
|
Landing = new YLandingAPI(this);
|
||||||
|
Library = new YLibraryAPI(this);
|
||||||
|
Playlist = new YPlaylistAPI(this);
|
||||||
|
Pins = new YPinsAPI(this);
|
||||||
|
Radio = new YRadioAPI(this);
|
||||||
|
Search = new YSearchAPI(this);
|
||||||
|
Track = new YTrackAPI(this);
|
||||||
|
Queue = new YQueueAPI(this);
|
||||||
|
User = new YUserAPI(this);
|
||||||
|
UserGeneratedContent = new YUgcAPI(this);
|
||||||
|
Ynison = new YYnisonAPI(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user