]> jfr.im git - yt-dlp.git/blame - youtube_dlc/extractor/acast.py
Merge branch 'master' of https://github.com/ssaqua/youtube-dl into ssaqua-master
[yt-dlp.git] / youtube_dlc / extractor / acast.py
CommitLineData
50e12e9d 1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
a1ff3cd5 5import functools
50e12e9d 6
7from .common import InfoExtractor
8from ..compat import compat_str
a1ff3cd5 9from ..utils import (
976e1ff7 10 clean_html,
1c9b1a44 11 float_or_none,
cae5d970
S
12 int_or_none,
13 try_get,
b5e531f3 14 unified_timestamp,
a1ff3cd5 15 OnDemandPagedList,
16)
50e12e9d 17
18
9934fe76 19class ACastIE(InfoExtractor):
50e12e9d 20 IE_NAME = 'acast'
50a498a6
S
21 _VALID_URL = r'''(?x)
22 https?://
23 (?:
24 (?:(?:embed|www)\.)?acast\.com/|
25 play\.acast\.com/s/
26 )
27 (?P<channel>[^/]+)/(?P<id>[^/#?]+)
28 '''
846fd69b 29 _TESTS = [{
846fd69b 30 'url': 'https://www.acast.com/sparpodcast/2.raggarmordet-rosterurdetforflutna',
976e1ff7 31 'md5': '16d936099ec5ca2d5869e3a813ee8dc4',
846fd69b
MW
32 'info_dict': {
33 'id': '2a92b283-1a75-4ad8-8396-499c641de0d9',
34 'ext': 'mp3',
35 'title': '2. Raggarmordet - Röster ur det förflutna',
cae5d970 36 'description': 'md5:4f81f6d8cf2e12ee21a321d8bca32db4',
846fd69b
MW
37 'timestamp': 1477346700,
38 'upload_date': '20161024',
cae5d970
S
39 'duration': 2766.602563,
40 'creator': 'Anton Berg & Martin Johnson',
41 'series': 'Spår',
42 'episode': '2. Raggarmordet - Röster ur det förflutna',
846fd69b 43 }
252e172d
TL
44 }, {
45 'url': 'http://embed.acast.com/adambuxton/ep.12-adam-joeschristmaspodcast2015',
46 'only_matching': True,
50a498a6
S
47 }, {
48 'url': 'https://play.acast.com/s/rattegangspodden/s04e09-styckmordet-i-helenelund-del-22',
49 'only_matching': True,
976e1ff7
RA
50 }, {
51 'url': 'https://play.acast.com/s/sparpodcast/2a92b283-1a75-4ad8-8396-499c641de0d9',
52 'only_matching': True,
846fd69b 53 }]
50e12e9d 54
55 def _real_extract(self, url):
56 channel, display_id = re.match(self._VALID_URL, url).groups()
1c9b1a44 57 s = self._download_json(
976e1ff7
RA
58 'https://feeder.acast.com/api/v1/shows/%s/episodes/%s' % (channel, display_id),
59 display_id)
1c9b1a44 60 media_url = s['url']
976e1ff7
RA
61 if re.search(r'[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}', display_id):
62 episode_url = s.get('episodeUrl')
63 if episode_url:
64 display_id = episode_url
65 else:
66 channel, display_id = re.match(self._VALID_URL, s['link']).groups()
a1ff3cd5 67 cast_data = self._download_json(
cae5d970
S
68 'https://play-api.acast.com/splash/%s/%s' % (channel, display_id),
69 display_id)['result']
70 e = cast_data['episode']
976e1ff7 71 title = e.get('name') or s['title']
50e12e9d 72 return {
b5e531f3 73 'id': compat_str(e['id']),
50e12e9d 74 'display_id': display_id,
1c9b1a44 75 'url': media_url,
cae5d970 76 'title': title,
976e1ff7 77 'description': e.get('summary') or clean_html(e.get('description') or s.get('description')),
b5e531f3 78 'thumbnail': e.get('image'),
976e1ff7
RA
79 'timestamp': unified_timestamp(e.get('publishingDate') or s.get('publishDate')),
80 'duration': float_or_none(e.get('duration') or s.get('duration')),
cae5d970
S
81 'filesize': int_or_none(e.get('contentLength')),
82 'creator': try_get(cast_data, lambda x: x['show']['author'], compat_str),
83 'series': try_get(cast_data, lambda x: x['show']['name'], compat_str),
84 'season_number': int_or_none(e.get('seasonNumber')),
85 'episode': title,
86 'episode_number': int_or_none(e.get('episodeNumber')),
50e12e9d 87 }
88
89
9934fe76 90class ACastChannelIE(InfoExtractor):
50e12e9d 91 IE_NAME = 'acast:channel'
0e713dbb 92 _VALID_URL = r'''(?x)
93 https?://
94 (?:
95 (?:www\.)?acast\.com/|
96 play\.acast\.com/s/
97 )
98 (?P<id>[^/#?]+)
99 '''
100 _TESTS = [{
101 'url': 'https://www.acast.com/todayinfocus',
50e12e9d 102 'info_dict': {
0e713dbb 103 'id': '4efc5294-5385-4847-98bd-519799ce5786',
104 'title': 'Today in Focus',
105 'description': 'md5:9ba5564de5ce897faeb12963f4537a64',
50e12e9d 106 },
0e713dbb 107 'playlist_mincount': 35,
108 }, {
109 'url': 'http://play.acast.com/s/ft-banking-weekly',
110 'only_matching': True,
111 }]
112 _API_BASE_URL = 'https://play.acast.com/api/'
a1ff3cd5 113 _PAGE_SIZE = 10
50e12e9d 114
ab3b773b 115 @classmethod
116 def suitable(cls, url):
117 return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url)
118
a1ff3cd5 119 def _fetch_page(self, channel_slug, page):
120 casts = self._download_json(
121 self._API_BASE_URL + 'channels/%s/acasts?page=%s' % (channel_slug, page),
122 channel_slug, note='Download page %d of channel data' % page)
123 for cast in casts:
124 yield self.url_result(
0e713dbb 125 'https://play.acast.com/s/%s/%s' % (channel_slug, cast['url']),
a1ff3cd5 126 'ACast', cast['id'])
50e12e9d 127
a1ff3cd5 128 def _real_extract(self, url):
129 channel_slug = self._match_id(url)
130 channel_data = self._download_json(
131 self._API_BASE_URL + 'channels/%s' % channel_slug, channel_slug)
132 entries = OnDemandPagedList(functools.partial(
133 self._fetch_page, channel_slug), self._PAGE_SIZE)
134 return self.playlist_result(entries, compat_str(
135 channel_data['id']), channel_data['name'], channel_data.get('description'))