доработка api поиска треков
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using PlaylistShared.Api.Entities;
|
||||
using PlaylistShared.Shared.DTO;
|
||||
using PlaylistShared.Api.Extensions;
|
||||
using PlaylistShared.Shared.Enums;
|
||||
using PlaylistShared.Shared.Yandex;
|
||||
using YandexMusic;
|
||||
using YandexMusic.API.Extensions.API;
|
||||
using YandexMusic.API.Models.Playlist;
|
||||
@@ -108,7 +109,7 @@ public class YandexMusicService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<YandexTrack>> SearchTracksAsync(
|
||||
public async Task<YandexSearchResult> SearchAsync(
|
||||
ApplicationUser user,
|
||||
string query,
|
||||
TrackSearchType? searchType = TrackSearchType.All,
|
||||
@@ -116,7 +117,7 @@ public class YandexMusicService
|
||||
)
|
||||
{
|
||||
var client = await CreateClientAsync(user);
|
||||
if (client == null) return new List<YandexTrack>();
|
||||
if (client == null) return new YandexSearchResult();
|
||||
|
||||
var ySerchType = searchType switch
|
||||
{
|
||||
@@ -128,19 +129,56 @@ public class YandexMusicService
|
||||
};
|
||||
|
||||
var searchResult = await client.SearchAsync(query, ySerchType, page: 0, pageSize: limit);
|
||||
if (searchResult?.Tracks?.Results == null) return new List<YandexTrack>();
|
||||
if (searchResult?.Tracks?.Results == null) return new YandexSearchResult();
|
||||
|
||||
return searchResult.Tracks.Results.Select(t => new YandexTrack
|
||||
return new YandexSearchResult
|
||||
{
|
||||
TrackId = t.Id,
|
||||
Title = t.Title,
|
||||
Artists = t.Artists?.Select(a => a.Name).ToList() ?? new List<string>(),
|
||||
CoverUri = t.CoverUri ?? string.Empty,
|
||||
DurationMs = t.DurationMs,
|
||||
}).ToList();
|
||||
Tracks = searchResult.Tracks.Results.Select(t => new YandexTrack
|
||||
{
|
||||
TrackId = t.Id,
|
||||
Title = t.Title,
|
||||
Artists = t.Artists?.Select(a => a.Name).ToList() ?? new List<string>(),
|
||||
CoverUri = t.CoverUri,
|
||||
DurationMs = t.DurationMs,
|
||||
}).ToList(),
|
||||
|
||||
Playlists = searchResult.Playlists?.Results.Select(p => new YandexPlaylist
|
||||
{
|
||||
Uuid = p.PlaylistUuid,
|
||||
Kind = p.Kind,
|
||||
OwnerUid = p.Owner?.Uid ?? string.Empty,
|
||||
Title = p.Title,
|
||||
Description = p.Description,
|
||||
CoverUrl = p.CoverUri,
|
||||
TrackCount = p.TrackCount,
|
||||
}).ToList(),
|
||||
|
||||
Artists = searchResult.Artists?.Results.Select(a => new YandexArtist
|
||||
{
|
||||
Id = a.Id,
|
||||
Name = a.Name,
|
||||
CoverUrl = a.Cover.GetUrl(),
|
||||
Description = a.Description.Text,
|
||||
}).ToList(),
|
||||
|
||||
Albums = searchResult.Albums?.Results.Select(a => new YandexAlbum
|
||||
{
|
||||
Id = a.Id,
|
||||
Title = a.Title,
|
||||
Artists = a.Artists.Select(t => new YandexArtist()
|
||||
{
|
||||
Id = t.Id,
|
||||
Name = t.Name,
|
||||
CoverUrl = t.Cover.GetUrl(),
|
||||
Description = t.Description.Text,
|
||||
}).ToList(),
|
||||
CoverUrl = string.IsNullOrEmpty(a.CoverUri) ? a.Cover.GetUrl() : a.CoverUri,
|
||||
Description = a.Description,
|
||||
}).ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<List<YandexTrack>> SearchTracksByIdAsync(
|
||||
public async Task<YandexSearchResult> SearchTracksByIdAsync(
|
||||
ApplicationUser user,
|
||||
string id,
|
||||
TrackSearchType searchType,
|
||||
@@ -148,7 +186,7 @@ public class YandexMusicService
|
||||
)
|
||||
{
|
||||
var client = await CreateClientAsync(user);
|
||||
if (client == null) return new List<YandexTrack>();
|
||||
if (client == null) return new YandexSearchResult();
|
||||
|
||||
var ySerchType = searchType switch
|
||||
{
|
||||
@@ -174,13 +212,16 @@ public class YandexMusicService
|
||||
if (limit > 0) searchResult = searchResult.Take(limit);
|
||||
}
|
||||
|
||||
return searchResult.Select(t => new YandexTrack
|
||||
return new YandexSearchResult()
|
||||
{
|
||||
TrackId = t.Id,
|
||||
Title = t.Title,
|
||||
Artists = t.Artists?.Select(a => a.Name).ToList() ?? new List<string>(),
|
||||
CoverUri = t.CoverUri ?? string.Empty,
|
||||
DurationMs = t.DurationMs,
|
||||
}).ToList();
|
||||
Tracks = searchResult.Select(t => new YandexTrack
|
||||
{
|
||||
TrackId = t.Id,
|
||||
Title = t.Title,
|
||||
Artists = t.Artists?.Select(a => a.Name).ToList() ?? new List<string>(),
|
||||
CoverUri = t.CoverUri ?? string.Empty,
|
||||
DurationMs = t.DurationMs,
|
||||
}).ToList(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user