]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/stitcher.py
[cbs] Add support for ParamountPlus (#138)
[yt-dlp.git] / yt_dlp / extractor / stitcher.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 clean_html,
8 ExtractorError,
9 int_or_none,
10 str_or_none,
11 try_get,
12 )
13
14
15 class StitcherIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?stitcher\.com/(?:podcast|show)/(?:[^/]+/)+e(?:pisode)?/(?:(?P<display_id>[^/#?&]+?)-)?(?P<id>\d+)(?:[/#?&]|$)'
17 _TESTS = [{
18 'url': 'http://www.stitcher.com/podcast/the-talking-machines/e/40789481?autoplay=true',
19 'md5': 'e9635098e0da10b21a0e2b85585530f6',
20 'info_dict': {
21 'id': '40789481',
22 'ext': 'mp3',
23 'title': 'Machine Learning Mastery and Cancer Clusters',
24 'description': 'md5:547adb4081864be114ae3831b4c2b42f',
25 'duration': 1604,
26 'thumbnail': r're:^https?://.*\.jpg',
27 'upload_date': '20180126',
28 'timestamp': 1516989316,
29 },
30 }, {
31 'url': 'http://www.stitcher.com/podcast/panoply/vulture-tv/e/the-rare-hourlong-comedy-plus-40846275?autoplay=true',
32 'info_dict': {
33 'id': '40846275',
34 'display_id': 'the-rare-hourlong-comedy-plus',
35 'ext': 'mp3',
36 'title': "The CW's 'Crazy Ex-Girlfriend'",
37 'description': 'md5:04f1e2f98eb3f5cbb094cea0f9e19b17',
38 'duration': 2235,
39 'thumbnail': r're:^https?://.*\.jpg',
40 },
41 'params': {
42 'skip_download': True,
43 },
44 'skip': 'Page Not Found',
45 }, {
46 # escaped title
47 'url': 'http://www.stitcher.com/podcast/marketplace-on-stitcher/e/40910226?autoplay=true',
48 'only_matching': True,
49 }, {
50 'url': 'http://www.stitcher.com/podcast/panoply/getting-in/e/episode-2a-how-many-extracurriculars-should-i-have-40876278?autoplay=true',
51 'only_matching': True,
52 }, {
53 'url': 'https://www.stitcher.com/show/threedom/episode/circles-on-a-stick-200212584',
54 'only_matching': True,
55 }]
56
57 def _real_extract(self, url):
58 display_id, audio_id = re.match(self._VALID_URL, url).groups()
59
60 resp = self._download_json(
61 'https://api.prod.stitcher.com/episode/' + audio_id,
62 display_id or audio_id)
63 episode = try_get(resp, lambda x: x['data']['episodes'][0], dict)
64 if not episode:
65 raise ExtractorError(resp['errors'][0]['message'], expected=True)
66
67 title = episode['title'].strip()
68 audio_url = episode['audio_url']
69
70 thumbnail = None
71 show_id = episode.get('show_id')
72 if show_id and episode.get('classic_id') != -1:
73 thumbnail = 'https://stitcher-classic.imgix.net/feedimages/%s.jpg' % show_id
74
75 return {
76 'id': audio_id,
77 'display_id': display_id,
78 'title': title,
79 'description': clean_html(episode.get('html_description') or episode.get('description')),
80 'duration': int_or_none(episode.get('duration')),
81 'thumbnail': thumbnail,
82 'url': audio_url,
83 'vcodec': 'none',
84 'timestamp': int_or_none(episode.get('date_created')),
85 'season_number': int_or_none(episode.get('season')),
86 'season_id': str_or_none(episode.get('season_id')),
87 }