]>
Commit | Line | Data |
---|---|---|
50e12e9d | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
a1ff3cd5 | 5 | import functools |
50e12e9d | 6 | |
7 | from .common import InfoExtractor | |
8 | from ..compat import compat_str | |
a1ff3cd5 | 9 | from ..utils import ( |
1c9b1a44 | 10 | float_or_none, |
cae5d970 S |
11 | int_or_none, |
12 | try_get, | |
b5e531f3 | 13 | unified_timestamp, |
a1ff3cd5 | 14 | OnDemandPagedList, |
15 | ) | |
50e12e9d | 16 | |
17 | ||
9934fe76 | 18 | class ACastIE(InfoExtractor): |
50e12e9d | 19 | IE_NAME = 'acast' |
20 | _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<channel>[^/]+)/(?P<id>[^/#?]+)' | |
846fd69b MW |
21 | _TESTS = [{ |
22 | # test with one bling | |
ab3b773b | 23 | 'url': 'https://www.acast.com/condenasttraveler/-where-are-you-taipei-101-taiwan', |
24 | 'md5': 'ada3de5a1e3a2a381327d749854788bb', | |
50e12e9d | 25 | 'info_dict': { |
ab3b773b | 26 | 'id': '57de3baa-4bb0-487e-9418-2692c1277a34', |
50e12e9d | 27 | 'ext': 'mp3', |
ab3b773b | 28 | 'title': '"Where Are You?": Taipei 101, Taiwan', |
cae5d970 | 29 | 'description': 'md5:a0b4ef3634e63866b542e5b1199a1a0e', |
12da8309 MW |
30 | 'timestamp': 1196172000, |
31 | 'upload_date': '20071127', | |
ab3b773b | 32 | 'duration': 211, |
cae5d970 S |
33 | 'creator': 'Concierge', |
34 | 'series': 'Condé Nast Traveler Podcast', | |
35 | 'episode': '"Where Are You?": Taipei 101, Taiwan', | |
50e12e9d | 36 | } |
846fd69b MW |
37 | }, { |
38 | # test with multiple blings | |
39 | 'url': 'https://www.acast.com/sparpodcast/2.raggarmordet-rosterurdetforflutna', | |
cae5d970 | 40 | 'md5': 'a02393c74f3bdb1801c3ec2695577ce0', |
846fd69b MW |
41 | 'info_dict': { |
42 | 'id': '2a92b283-1a75-4ad8-8396-499c641de0d9', | |
43 | 'ext': 'mp3', | |
44 | 'title': '2. Raggarmordet - Röster ur det förflutna', | |
cae5d970 | 45 | 'description': 'md5:4f81f6d8cf2e12ee21a321d8bca32db4', |
846fd69b MW |
46 | 'timestamp': 1477346700, |
47 | 'upload_date': '20161024', | |
cae5d970 S |
48 | 'duration': 2766.602563, |
49 | 'creator': 'Anton Berg & Martin Johnson', | |
50 | 'series': 'Spår', | |
51 | 'episode': '2. Raggarmordet - Röster ur det förflutna', | |
846fd69b MW |
52 | } |
53 | }] | |
50e12e9d | 54 | |
55 | def _real_extract(self, url): | |
56 | channel, display_id = re.match(self._VALID_URL, url).groups() | |
1c9b1a44 S |
57 | s = self._download_json( |
58 | 'https://play-api.acast.com/stitch/%s/%s' % (channel, display_id), | |
59 | display_id)['result'] | |
60 | media_url = s['url'] | |
a1ff3cd5 | 61 | cast_data = self._download_json( |
cae5d970 S |
62 | 'https://play-api.acast.com/splash/%s/%s' % (channel, display_id), |
63 | display_id)['result'] | |
64 | e = cast_data['episode'] | |
65 | title = e['name'] | |
50e12e9d | 66 | return { |
b5e531f3 | 67 | 'id': compat_str(e['id']), |
50e12e9d | 68 | 'display_id': display_id, |
1c9b1a44 | 69 | 'url': media_url, |
cae5d970 S |
70 | 'title': title, |
71 | 'description': e.get('description') or e.get('summary'), | |
b5e531f3 MW |
72 | 'thumbnail': e.get('image'), |
73 | 'timestamp': unified_timestamp(e.get('publishingDate')), | |
1c9b1a44 | 74 | 'duration': float_or_none(s.get('duration') or e.get('duration')), |
cae5d970 S |
75 | 'filesize': int_or_none(e.get('contentLength')), |
76 | 'creator': try_get(cast_data, lambda x: x['show']['author'], compat_str), | |
77 | 'series': try_get(cast_data, lambda x: x['show']['name'], compat_str), | |
78 | 'season_number': int_or_none(e.get('seasonNumber')), | |
79 | 'episode': title, | |
80 | 'episode_number': int_or_none(e.get('episodeNumber')), | |
50e12e9d | 81 | } |
82 | ||
83 | ||
9934fe76 | 84 | class ACastChannelIE(InfoExtractor): |
50e12e9d | 85 | IE_NAME = 'acast:channel' |
86 | _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<id>[^/#?]+)' | |
87 | _TEST = { | |
ab3b773b | 88 | 'url': 'https://www.acast.com/condenasttraveler', |
50e12e9d | 89 | 'info_dict': { |
ab3b773b | 90 | 'id': '50544219-29bb-499e-a083-6087f4cb7797', |
91 | 'title': 'Condé Nast Traveler Podcast', | |
92 | 'description': 'md5:98646dee22a5b386626ae31866638fbd', | |
50e12e9d | 93 | }, |
ab3b773b | 94 | 'playlist_mincount': 20, |
50e12e9d | 95 | } |
9934fe76 | 96 | _API_BASE_URL = 'https://www.acast.com/api/' |
a1ff3cd5 | 97 | _PAGE_SIZE = 10 |
50e12e9d | 98 | |
ab3b773b | 99 | @classmethod |
100 | def suitable(cls, url): | |
101 | return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url) | |
102 | ||
a1ff3cd5 | 103 | def _fetch_page(self, channel_slug, page): |
104 | casts = self._download_json( | |
105 | self._API_BASE_URL + 'channels/%s/acasts?page=%s' % (channel_slug, page), | |
106 | channel_slug, note='Download page %d of channel data' % page) | |
107 | for cast in casts: | |
108 | yield self.url_result( | |
109 | 'https://www.acast.com/%s/%s' % (channel_slug, cast['url']), | |
110 | 'ACast', cast['id']) | |
50e12e9d | 111 | |
a1ff3cd5 | 112 | def _real_extract(self, url): |
113 | channel_slug = self._match_id(url) | |
114 | channel_data = self._download_json( | |
115 | self._API_BASE_URL + 'channels/%s' % channel_slug, channel_slug) | |
116 | entries = OnDemandPagedList(functools.partial( | |
117 | self._fetch_page, channel_slug), self._PAGE_SIZE) | |
118 | return self.playlist_result(entries, compat_str( | |
119 | channel_data['id']), channel_data['name'], channel_data.get('description')) |