diff --git a/YoutubeExplode.Tests/SearchSpecs.cs b/YoutubeExplode.Tests/SearchSpecs.cs index 1838ed21..61a92201 100644 --- a/YoutubeExplode.Tests/SearchSpecs.cs +++ b/YoutubeExplode.Tests/SearchSpecs.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Threading.Tasks; using FluentAssertions; using Xunit; @@ -100,6 +101,16 @@ public async Task I_can_get_playlist_results_from_a_search_query() // Assert playlists.Should().NotBeEmpty(); + + var last = playlists.Last(); + + last.Title.Should().NotBeNullOrWhiteSpace(); + last.Author.Should().NotBeNull(); + last.Thumbnails.Should().NotBeEmpty(); + + var lastThumb = last.Thumbnails.Last(); + lastThumb.Url.Should().NotBeNullOrWhiteSpace(); + lastThumb.Resolution.Should().NotBeSameAs(default(Resolution)); } [Fact] diff --git a/YoutubeExplode/Bridge/SearchResponse.cs b/YoutubeExplode/Bridge/SearchResponse.cs index 51883fe6..962d76c4 100644 --- a/YoutubeExplode/Bridge/SearchResponse.cs +++ b/YoutubeExplode/Bridge/SearchResponse.cs @@ -28,7 +28,7 @@ internal partial class SearchResponse(JsonElement content) [Lazy] public IReadOnlyList Playlists => ContentRoot - ?.EnumerateDescendantProperties("playlistRenderer") + ?.EnumerateDescendantProperties("lockupViewModel") .Select(j => new PlaylistData(j)) .ToArray() ?? []; @@ -129,34 +129,34 @@ internal partial class SearchResponse public class PlaylistData(JsonElement content) { [Lazy] - public string? Id => content.GetPropertyOrNull("playlistId")?.GetStringOrNull(); + public string? Id => content.GetPropertyOrNull("contentId")?.GetStringOrNull(); [Lazy] - public string? Title => - content.GetPropertyOrNull("title")?.GetPropertyOrNull("simpleText")?.GetStringOrNull() - ?? content - .GetPropertyOrNull("title") - ?.GetPropertyOrNull("runs") - ?.EnumerateArrayOrNull() - ?.Select(j => j.GetPropertyOrNull("text")?.GetStringOrNull()) - .WhereNotNull() - .ConcatToString(); + private JsonElement? Metadata => content.GetPropertyOrNull("metadata")?.GetPropertyOrNull("lockupMetadataViewModel"); + + [Lazy] + public string? Title => Metadata?.GetPropertyOrNull("title")?.GetPropertyOrNull("content")?.GetStringOrNull(); [Lazy] private JsonElement? AuthorDetails => - content - .GetPropertyOrNull("longBylineText") - ?.GetPropertyOrNull("runs") + Metadata + ?.EnumerateDescendantProperties("metadataParts") + ?.ElementAtOrNull(0) ?.EnumerateArrayOrNull() - ?.ElementAtOrNull(0); + ?.ElementAtOrNull(0) + ?.GetPropertyOrNull("text"); [Lazy] - public string? Author => AuthorDetails?.GetPropertyOrNull("text")?.GetStringOrNull(); + public string? Author => AuthorDetails?.GetPropertyOrNull("content")?.GetStringOrNull(); [Lazy] public string? ChannelId => AuthorDetails - ?.GetPropertyOrNull("navigationEndpoint") + ?.GetPropertyOrNull("commandRuns") + ?.EnumerateArrayOrNull() + ?.ElementAtOrNull(0) + ?.GetPropertyOrNull("onTap") + ?.GetPropertyOrNull("innertubeCommand") ?.GetPropertyOrNull("browseEndpoint") ?.GetPropertyOrNull("browseId") ?.GetStringOrNull(); @@ -164,9 +164,13 @@ public class PlaylistData(JsonElement content) [Lazy] public IReadOnlyList Thumbnails => content - .GetPropertyOrNull("thumbnails") - ?.EnumerateDescendantProperties("thumbnails") - .SelectMany(j => j.EnumerateArrayOrEmpty()) + .GetPropertyOrNull("contentImage") + ?.GetPropertyOrNull("collectionThumbnailViewModel") + ?.GetPropertyOrNull("primaryThumbnail") + ?.GetPropertyOrNull("thumbnailViewModel") + ?.GetPropertyOrNull("image") + ?.GetPropertyOrNull("sources") + ?.EnumerateArrayOrEmpty() .Select(j => new ThumbnailData(j)) .ToArray() ?? []; }