From b7b10eae9761761e450e84a19a5ed47da0a6b0d1 Mon Sep 17 00:00:00 2001 From: Holger Schmidt Date: Tue, 26 Nov 2024 19:17:26 +0100 Subject: [PATCH] restored older working json paths as fallbacks --- YoutubeExplode/Bridge/SearchResponse.cs | 57 ++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/YoutubeExplode/Bridge/SearchResponse.cs b/YoutubeExplode/Bridge/SearchResponse.cs index 962d76c4..358e7e01 100644 --- a/YoutubeExplode/Bridge/SearchResponse.cs +++ b/YoutubeExplode/Bridge/SearchResponse.cs @@ -30,7 +30,13 @@ internal partial class SearchResponse(JsonElement content) ContentRoot ?.EnumerateDescendantProperties("lockupViewModel") .Select(j => new PlaylistData(j)) - .ToArray() ?? []; + .ToArray() + // fall back to older working paths + ?? ContentRoot + ?.EnumerateDescendantProperties("playlistRenderer") + .Select(j => new PlaylistData(j)) + .ToArray() + ?? []; [Lazy] public IReadOnlyList Channels => @@ -129,13 +135,27 @@ internal partial class SearchResponse public class PlaylistData(JsonElement content) { [Lazy] - public string? Id => content.GetPropertyOrNull("contentId")?.GetStringOrNull(); + public string? Id => + content.GetPropertyOrNull("contentId")?.GetStringOrNull() + // fall back to older working paths + ?? content.GetPropertyOrNull("playlistId")?.GetStringOrNull(); [Lazy] - private JsonElement? Metadata => content.GetPropertyOrNull("metadata")?.GetPropertyOrNull("lockupMetadataViewModel"); + private JsonElement? Metadata => + content.GetPropertyOrNull("metadata")?.GetPropertyOrNull("lockupMetadataViewModel"); [Lazy] - public string? Title => Metadata?.GetPropertyOrNull("title")?.GetPropertyOrNull("content")?.GetStringOrNull(); + public string? Title => + Metadata?.GetPropertyOrNull("title")?.GetPropertyOrNull("content")?.GetStringOrNull() + // fall back to older working paths + ?? content.GetPropertyOrNull("title")?.GetPropertyOrNull("simpleText")?.GetStringOrNull() + ?? content + .GetPropertyOrNull("title") + ?.GetPropertyOrNull("runs") + ?.EnumerateArrayOrNull() + ?.Select(j => j.GetPropertyOrNull("text")?.GetStringOrNull()) + .WhereNotNull() + .ConcatToString(); [Lazy] private JsonElement? AuthorDetails => @@ -144,10 +164,19 @@ public class PlaylistData(JsonElement content) ?.ElementAtOrNull(0) ?.EnumerateArrayOrNull() ?.ElementAtOrNull(0) - ?.GetPropertyOrNull("text"); + ?.GetPropertyOrNull("text") + // fall back to older working paths + ?? content + .GetPropertyOrNull("longBylineText") + ?.GetPropertyOrNull("runs") + ?.EnumerateArrayOrNull() + ?.ElementAtOrNull(0); [Lazy] - public string? Author => AuthorDetails?.GetPropertyOrNull("content")?.GetStringOrNull(); + public string? Author => + AuthorDetails?.GetPropertyOrNull("content")?.GetStringOrNull() + // fall back to older working paths + ?? AuthorDetails?.GetPropertyOrNull("text")?.GetStringOrNull(); [Lazy] public string? ChannelId => @@ -159,6 +188,12 @@ public class PlaylistData(JsonElement content) ?.GetPropertyOrNull("innertubeCommand") ?.GetPropertyOrNull("browseEndpoint") ?.GetPropertyOrNull("browseId") + ?.GetStringOrNull() + // fall back to older working paths + ?? AuthorDetails + ?.GetPropertyOrNull("navigationEndpoint") + ?.GetPropertyOrNull("browseEndpoint") + ?.GetPropertyOrNull("browseId") ?.GetStringOrNull(); [Lazy] @@ -172,7 +207,15 @@ public class PlaylistData(JsonElement content) ?.GetPropertyOrNull("sources") ?.EnumerateArrayOrEmpty() .Select(j => new ThumbnailData(j)) - .ToArray() ?? []; + .ToArray() + // fall back to older working paths + ?? content + .GetPropertyOrNull("thumbnails") + ?.EnumerateDescendantProperties("thumbnails") + .SelectMany(j => j.EnumerateArrayOrEmpty()) + .Select(j => new ThumbnailData(j)) + .ToArray() + ?? []; } }