]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/acast.py
[extractors] Add missing age limits
[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 (
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 18class ACastIE(InfoExtractor):
50e12e9d 19 IE_NAME = 'acast'
50a498a6
S
20 _VALID_URL = r'''(?x)
21 https?://
22 (?:
23 (?:(?:embed|www)\.)?acast\.com/|
24 play\.acast\.com/s/
25 )
26 (?P<channel>[^/]+)/(?P<id>[^/#?]+)
27 '''
846fd69b 28 _TESTS = [{
846fd69b 29 'url': 'https://www.acast.com/sparpodcast/2.raggarmordet-rosterurdetforflutna',
cae5d970 30 'md5': 'a02393c74f3bdb1801c3ec2695577ce0',
846fd69b
MW
31 'info_dict': {
32 'id': '2a92b283-1a75-4ad8-8396-499c641de0d9',
33 'ext': 'mp3',
34 'title': '2. Raggarmordet - Röster ur det förflutna',
cae5d970 35 'description': 'md5:4f81f6d8cf2e12ee21a321d8bca32db4',
846fd69b
MW
36 'timestamp': 1477346700,
37 'upload_date': '20161024',
cae5d970
S
38 'duration': 2766.602563,
39 'creator': 'Anton Berg & Martin Johnson',
40 'series': 'Spår',
41 'episode': '2. Raggarmordet - Röster ur det förflutna',
846fd69b 42 }
252e172d
TL
43 }, {
44 'url': 'http://embed.acast.com/adambuxton/ep.12-adam-joeschristmaspodcast2015',
45 'only_matching': True,
50a498a6
S
46 }, {
47 'url': 'https://play.acast.com/s/rattegangspodden/s04e09-styckmordet-i-helenelund-del-22',
48 'only_matching': True,
846fd69b 49 }]
50e12e9d 50
51 def _real_extract(self, url):
52 channel, display_id = re.match(self._VALID_URL, url).groups()
1c9b1a44
S
53 s = self._download_json(
54 'https://play-api.acast.com/stitch/%s/%s' % (channel, display_id),
55 display_id)['result']
56 media_url = s['url']
a1ff3cd5 57 cast_data = self._download_json(
cae5d970
S
58 'https://play-api.acast.com/splash/%s/%s' % (channel, display_id),
59 display_id)['result']
60 e = cast_data['episode']
61 title = e['name']
50e12e9d 62 return {
b5e531f3 63 'id': compat_str(e['id']),
50e12e9d 64 'display_id': display_id,
1c9b1a44 65 'url': media_url,
cae5d970
S
66 'title': title,
67 'description': e.get('description') or e.get('summary'),
b5e531f3
MW
68 'thumbnail': e.get('image'),
69 'timestamp': unified_timestamp(e.get('publishingDate')),
1c9b1a44 70 'duration': float_or_none(s.get('duration') or e.get('duration')),
cae5d970
S
71 'filesize': int_or_none(e.get('contentLength')),
72 'creator': try_get(cast_data, lambda x: x['show']['author'], compat_str),
73 'series': try_get(cast_data, lambda x: x['show']['name'], compat_str),
74 'season_number': int_or_none(e.get('seasonNumber')),
75 'episode': title,
76 'episode_number': int_or_none(e.get('episodeNumber')),
50e12e9d 77 }
78
79
9934fe76 80class ACastChannelIE(InfoExtractor):
50e12e9d 81 IE_NAME = 'acast:channel'
82 _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<id>[^/#?]+)'
83 _TEST = {
ab3b773b 84 'url': 'https://www.acast.com/condenasttraveler',
50e12e9d 85 'info_dict': {
ab3b773b 86 'id': '50544219-29bb-499e-a083-6087f4cb7797',
87 'title': 'Condé Nast Traveler Podcast',
88 'description': 'md5:98646dee22a5b386626ae31866638fbd',
50e12e9d 89 },
ab3b773b 90 'playlist_mincount': 20,
50e12e9d 91 }
9934fe76 92 _API_BASE_URL = 'https://www.acast.com/api/'
a1ff3cd5 93 _PAGE_SIZE = 10
50e12e9d 94
ab3b773b 95 @classmethod
96 def suitable(cls, url):
97 return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url)
98
a1ff3cd5 99 def _fetch_page(self, channel_slug, page):
100 casts = self._download_json(
101 self._API_BASE_URL + 'channels/%s/acasts?page=%s' % (channel_slug, page),
102 channel_slug, note='Download page %d of channel data' % page)
103 for cast in casts:
104 yield self.url_result(
105 'https://www.acast.com/%s/%s' % (channel_slug, cast['url']),
106 'ACast', cast['id'])
50e12e9d 107
a1ff3cd5 108 def _real_extract(self, url):
109 channel_slug = self._match_id(url)
110 channel_data = self._download_json(
111 self._API_BASE_URL + 'channels/%s' % channel_slug, channel_slug)
112 entries = OnDemandPagedList(functools.partial(
113 self._fetch_page, channel_slug), self._PAGE_SIZE)
114 return self.playlist_result(entries, compat_str(
115 channel_data['id']), channel_data['name'], channel_data.get('description'))