]>
Commit | Line | Data |
---|---|---|
1 | # coding: utf-8 | |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
8 | clean_html, | |
9 | int_or_none, | |
10 | parse_iso8601, | |
11 | ) | |
12 | ||
13 | ||
14 | class ACastBaseIE(InfoExtractor): | |
15 | def _extract_episode(self, episode, show_info): | |
16 | title = episode['title'] | |
17 | info = { | |
18 | 'id': episode['id'], | |
19 | 'display_id': episode.get('episodeUrl'), | |
20 | 'url': episode['url'], | |
21 | 'title': title, | |
22 | 'description': clean_html(episode.get('description') or episode.get('summary')), | |
23 | 'thumbnail': episode.get('image'), | |
24 | 'timestamp': parse_iso8601(episode.get('publishDate')), | |
25 | 'duration': int_or_none(episode.get('duration')), | |
26 | 'filesize': int_or_none(episode.get('contentLength')), | |
27 | 'season_number': int_or_none(episode.get('season')), | |
28 | 'episode': title, | |
29 | 'episode_number': int_or_none(episode.get('episode')), | |
30 | } | |
31 | info.update(show_info) | |
32 | return info | |
33 | ||
34 | def _extract_show_info(self, show): | |
35 | return { | |
36 | 'creator': show.get('author'), | |
37 | 'series': show.get('title'), | |
38 | } | |
39 | ||
40 | def _call_api(self, path, video_id, query=None): | |
41 | return self._download_json( | |
42 | 'https://feeder.acast.com/api/v1/shows/' + path, video_id, query=query) | |
43 | ||
44 | ||
45 | class ACastIE(ACastBaseIE): | |
46 | IE_NAME = 'acast' | |
47 | _VALID_URL = r'''(?x) | |
48 | https?:// | |
49 | (?: | |
50 | (?:(?:embed|www)\.)?acast\.com/| | |
51 | play\.acast\.com/s/ | |
52 | ) | |
53 | (?P<channel>[^/]+)/(?P<id>[^/#?]+) | |
54 | ''' | |
55 | _TESTS = [{ | |
56 | 'url': 'https://www.acast.com/sparpodcast/2.raggarmordet-rosterurdetforflutna', | |
57 | 'md5': 'f5598f3ad1e4776fed12ec1407153e4b', | |
58 | 'info_dict': { | |
59 | 'id': '2a92b283-1a75-4ad8-8396-499c641de0d9', | |
60 | 'ext': 'mp3', | |
61 | 'title': '2. Raggarmordet - Röster ur det förflutna', | |
62 | 'description': 'md5:a992ae67f4d98f1c0141598f7bebbf67', | |
63 | 'timestamp': 1477346700, | |
64 | 'upload_date': '20161024', | |
65 | 'duration': 2766, | |
66 | 'creator': 'Anton Berg & Martin Johnson', | |
67 | 'series': 'Spår', | |
68 | 'episode': '2. Raggarmordet - Röster ur det förflutna', | |
69 | } | |
70 | }, { | |
71 | 'url': 'http://embed.acast.com/adambuxton/ep.12-adam-joeschristmaspodcast2015', | |
72 | 'only_matching': True, | |
73 | }, { | |
74 | 'url': 'https://play.acast.com/s/rattegangspodden/s04e09styckmordetihelenelund-del2-2', | |
75 | 'only_matching': True, | |
76 | }, { | |
77 | 'url': 'https://play.acast.com/s/sparpodcast/2a92b283-1a75-4ad8-8396-499c641de0d9', | |
78 | 'only_matching': True, | |
79 | }] | |
80 | ||
81 | def _real_extract(self, url): | |
82 | channel, display_id = re.match(self._VALID_URL, url).groups() | |
83 | episode = self._call_api( | |
84 | '%s/episodes/%s' % (channel, display_id), | |
85 | display_id, {'showInfo': 'true'}) | |
86 | return self._extract_episode( | |
87 | episode, self._extract_show_info(episode.get('show') or {})) | |
88 | ||
89 | ||
90 | class ACastChannelIE(ACastBaseIE): | |
91 | IE_NAME = 'acast:channel' | |
92 | _VALID_URL = r'''(?x) | |
93 | https?:// | |
94 | (?: | |
95 | (?:www\.)?acast\.com/| | |
96 | play\.acast\.com/s/ | |
97 | ) | |
98 | (?P<id>[^/#?]+) | |
99 | ''' | |
100 | _TESTS = [{ | |
101 | 'url': 'https://www.acast.com/todayinfocus', | |
102 | 'info_dict': { | |
103 | 'id': '4efc5294-5385-4847-98bd-519799ce5786', | |
104 | 'title': 'Today in Focus', | |
105 | 'description': 'md5:c09ce28c91002ce4ffce71d6504abaae', | |
106 | }, | |
107 | 'playlist_mincount': 200, | |
108 | }, { | |
109 | 'url': 'http://play.acast.com/s/ft-banking-weekly', | |
110 | 'only_matching': True, | |
111 | }] | |
112 | ||
113 | @classmethod | |
114 | def suitable(cls, url): | |
115 | return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url) | |
116 | ||
117 | def _real_extract(self, url): | |
118 | show_slug = self._match_id(url) | |
119 | show = self._call_api(show_slug, show_slug) | |
120 | show_info = self._extract_show_info(show) | |
121 | entries = [] | |
122 | for episode in (show.get('episodes') or []): | |
123 | entries.append(self._extract_episode(episode, show_info)) | |
124 | return self.playlist_result( | |
125 | entries, show.get('id'), show.get('title'), show.get('description')) |