Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/applepodcasts.py (Python)

Code before:
    }, {
        'url': 'https://podcasts.apple.com/podcast/207-whitney-webb-returns/id1135137367?i=1000482637777',
        'only_matching': True,
    }, {
        'url': 'https://podcasts.apple.com/podcast/207-whitney-webb-returns?i=1000482637777',
        'only_matching': True,
    }, {
        'url': 'https://podcasts.apple.com/podcast/id1135137367?i=1000482637777',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        episode_id = self._match_id(url)
        webpage = self._download_webpage(url, episode_id)
        server_data = self._parse_json(
            get_element_by_id('serialized-server-data', webpage),
            episode_id) or [{}]
        model_data = traverse_obj(
            server_data,
            (0, 'data', 'headerButtonItems',
             {lambda x: next(y for y in x
                             if y.get('$kind') == 'bookmark' and y.get('modelType') == 'EpisodeOffer')},
             'model'))
        schema_content = traverse_obj(server_data, (0, 'data', 'seoData', 'schemaContent'))

        return {
            'id': episode_id,
            'title': model_data.get('title') or schema_content.get('name') or self._og_search_title(webpage),
            'url': clean_podcast_url(model_data['streamUrl']),
            'description': schema_content.get('description'),
            'timestamp': parse_iso8601(model_data.get('releaseDate')),
            'duration': model_data.get('duration'),
            'series': schema_content.get('partOfSeries', {}).get('name'),
            'thumbnail': self._og_search_thumbnail(webpage),
            'vcodec': 'none',
        }


Review comment (security):
```suggestion
            'id': episode_id,
            **self._json_ld(
                traverse_obj(server_data, ('seoData', 'schemaContent', {dict}))
                or self._yield_json_ld(webpage, episode_id, fatal=False), episode_id, fatal=False),
```

You will need to also modify `_json_ld` in `InfoExtractor` so that `PodcastEpisode` is accepted.

```diff
                 if rating is not None:
                     info['average_rating'] = rating
-                if is_type(e, 'TVEpisode', 'Episode'):
+                if is_type(e, 'TVEpisode', 'Episode', 'PodcastEpisode'):
                     episode_name = unescapeHTML(e.get('name'))
                     info.update({
```
You can then drop the fields below that get extracted from `schema_content`.

Code after:
            'series': 'The Tim Dillon Show',
            'thumbnail': 're:.+[.](png|jpe?g|webp)',
        },
    }, {
        'url': 'https://podcasts.apple.com/podcast/207-whitney-webb-returns/id1135137367?i=1000482637777',
        'only_matching': True,
    }, {
        'url': 'https://podcasts.apple.com/podcast/207-whitney-webb-returns?i=1000482637777',
        'only_matching': True,
    }, {
        'url': 'https://podcasts.apple.com/podcast/id1135137367?i=1000482637777',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        episode_id = self._match_id(url)
        webpage = self._download_webpage(url, episode_id)
        server_data = self._search_json(
            r'<script [^>]*\bid=["\']serialized-server-data["\'][^>]*>', webpage,
            'server data', episode_id, contains_pattern=r'\[{(?s:.+)}\]')[0]['data']
        model_data = traverse_obj(server_data, (
            'headerButtonItems', lambda _, v: v['$kind'] == 'bookmark' and v['modelType'] == 'EpisodeOffer',
            'model', {dict}, any))

        return {
            'id': episode_id,
            **self._json_ld(
                traverse_obj(server_data, ('seoData', 'schemaContent', {dict}))
                or self._yield_json_ld(webpage, episode_id, fatal=False), episode_id, fatal=False),
            **traverse_obj(model_data, {
                'title': ('title', {str}),
                'url': ('streamUrl', {clean_podcast_url}),
                'timestamp': ('releaseDate', {parse_iso8601}),
                'duration': ('duration', {int_or_none}),
            }),
            'thumbnail': self._og_search_thumbnail(webpage),
            'vcodec': 'none',
        }