From 85b5444d07ed23e1e7e57511ed65d028bcab71eb Mon Sep 17 00:00:00 2001 From: Dachein <149984401+Dachein@users.noreply.github.com> Date: Mon, 16 Mar 2026 04:58:24 -0700 Subject: [PATCH] fix(route/apple/podcast): adapt to new serialized-server-data structure (#21387) Apple Podcasts changed the `#serialized-server-data` element from a direct array to an object wrapper `{ data: [...], userTokenHash }`. This broke the route with: TypeError: Cannot read properties of undefined (reading 'data') Changes: - Handle both old (array) and new (object with `data` key) formats using `Array.isArray()` check for backward compatibility - Add defensive optional chaining on the `channel` relationship access chain to prevent crashes when episodes lack channel data Fixes the same underlying issue reported by yt-dlp (yt-dlp/yt-dlp#15926). Made-with: Cursor Co-authored-by: xbankeradmin --- lib/routes/apple/podcast.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/routes/apple/podcast.ts b/lib/routes/apple/podcast.ts index d73d90fe3..ecca6a797 100644 --- a/lib/routes/apple/podcast.ts +++ b/lib/routes/apple/podcast.ts @@ -43,8 +43,9 @@ async function handler(ctx) { const $ = load(response); - const serializedServerData = JSON.parse($('#serialized-server-data').text()); - const header = serializedServerData[0].data.shelves.find((item) => item.contentType === 'showHeaderRegular').items[0]; + const rawServerData = JSON.parse($('#serialized-server-data').text()); + const serverData = (Array.isArray(rawServerData) ? rawServerData : rawServerData.data)[0].data; + const header = serverData.shelves.find((item) => item.contentType === 'showHeaderRegular').items[0]; const bearerToken = await cache.tryGet( 'apple:podcast:bearer', @@ -93,7 +94,7 @@ async function handler(ctx) { }; }); - const channel = episodeReponse.data.find((d) => d.type === 'podcast-episodes').relationships.channel.data.find((d) => d.type === 'podcast-channels')?.attributes; + const channel = episodeReponse.data.find((d) => d.type === 'podcast-episodes')?.relationships?.channel?.data?.find((d) => d.type === 'podcast-channels')?.attributes; return { title: channel?.name ?? header.title,