2 from __future__ import unicode_literals
4 from .common import InfoExtractor
16 class ApplePodcastsIE(InfoExtractor):
17 _VALID_URL = r'https?://podcasts\.apple\.com/(?:[^/]+/)?podcast(?:/[^/]+){1,2}.*?\bi=(?P<id>\d+)'
19 'url': 'https://podcasts.apple.com/us/podcast/207-whitney-webb-returns/id1135137367?i=1000482637777',
20 'md5': '41dc31cd650143e530d9423b6b5a344f',
22 'id': '1000482637777',
24 'title': '207 - Whitney Webb Returns',
25 'description': 'md5:75ef4316031df7b41ced4e7b987f79c6',
26 'upload_date': '20200705',
27 'timestamp': 1593932400,
29 'series': 'The Tim Dillon Show',
30 'thumbnail': 're:.+[.](png|jpe?g|webp)',
33 'url': 'https://podcasts.apple.com/podcast/207-whitney-webb-returns/id1135137367?i=1000482637777',
34 'only_matching': True,
36 'url': 'https://podcasts.apple.com/podcast/207-whitney-webb-returns?i=1000482637777',
37 'only_matching': True,
39 'url': 'https://podcasts.apple.com/podcast/id1135137367?i=1000482637777',
40 'only_matching': True,
43 def _real_extract(self, url):
44 episode_id = self._match_id(url)
45 webpage = self._download_webpage(url, episode_id)
48 # new page type 2021-11
49 amp_data = self._parse_json(self._search_regex(
50 r'(?s)id="shoebox-media-api-cache-amp-podcasts"[^>]*>\s*({.+?})\s*<',
51 webpage, 'AMP data', default='{}'), episode_id, fatal=False) or {}
52 amp_data = try_get(amp_data,
53 lambda a: self._parse_json(
54 next(a[x] for x in iter(a) if episode_id in x),
57 amp_data = amp_data.get('d') or []
58 episode_data = try_get(
60 lambda a: next(x for x in a
61 if x['type'] == 'podcast-episodes' and x['id'] == episode_id),
64 # try pre 2021-11 page type: TODO: consider deleting if no longer used
65 ember_data = self._parse_json(self._search_regex(
66 r'(?s)id="shoebox-ember-data-store"[^>]*>\s*({.+?})\s*<',
67 webpage, 'ember data'), episode_id) or {}
68 ember_data = ember_data.get(episode_id) or ember_data
69 episode_data = try_get(ember_data, lambda x: x['data'], dict)
70 episode = episode_data['attributes']
71 description = episode.get('description') or {}
74 for inc in (amp_data or ember_data.get('included') or []):
75 if inc.get('type') == 'media/podcast':
76 series = try_get(inc, lambda x: x['attributes']['name'])
77 series = series or clean_html(get_element_by_class('podcast-header__identity', webpage))
81 'title': episode['name'],
82 'url': clean_podcast_url(episode['assetUrl']),
83 'description': description.get('standard') or description.get('short'),
84 'timestamp': parse_iso8601(episode.get('releaseDateTime')),
85 'duration': int_or_none(episode.get('durationInMilliseconds'), 1000),
87 'thumbnail': self._og_search_thumbnail(webpage),
89 self._sort_formats(info)
91 codecs = parse_codecs(info.get('ext', 'mp3'))