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,