]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/corus.py
[test/download] Fallback test to `bv`
[yt-dlp.git] / yt_dlp / extractor / corus.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4
5 from .theplatform import ThePlatformFeedIE
6 from ..utils import (
7 dict_get,
8 ExtractorError,
9 float_or_none,
10 int_or_none,
11 )
12
13
14 class CorusIE(ThePlatformFeedIE):
15 _VALID_URL = r'''(?x)
16 https?://
17 (?:www\.)?
18 (?P<domain>
19 (?:
20 globaltv|
21 etcanada|
22 seriesplus|
23 wnetwork|
24 ytv
25 )\.com|
26 (?:
27 hgtv|
28 foodnetwork|
29 slice|
30 history|
31 showcase|
32 bigbrothercanada|
33 abcspark|
34 disney(?:channel|lachaine)
35 )\.ca
36 )
37 /(?:[^/]+/)*
38 (?:
39 video\.html\?.*?\bv=|
40 videos?/(?:[^/]+/)*(?:[a-z0-9-]+-)?
41 )
42 (?P<id>
43 [\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}|
44 (?:[A-Z]{4})?\d{12,20}
45 )
46 '''
47 _TESTS = [{
48 'url': 'http://www.hgtv.ca/shows/bryan-inc/videos/movie-night-popcorn-with-bryan-870923331648/',
49 'info_dict': {
50 'id': '870923331648',
51 'ext': 'mp4',
52 'title': 'Movie Night Popcorn with Bryan',
53 'description': 'Bryan whips up homemade popcorn, the old fashion way for Jojo and Lincoln.',
54 'upload_date': '20170206',
55 'timestamp': 1486392197,
56 },
57 'params': {
58 'skip_download': True,
59 },
60 'expected_warnings': ['Failed to parse JSON'],
61 }, {
62 'url': 'http://www.foodnetwork.ca/shows/chopped/video/episode/chocolate-obsession/video.html?v=872683587753',
63 'only_matching': True,
64 }, {
65 'url': 'http://etcanada.com/video/873675331955/meet-the-survivor-game-changers-castaways-part-2/',
66 'only_matching': True,
67 }, {
68 'url': 'http://www.history.ca/the-world-without-canada/video/full-episodes/natural-resources/video.html?v=955054659646#video',
69 'only_matching': True,
70 }, {
71 'url': 'http://www.showcase.ca/eyewitness/video/eyewitness++106/video.html?v=955070531919&p=1&s=da#video',
72 'only_matching': True,
73 }, {
74 'url': 'http://www.bigbrothercanada.ca/video/1457812035894/',
75 'only_matching': True
76 }, {
77 'url': 'https://www.bigbrothercanada.ca/video/big-brother-canada-704/1457812035894/',
78 'only_matching': True
79 }, {
80 'url': 'https://www.seriesplus.com/emissions/dre-mary-mort-sur-ordonnance/videos/deux-coeurs-battant/SERP0055626330000200/',
81 'only_matching': True
82 }, {
83 'url': 'https://www.disneychannel.ca/shows/gabby-duran-the-unsittables/video/crybaby-duran-clip/2f557eec-0588-11ea-ae2b-e2c6776b770e/',
84 'only_matching': True
85 }]
86 _GEO_BYPASS = False
87 _SITE_MAP = {
88 'globaltv': 'series',
89 'etcanada': 'series',
90 'foodnetwork': 'food',
91 'bigbrothercanada': 'series',
92 'disneychannel': 'disneyen',
93 'disneylachaine': 'disneyfr',
94 }
95
96 def _real_extract(self, url):
97 domain, video_id = self._match_valid_url(url).groups()
98 site = domain.split('.')[0]
99 path = self._SITE_MAP.get(site, site)
100 if path != 'series':
101 path = 'migration/' + path
102 video = self._download_json(
103 'https://globalcontent.corusappservices.com/templates/%s/playlist/' % path,
104 video_id, query={'byId': video_id},
105 headers={'Accept': 'application/json'})[0]
106 title = video['title']
107
108 formats = []
109 for source in video.get('sources', []):
110 smil_url = source.get('file')
111 if not smil_url:
112 continue
113 source_type = source.get('type')
114 note = 'Downloading%s smil file' % (' ' + source_type if source_type else '')
115 resp = self._download_webpage(
116 smil_url, video_id, note, fatal=False,
117 headers=self.geo_verification_headers())
118 if not resp:
119 continue
120 error = self._parse_json(resp, video_id, fatal=False)
121 if error:
122 if error.get('exception') == 'GeoLocationBlocked':
123 self.raise_geo_restricted(countries=['CA'])
124 raise ExtractorError(error['description'])
125 smil = self._parse_xml(resp, video_id, fatal=False)
126 if smil is None:
127 continue
128 namespace = self._parse_smil_namespace(smil)
129 formats.extend(self._parse_smil_formats(
130 smil, smil_url, video_id, namespace))
131 if not formats and video.get('drm'):
132 self.report_drm(video_id)
133 self._sort_formats(formats)
134
135 subtitles = {}
136 for track in video.get('tracks', []):
137 track_url = track.get('file')
138 if not track_url:
139 continue
140 lang = 'fr' if site in ('disneylachaine', 'seriesplus') else 'en'
141 subtitles.setdefault(lang, []).append({'url': track_url})
142
143 metadata = video.get('metadata') or {}
144 get_number = lambda x: int_or_none(video.get('pl1$' + x) or metadata.get(x + 'Number'))
145
146 return {
147 'id': video_id,
148 'title': title,
149 'formats': formats,
150 'thumbnail': dict_get(video, ('defaultThumbnailUrl', 'thumbnail', 'image')),
151 'description': video.get('description'),
152 'timestamp': int_or_none(video.get('availableDate'), 1000),
153 'subtitles': subtitles,
154 'duration': float_or_none(metadata.get('duration')),
155 'series': dict_get(video, ('show', 'pl1$show')),
156 'season_number': get_number('season'),
157 'episode_number': get_number('episode'),
158 }