[ie/dropout] Fix extraction (#12102)
[yt-dlp.git] / yt_dlp / extractor / applepodcasts.py
blobb99d24e0ebacc2669042762e5f86bd1e938d2a87
1 from .common import InfoExtractor
2 from ..utils import (
3 clean_podcast_url,
4 int_or_none,
5 parse_iso8601,
7 from ..utils.traversal import traverse_obj
10 class ApplePodcastsIE(InfoExtractor):
11 _VALID_URL = r'https?://podcasts\.apple\.com/(?:[^/]+/)?podcast(?:/[^/]+){1,2}.*?\bi=(?P<id>\d+)'
12 _TESTS = [{
13 'url': 'https://podcasts.apple.com/us/podcast/ferreck-dawn-to-the-break-of-dawn-117/id1625658232?i=1000665010654',
14 'md5': '82cc219b8cc1dcf8bfc5a5e99b23b172',
15 'info_dict': {
16 'id': '1000665010654',
17 'ext': 'mp3',
18 'title': 'Ferreck Dawn - To The Break of Dawn 117',
19 'episode': 'Ferreck Dawn - To The Break of Dawn 117',
20 'description': 'md5:1fc571102f79dbd0a77bfd71ffda23bc',
21 'upload_date': '20240812',
22 'timestamp': 1723449600,
23 'duration': 3596,
24 'series': 'Ferreck Dawn - To The Break of Dawn',
25 'thumbnail': 're:.+[.](png|jpe?g|webp)',
27 }, {
28 'url': 'https://podcasts.apple.com/us/podcast/207-whitney-webb-returns/id1135137367?i=1000482637777',
29 'md5': 'baf8a6b8b8aa6062dbb4639ed73d0052',
30 'info_dict': {
31 'id': '1000482637777',
32 'ext': 'mp3',
33 'title': '207 - Whitney Webb Returns',
34 'episode': '207 - Whitney Webb Returns',
35 'episode_number': 207,
36 'description': 'md5:75ef4316031df7b41ced4e7b987f79c6',
37 'upload_date': '20200705',
38 'timestamp': 1593932400,
39 'duration': 5369,
40 'series': 'The Tim Dillon Show',
41 'thumbnail': 're:.+[.](png|jpe?g|webp)',
43 }, {
44 'url': 'https://podcasts.apple.com/podcast/207-whitney-webb-returns/id1135137367?i=1000482637777',
45 'only_matching': True,
46 }, {
47 'url': 'https://podcasts.apple.com/podcast/207-whitney-webb-returns?i=1000482637777',
48 'only_matching': True,
49 }, {
50 'url': 'https://podcasts.apple.com/podcast/id1135137367?i=1000482637777',
51 'only_matching': True,
54 def _real_extract(self, url):
55 episode_id = self._match_id(url)
56 webpage = self._download_webpage(url, episode_id)
57 server_data = self._search_json(
58 r'<script [^>]*\bid=["\']serialized-server-data["\'][^>]*>', webpage,
59 'server data', episode_id, contains_pattern=r'\[{(?s:.+)}\]')[0]['data']
60 model_data = traverse_obj(server_data, (
61 'headerButtonItems', lambda _, v: v['$kind'] == 'bookmark' and v['modelType'] == 'EpisodeOffer',
62 'model', {dict}, any))
64 return {
65 'id': episode_id,
66 **self._json_ld(
67 traverse_obj(server_data, ('seoData', 'schemaContent', {dict}))
68 or self._yield_json_ld(webpage, episode_id, fatal=False), episode_id, fatal=False),
69 **traverse_obj(model_data, {
70 'title': ('title', {str}),
71 'url': ('streamUrl', {clean_podcast_url}),
72 'timestamp': ('releaseDate', {parse_iso8601}),
73 'duration': ('duration', {int_or_none}),
74 }),
75 'thumbnail': self._og_search_thumbnail(webpage),
76 'vcodec': 'none',