]> jfr.im git - yt-dlp.git/blame - youtube_dlc/extractor/acast.py
Update to ytdl-2021.01.03
[yt-dlp.git] / youtube_dlc / extractor / acast.py
CommitLineData
50e12e9d 1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
a1ff3cd5 7from ..utils import (
976e1ff7 8 clean_html,
cae5d970 9 int_or_none,
29f7c58a 10 parse_iso8601,
a1ff3cd5 11)
50e12e9d 12
13
29f7c58a 14class 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
45class ACastIE(ACastBaseIE):
50e12e9d 46 IE_NAME = 'acast'
50a498a6
S
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 '''
846fd69b 55 _TESTS = [{
846fd69b 56 'url': 'https://www.acast.com/sparpodcast/2.raggarmordet-rosterurdetforflutna',
29f7c58a 57 'md5': 'f5598f3ad1e4776fed12ec1407153e4b',
846fd69b
MW
58 'info_dict': {
59 'id': '2a92b283-1a75-4ad8-8396-499c641de0d9',
60 'ext': 'mp3',
61 'title': '2. Raggarmordet - Röster ur det förflutna',
29f7c58a 62 'description': 'md5:a992ae67f4d98f1c0141598f7bebbf67',
846fd69b
MW
63 'timestamp': 1477346700,
64 'upload_date': '20161024',
29f7c58a 65 'duration': 2766,
cae5d970
S
66 'creator': 'Anton Berg & Martin Johnson',
67 'series': 'Spår',
68 'episode': '2. Raggarmordet - Röster ur det förflutna',
846fd69b 69 }
252e172d
TL
70 }, {
71 'url': 'http://embed.acast.com/adambuxton/ep.12-adam-joeschristmaspodcast2015',
72 'only_matching': True,
50a498a6 73 }, {
29f7c58a 74 'url': 'https://play.acast.com/s/rattegangspodden/s04e09styckmordetihelenelund-del2-2',
50a498a6 75 'only_matching': True,
976e1ff7
RA
76 }, {
77 'url': 'https://play.acast.com/s/sparpodcast/2a92b283-1a75-4ad8-8396-499c641de0d9',
78 'only_matching': True,
846fd69b 79 }]
50e12e9d 80
81 def _real_extract(self, url):
82 channel, display_id = re.match(self._VALID_URL, url).groups()
29f7c58a 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 {}))
50e12e9d 88
89
29f7c58a 90class ACastChannelIE(ACastBaseIE):
50e12e9d 91 IE_NAME = 'acast:channel'
0e713dbb 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',
50e12e9d 102 'info_dict': {
0e713dbb 103 'id': '4efc5294-5385-4847-98bd-519799ce5786',
104 'title': 'Today in Focus',
29f7c58a 105 'description': 'md5:c09ce28c91002ce4ffce71d6504abaae',
50e12e9d 106 },
29f7c58a 107 'playlist_mincount': 200,
0e713dbb 108 }, {
109 'url': 'http://play.acast.com/s/ft-banking-weekly',
110 'only_matching': True,
111 }]
50e12e9d 112
ab3b773b 113 @classmethod
114 def suitable(cls, url):
115 return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url)
116
a1ff3cd5 117 def _real_extract(self, url):
29f7c58a 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'))