]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/acast.py
Update 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 float_or_none,
11 int_or_none,
12 try_get,
13 unified_timestamp,
14 OnDemandPagedList,
15 )
16
17
18 class ACastIE(InfoExtractor):
19 IE_NAME = 'acast'
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 '''
28 _TESTS = [{
29 'url': 'https://www.acast.com/sparpodcast/2.raggarmordet-rosterurdetforflutna',
30 'md5': 'a02393c74f3bdb1801c3ec2695577ce0',
31 'info_dict': {
32 'id': '2a92b283-1a75-4ad8-8396-499c641de0d9',
33 'ext': 'mp3',
34 'title': '2. Raggarmordet - Röster ur det förflutna',
35 'description': 'md5:4f81f6d8cf2e12ee21a321d8bca32db4',
36 'timestamp': 1477346700,
37 'upload_date': '20161024',
38 'duration': 2766.602563,
39 'creator': 'Anton Berg & Martin Johnson',
40 'series': 'Spår',
41 'episode': '2. Raggarmordet - Röster ur det förflutna',
42 }
43 }, {
44 'url': 'http://embed.acast.com/adambuxton/ep.12-adam-joeschristmaspodcast2015',
45 'only_matching': True,
46 }, {
47 'url': 'https://play.acast.com/s/rattegangspodden/s04e09-styckmordet-i-helenelund-del-22',
48 'only_matching': True,
49 }]
50
51 def _real_extract(self, url):
52 channel, display_id = re.match(self._VALID_URL, url).groups()
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']
57 cast_data = self._download_json(
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']
62 return {
63 'id': compat_str(e['id']),
64 'display_id': display_id,
65 'url': media_url,
66 'title': title,
67 'description': e.get('description') or e.get('summary'),
68 'thumbnail': e.get('image'),
69 'timestamp': unified_timestamp(e.get('publishingDate')),
70 'duration': float_or_none(s.get('duration') or e.get('duration')),
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')),
77 }
78
79
80 class ACastChannelIE(InfoExtractor):
81 IE_NAME = 'acast:channel'
82 _VALID_URL = r'''(?x)
83 https?://
84 (?:
85 (?:www\.)?acast\.com/|
86 play\.acast\.com/s/
87 )
88 (?P<id>[^/#?]+)
89 '''
90 _TESTS = [{
91 'url': 'https://www.acast.com/todayinfocus',
92 'info_dict': {
93 'id': '4efc5294-5385-4847-98bd-519799ce5786',
94 'title': 'Today in Focus',
95 'description': 'md5:9ba5564de5ce897faeb12963f4537a64',
96 },
97 'playlist_mincount': 35,
98 }, {
99 'url': 'http://play.acast.com/s/ft-banking-weekly',
100 'only_matching': True,
101 }]
102 _API_BASE_URL = 'https://play.acast.com/api/'
103 _PAGE_SIZE = 10
104
105 @classmethod
106 def suitable(cls, url):
107 return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url)
108
109 def _fetch_page(self, channel_slug, page):
110 casts = self._download_json(
111 self._API_BASE_URL + 'channels/%s/acasts?page=%s' % (channel_slug, page),
112 channel_slug, note='Download page %d of channel data' % page)
113 for cast in casts:
114 yield self.url_result(
115 'https://play.acast.com/s/%s/%s' % (channel_slug, cast['url']),
116 'ACast', cast['id'])
117
118 def _real_extract(self, url):
119 channel_slug = self._match_id(url)
120 channel_data = self._download_json(
121 self._API_BASE_URL + 'channels/%s' % channel_slug, channel_slug)
122 entries = OnDemandPagedList(functools.partial(
123 self._fetch_page, channel_slug), self._PAGE_SIZE)
124 return self.playlist_result(entries, compat_str(
125 channel_data['id']), channel_data['name'], channel_data.get('description'))