]>
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 ( |
10 | int_or_none, | |
12da8309 | 11 | parse_iso8601, |
a1ff3cd5 | 12 | OnDemandPagedList, |
13 | ) | |
50e12e9d | 14 | |
15 | ||
9934fe76 | 16 | class ACastIE(InfoExtractor): |
50e12e9d | 17 | IE_NAME = 'acast' |
18 | _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<channel>[^/]+)/(?P<id>[^/#?]+)' | |
846fd69b MW |
19 | _TESTS = [{ |
20 | # test with one bling | |
ab3b773b | 21 | 'url': 'https://www.acast.com/condenasttraveler/-where-are-you-taipei-101-taiwan', |
22 | 'md5': 'ada3de5a1e3a2a381327d749854788bb', | |
50e12e9d | 23 | 'info_dict': { |
ab3b773b | 24 | 'id': '57de3baa-4bb0-487e-9418-2692c1277a34', |
50e12e9d | 25 | 'ext': 'mp3', |
ab3b773b | 26 | 'title': '"Where Are You?": Taipei 101, Taiwan', |
12da8309 MW |
27 | 'timestamp': 1196172000, |
28 | 'upload_date': '20071127', | |
a8aad210 | 29 | 'description': 'md5:a0b4ef3634e63866b542e5b1199a1a0e', |
ab3b773b | 30 | 'duration': 211, |
50e12e9d | 31 | } |
846fd69b MW |
32 | }, { |
33 | # test with multiple blings | |
34 | 'url': 'https://www.acast.com/sparpodcast/2.raggarmordet-rosterurdetforflutna', | |
35 | 'md5': '55c0097badd7095f494c99a172f86501', | |
36 | 'info_dict': { | |
37 | 'id': '2a92b283-1a75-4ad8-8396-499c641de0d9', | |
38 | 'ext': 'mp3', | |
39 | 'title': '2. Raggarmordet - Röster ur det förflutna', | |
40 | 'timestamp': 1477346700, | |
41 | 'upload_date': '20161024', | |
42 | 'description': 'md5:4f81f6d8cf2e12ee21a321d8bca32db4', | |
43 | 'duration': 2797, | |
44 | } | |
45 | }] | |
50e12e9d | 46 | |
47 | def _real_extract(self, url): | |
48 | channel, display_id = re.match(self._VALID_URL, url).groups() | |
a1ff3cd5 | 49 | cast_data = self._download_json( |
50 | 'https://embed.acast.com/api/acasts/%s/%s' % (channel, display_id), display_id) | |
50e12e9d | 51 | return { |
52 | 'id': compat_str(cast_data['id']), | |
53 | 'display_id': display_id, | |
12da8309 | 54 | 'url': [b['audio'] for b in cast_data['blings'] if b['type'] == 'BlingAudio'][0], |
50e12e9d | 55 | 'title': cast_data['name'], |
56 | 'description': cast_data.get('description'), | |
57 | 'thumbnail': cast_data.get('image'), | |
12da8309 | 58 | 'timestamp': parse_iso8601(cast_data.get('publishingDate')), |
50e12e9d | 59 | 'duration': int_or_none(cast_data.get('duration')), |
60 | } | |
61 | ||
62 | ||
9934fe76 | 63 | class ACastChannelIE(InfoExtractor): |
50e12e9d | 64 | IE_NAME = 'acast:channel' |
65 | _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<id>[^/#?]+)' | |
66 | _TEST = { | |
ab3b773b | 67 | 'url': 'https://www.acast.com/condenasttraveler', |
50e12e9d | 68 | 'info_dict': { |
ab3b773b | 69 | 'id': '50544219-29bb-499e-a083-6087f4cb7797', |
70 | 'title': 'Condé Nast Traveler Podcast', | |
71 | 'description': 'md5:98646dee22a5b386626ae31866638fbd', | |
50e12e9d | 72 | }, |
ab3b773b | 73 | 'playlist_mincount': 20, |
50e12e9d | 74 | } |
9934fe76 | 75 | _API_BASE_URL = 'https://www.acast.com/api/' |
a1ff3cd5 | 76 | _PAGE_SIZE = 10 |
50e12e9d | 77 | |
ab3b773b | 78 | @classmethod |
79 | def suitable(cls, url): | |
80 | return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url) | |
81 | ||
a1ff3cd5 | 82 | def _fetch_page(self, channel_slug, page): |
83 | casts = self._download_json( | |
84 | self._API_BASE_URL + 'channels/%s/acasts?page=%s' % (channel_slug, page), | |
85 | channel_slug, note='Download page %d of channel data' % page) | |
86 | for cast in casts: | |
87 | yield self.url_result( | |
88 | 'https://www.acast.com/%s/%s' % (channel_slug, cast['url']), | |
89 | 'ACast', cast['id']) | |
50e12e9d | 90 | |
a1ff3cd5 | 91 | def _real_extract(self, url): |
92 | channel_slug = self._match_id(url) | |
93 | channel_data = self._download_json( | |
94 | self._API_BASE_URL + 'channels/%s' % channel_slug, channel_slug) | |
95 | entries = OnDemandPagedList(functools.partial( | |
96 | self._fetch_page, channel_slug), self._PAGE_SIZE) | |
97 | return self.playlist_result(entries, compat_str( | |
98 | channel_data['id']), channel_data['name'], channel_data.get('description')) |