]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/acast.py
[tmz] delegate extraction to KalturaIE
[yt-dlp.git] / youtube_dl / 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 (
10 int_or_none,
11 OnDemandPagedList,
12)
50e12e9d 13
14
9934fe76 15class ACastIE(InfoExtractor):
50e12e9d 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,
a8aad210 26 'description': 'md5:a0b4ef3634e63866b542e5b1199a1a0e',
ab3b773b 27 'duration': 211,
50e12e9d 28 }
29 }
30
31 def _real_extract(self, url):
32 channel, display_id = re.match(self._VALID_URL, url).groups()
a1ff3cd5 33 cast_data = self._download_json(
34 'https://embed.acast.com/api/acasts/%s/%s' % (channel, display_id), display_id)
50e12e9d 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
9934fe76 47class ACastChannelIE(InfoExtractor):
50e12e9d 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 }
9934fe76 59 _API_BASE_URL = 'https://www.acast.com/api/'
a1ff3cd5 60 _PAGE_SIZE = 10
50e12e9d 61
ab3b773b 62 @classmethod
63 def suitable(cls, url):
64 return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url)
65
a1ff3cd5 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'])
50e12e9d 74
a1ff3cd5 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'))