diff --git a/YaMusicCli/Program.cs b/YaMusicCli/Program.cs new file mode 100644 index 0000000..99dbea1 --- /dev/null +++ b/YaMusicCli/Program.cs @@ -0,0 +1,10 @@ +internal class Program +{ + private async static Task Main(string[] args) + { + var client = new YandexMusic.YandexMusicClient(); + var type = await client.Authorize("y0__xDy2budARje-AYg7rmliBc11LbYoMeUiwiO6f6mSCAMDYVIKg"); + var playlists = (await client.GetFavoritesAsync()).Where(t => t.Owner.Uid == client.Account.Uid).ToList(); + var playlist = await client.GetPlaylistAsync("97ae0768-8a40-8485-9fa4-b6c856bc6b21"); + } +} \ No newline at end of file diff --git a/YandexMusic.API/Common/Providers/CommonRequestProvider.cs b/YandexMusic.API/Common/Providers/CommonRequestProvider.cs index 2ede2e6..d6e8369 100644 --- a/YandexMusic.API/Common/Providers/CommonRequestProvider.cs +++ b/YandexMusic.API/Common/Providers/CommonRequestProvider.cs @@ -1,5 +1,6 @@ using System.Text.Json; using System.Text.Json.Serialization; +using YandexMusic.API.Converters; using YandexMusic.API.Models.Common; namespace YandexMusic.API.Common.Providers; @@ -14,7 +15,7 @@ public abstract class CommonRequestProvider : IRequestProvider private static readonly JsonSerializerOptions JsonOptions = new() { PropertyNameCaseInsensitive = true, - Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) } + Converters = { new JsonStringEnumConverter(JsonNamingPolicy.KebabCaseLower), new IntToStringConverter() } }; /// Инициализирует новый экземпляр провайдера. diff --git a/YandexMusic.API/Converters/IntToStringConverter.cs b/YandexMusic.API/Converters/IntToStringConverter.cs new file mode 100644 index 0000000..f8ec5fe --- /dev/null +++ b/YandexMusic.API/Converters/IntToStringConverter.cs @@ -0,0 +1,34 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace YandexMusic.API.Converters; + +public class IntToStringConverter : JsonConverter +{ + public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.Number) + { + // Пытаемся извлечь число как int или long + if (reader.TryGetInt32(out int intValue)) + return intValue.ToString(); + if (reader.TryGetInt64(out long longValue)) + return longValue.ToString(); + } + else if (reader.TokenType == JsonTokenType.String) + { + return reader.GetString(); + } + else if (reader.TokenType == JsonTokenType.Null) + { + return null; + } + + throw new JsonException($"Не удалось преобразовать {reader.TokenType} в строку."); + } + + public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) + { + writer.WriteStringValue(value); + } +} \ No newline at end of file diff --git a/YandexMusic.API/Models/Account/YAccount.cs b/YandexMusic.API/Models/Account/YAccount.cs index 8e463f5..ff7f2b4 100644 --- a/YandexMusic.API/Models/Account/YAccount.cs +++ b/YandexMusic.API/Models/Account/YAccount.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using YandexMusic.API.Converters; using YandexMusic.API.Models.Common; namespace YandexMusic.API.Models.Account; @@ -36,5 +37,6 @@ public class YAccount public bool ServiceAvailable { get; set; } + [JsonConverter(typeof(IntToStringConverter))] public string Uid { get; set; } } \ No newline at end of file diff --git a/YandexMusic.API/Models/Common/Cover/YCover.cs b/YandexMusic.API/Models/Common/Cover/YCover.cs index be93992..174dd1d 100644 --- a/YandexMusic.API/Models/Common/Cover/YCover.cs +++ b/YandexMusic.API/Models/Common/Cover/YCover.cs @@ -20,7 +20,7 @@ public class YCoverConverter : JsonConverter "from-artist-photos" or "from-album-cover" => JsonSerializer.Deserialize(root.GetRawText(), options), "pic" => JsonSerializer.Deserialize(root.GetRawText(), options), "mosaic" => JsonSerializer.Deserialize(root.GetRawText(), options), - _ => JsonSerializer.Deserialize(root.GetRawText(), options) + _ => new YCover() { Type = YCoverType.Error } }; } diff --git a/YandexMusic.API/Models/Common/Cover/YCoverType.cs b/YandexMusic.API/Models/Common/Cover/YCoverType.cs index cc9273c..48dab34 100644 --- a/YandexMusic.API/Models/Common/Cover/YCoverType.cs +++ b/YandexMusic.API/Models/Common/Cover/YCoverType.cs @@ -1,4 +1,3 @@ -using System.Runtime.Serialization; using System.Text.Json.Serialization; namespace YandexMusic.API.Models.Common.Cover; @@ -8,9 +7,7 @@ public enum YCoverType { Color, Error, - [EnumMember(Value = "from-artist-photos")] FromArtistPhotos, - [EnumMember(Value = "from-album-cover")] FromAlbumCover, Mosaic, Pic, diff --git a/YandexMusic.API/Models/Common/YTrackSharingFlag.cs b/YandexMusic.API/Models/Common/YTrackSharingFlag.cs index 77a1000..4431c00 100644 --- a/YandexMusic.API/Models/Common/YTrackSharingFlag.cs +++ b/YandexMusic.API/Models/Common/YTrackSharingFlag.cs @@ -1,11 +1,12 @@ -using System.Runtime.Serialization; +using System.Text.Json.Serialization; namespace YandexMusic.API.Models.Common; +[JsonConverter(typeof(JsonStringEnumConverter))] public enum YTrackSharingFlag { - [EnumMember(Value = "VIDEO_ALLOWED")] + [JsonStringEnumMemberName("VIDEO_ALLOWED")] VideoAllowed, - [EnumMember(Value = "COVER_ONLY")] + [JsonStringEnumMemberName("COVER_ONLY")] CoverOnly } diff --git a/YandexMusic.API/Models/Playlist/YPlaylist.cs b/YandexMusic.API/Models/Playlist/YPlaylist.cs index 17dc376..1fa3bbe 100644 --- a/YandexMusic.API/Models/Playlist/YPlaylist.cs +++ b/YandexMusic.API/Models/Playlist/YPlaylist.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using YandexMusic.API.Converters; using YandexMusic.API.Models.Common; using YandexMusic.API.Models.Common.Cover; using YandexMusic.API.Models.Track; @@ -44,6 +45,7 @@ public class YPlaylist : YBaseModel public string Image { get; set; } public bool IsBanner { get; set; } public bool IsPremiere { get; set; } + [JsonConverter(typeof(IntToStringConverter))] public string Kind { get; set; } public List LastOwnerPlaylists { get; set; } public int LikesCount { get; set; } diff --git a/YandexMusic.API/nuget-publish.ps1 b/YandexMusic.API/nuget-publish.ps1 new file mode 100644 index 0000000..ffcbded --- /dev/null +++ b/YandexMusic.API/nuget-publish.ps1 @@ -0,0 +1,100 @@ +param( + [string]$Version +) + +Write-Host "=== YandexMusic Manual Publisher ===" -ForegroundColor Cyan + +# --- Ask for version if not provided --- +if (-not $Version) { + $Version = Read-Host "Введите версию пакета (например 1.2.3). Пусто = взять из git-тега" + + if (-not $Version) { + Write-Host "Читаю версию из git..." -ForegroundColor Yellow + $tag = git describe --tags --abbrev=0 2>$null + + if (-not $tag) { + Write-Host "ОШИБКА: версия не указана и git-тег не найден." -ForegroundColor Red + exit 1 + } + + $Version = $tag.TrimStart("v") + } +} + +Write-Host "Используемая версия: $Version" -ForegroundColor Green + +# --- Paths --- +$csprojPath = "YandexMusic/YandexMusic.csproj" +$backupPath = "$csprojPath.bak" +$artifacts = "artifacts" + +# --- Backup original csproj --- +Write-Host "Создаю резервную копию $csprojPath ..." -ForegroundColor Cyan +Copy-Item $csprojPath $backupPath -Force + +# --- Replace ProjectReference with PackageReference --- +Write-Host "Патчу csproj..." -ForegroundColor Cyan + +(Get-Content $csprojPath) ` + -replace '', + "" | + Set-Content $csprojPath + +Write-Host "ProjectReference → PackageReference заменён." -ForegroundColor Green + +# --- Build & Pack --- +$projects = @( + "YandexMusic.API", + "YandexMusic" +) + +if (Test-Path $artifacts) { + Remove-Item $artifacts -Recurse -Force +} +New-Item -ItemType Directory -Path $artifacts | Out-Null + +try { + foreach ($proj in $projects) { + Write-Host "Restoring $proj ..." -ForegroundColor Cyan + dotnet restore $proj + + Write-Host "Building $proj ..." -ForegroundColor Cyan + dotnet build $proj -c Release -p:Version=$Version + + Write-Host "Packing $proj ..." -ForegroundColor Cyan + dotnet pack $proj -c Release --no-build -p:PackageVersion=$Version -o $artifacts + } + + Write-Host "Сборка и упаковка завершены." -ForegroundColor Green + + # --- Publish --- + $apiKey = $env:NUGET_API_KEY + if (-not $apiKey) { + Write-Host "ОШИБКА: переменная окружения NUGET_API_KEY не установлена." -ForegroundColor Red + exit 1 + } + + Write-Host "Публикую пакеты..." -ForegroundColor Cyan + + dotnet nuget push "$artifacts\*.nupkg" ` + --source "https://git.frigat.duckdns.org/api/packages/FrigaT/nuget/index.json" ` + --api-key $apiKey ` + --skip-duplicate + + Write-Host "Публикация завершена." -ForegroundColor Green +} +finally { + # --- Restore original csproj --- + Write-Host "Восстанавливаю оригинальный csproj..." -ForegroundColor Cyan + Move-Item $backupPath $csprojPath -Force + + # --- Cleanup artifacts --- + if (Test-Path $artifacts) { + Write-Host "Удаляю artifacts..." -ForegroundColor Cyan + Remove-Item $artifacts -Recurse -Force + } + + Write-Host "Откат завершён." -ForegroundColor Green +} + +Write-Host "Готово." -ForegroundColor Cyan \ No newline at end of file diff --git a/YandexMusic.slnx b/YandexMusic.slnx index 21c5e97..9f6300b 100644 --- a/YandexMusic.slnx +++ b/YandexMusic.slnx @@ -1,4 +1,5 @@ +