]>
Commit | Line | Data |
---|---|---|
50e12e9d | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..compat import compat_str | |
8 | from ..utils import int_or_none | |
9 | ||
10 | ||
11 | class ACastBaseIE(InfoExtractor): | |
12 | _API_BASE_URL = 'https://www.acast.com/api/' | |
13 | ||
14 | ||
15 | class ACastIE(ACastBaseIE): | |
16 | IE_NAME = 'acast' | |
17 | _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<channel>[^/]+)/(?P<id>[^/#?]+)' | |
18 | _TEST = { | |
ab3b773b | 19 | 'url': 'https://www.acast.com/condenasttraveler/-where-are-you-taipei-101-taiwan', |
20 | 'md5': 'ada3de5a1e3a2a381327d749854788bb', | |
50e12e9d | 21 | 'info_dict': { |
ab3b773b | 22 | 'id': '57de3baa-4bb0-487e-9418-2692c1277a34', |
50e12e9d | 23 | 'ext': 'mp3', |
ab3b773b | 24 | 'title': '"Where Are You?": Taipei 101, Taiwan', |
25 | 'timestamp': 1196172000000, | |
26 | 'description': 'md5:0c5d8201dfea2b93218ea986c91eee6e', | |
27 | 'duration': 211, | |
50e12e9d | 28 | } |
29 | } | |
30 | ||
31 | def _real_extract(self, url): | |
32 | channel, display_id = re.match(self._VALID_URL, url).groups() | |
33 | cast_data = self._download_json(self._API_BASE_URL + 'channels/%s/acasts/%s/playback' % (channel, display_id), display_id) | |
34 | ||
35 | return { | |
36 | 'id': compat_str(cast_data['id']), | |
37 | 'display_id': display_id, | |
38 | 'url': cast_data['blings'][0]['audio'], | |
39 | 'title': cast_data['name'], | |
40 | 'description': cast_data.get('description'), | |
41 | 'thumbnail': cast_data.get('image'), | |
42 | 'timestamp': int_or_none(cast_data.get('publishingDate')), | |
43 | 'duration': int_or_none(cast_data.get('duration')), | |
44 | } | |
45 | ||
46 | ||
47 | class ACastChannelIE(ACastBaseIE): | |
48 | IE_NAME = 'acast:channel' | |
49 | _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<id>[^/#?]+)' | |
50 | _TEST = { | |
ab3b773b | 51 | 'url': 'https://www.acast.com/condenasttraveler', |
50e12e9d | 52 | 'info_dict': { |
ab3b773b | 53 | 'id': '50544219-29bb-499e-a083-6087f4cb7797', |
54 | 'title': 'Condé Nast Traveler Podcast', | |
55 | 'description': 'md5:98646dee22a5b386626ae31866638fbd', | |
50e12e9d | 56 | }, |
ab3b773b | 57 | 'playlist_mincount': 20, |
50e12e9d | 58 | } |
59 | ||
ab3b773b | 60 | @classmethod |
61 | def suitable(cls, url): | |
62 | return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url) | |
63 | ||
50e12e9d | 64 | def _real_extract(self, url): |
65 | display_id = self._match_id(url) | |
66 | channel_data = self._download_json(self._API_BASE_URL + 'channels/%s' % display_id, display_id) | |
67 | casts = self._download_json(self._API_BASE_URL + 'channels/%s/acasts' % display_id, display_id) | |
68 | entries = [self.url_result('https://www.acast.com/%s/%s' % (display_id, cast['url']), 'ACast') for cast in casts] | |
69 | ||
70 | return self.playlist_result(entries, compat_str(channel_data['id']), channel_data['name'], channel_data.get('description')) |