Skip to content

Commit

Permalink
restored older working json paths as fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
h0lg committed Nov 26, 2024
1 parent 678b371 commit b7b10ea
Showing 1 changed file with 50 additions and 7 deletions.
57 changes: 50 additions & 7 deletions YoutubeExplode/Bridge/SearchResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChannelData> Channels =>
Expand Down Expand Up @@ -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 =>
Expand All @@ -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 =>
Expand All @@ -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]
Expand All @@ -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()
?? [];
}
}

Expand Down

0 comments on commit b7b10ea

Please sign in to comment.