]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/acast.py
Update the changelog.
[youtubedl] / youtube_dl / extractor / acast.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import functools
6
7 from .common import InfoExtractor
8 from ..compat import compat_str
9 from ..utils import (
10 int_or_none,
11 OnDemandPagedList,
12 )
13
14
15 class ACastIE(InfoExtractor):
16 IE_NAME = 'acast'
17 _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<channel>[^/]+)/(?P<id>[^/#?]+)'
18 _TEST = {
19 'url': 'https://www.acast.com/condenasttraveler/-where-are-you-taipei-101-taiwan',
20 'md5': 'ada3de5a1e3a2a381327d749854788bb',
21 'info_dict': {
22 'id': '57de3baa-4bb0-487e-9418-2692c1277a34',
23 'ext': 'mp3',
24 'title': '"Where Are You?": Taipei 101, Taiwan',
25 'timestamp': 1196172000000,
26 'description': 'md5:a0b4ef3634e63866b542e5b1199a1a0e',
27 'duration': 211,
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(
34 'https://embed.acast.com/api/acasts/%s/%s' % (channel, display_id), display_id)
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(InfoExtractor):
48 IE_NAME = 'acast:channel'
49 _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<id>[^/#?]+)'
50 _TEST = {
51 'url': 'https://www.acast.com/condenasttraveler',
52 'info_dict': {
53 'id': '50544219-29bb-499e-a083-6087f4cb7797',
54 'title': 'Condé Nast Traveler Podcast',
55 'description': 'md5:98646dee22a5b386626ae31866638fbd',
56 },
57 'playlist_mincount': 20,
58 }
59 _API_BASE_URL = 'https://www.acast.com/api/'
60 _PAGE_SIZE = 10
61
62 @classmethod
63 def suitable(cls, url):
64 return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url)
65
66 def _fetch_page(self, channel_slug, page):
67 casts = self._download_json(
68 self._API_BASE_URL + 'channels/%s/acasts?page=%s' % (channel_slug, page),
69 channel_slug, note='Download page %d of channel data' % page)
70 for cast in casts:
71 yield self.url_result(
72 'https://www.acast.com/%s/%s' % (channel_slug, cast['url']),
73 'ACast', cast['id'])
74
75 def _real_extract(self, url):
76 channel_slug = self._match_id(url)
77 channel_data = self._download_json(
78 self._API_BASE_URL + 'channels/%s' % channel_slug, channel_slug)
79 entries = OnDemandPagedList(functools.partial(
80 self._fetch_page, channel_slug), self._PAGE_SIZE)
81 return self.playlist_result(entries, compat_str(
82 channel_data['id']), channel_data['name'], channel_data.get('description'))