]>
Commit | Line | Data |
---|---|---|
c7d6f614 RA |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
c7d6f614 RA |
4 | |
5 | from .theplatform import ThePlatformFeedIE | |
df65a4a1 RA |
6 | from ..utils import ( |
7 | dict_get, | |
8 | ExtractorError, | |
9 | float_or_none, | |
10 | int_or_none, | |
11 | ) | |
c7d6f614 RA |
12 | |
13 | ||
14 | class CorusIE(ThePlatformFeedIE): | |
97fa1f8d S |
15 | _VALID_URL = r'''(?x) |
16 | https?:// | |
17 | (?:www\.)? | |
18 | (?P<domain> | |
df65a4a1 RA |
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} | |
97fa1f8d | 45 | ) |
97fa1f8d | 46 | ''' |
c7d6f614 RA |
47 | _TESTS = [{ |
48 | 'url': 'http://www.hgtv.ca/shows/bryan-inc/videos/movie-night-popcorn-with-bryan-870923331648/', | |
c7d6f614 RA |
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.', | |
c7d6f614 RA |
54 | 'upload_date': '20170206', |
55 | 'timestamp': 1486392197, | |
56 | }, | |
df65a4a1 RA |
57 | 'params': { |
58 | 'format': 'bestvideo', | |
59 | 'skip_download': True, | |
60 | }, | |
61 | 'expected_warnings': ['Failed to parse JSON'], | |
c7d6f614 RA |
62 | }, { |
63 | 'url': 'http://www.foodnetwork.ca/shows/chopped/video/episode/chocolate-obsession/video.html?v=872683587753', | |
64 | 'only_matching': True, | |
65 | }, { | |
66 | 'url': 'http://etcanada.com/video/873675331955/meet-the-survivor-game-changers-castaways-part-2/', | |
67 | 'only_matching': True, | |
97fa1f8d S |
68 | }, { |
69 | 'url': 'http://www.history.ca/the-world-without-canada/video/full-episodes/natural-resources/video.html?v=955054659646#video', | |
70 | 'only_matching': True, | |
b5dc33da S |
71 | }, { |
72 | 'url': 'http://www.showcase.ca/eyewitness/video/eyewitness++106/video.html?v=955070531919&p=1&s=da#video', | |
73 | 'only_matching': True, | |
a63782b5 | 74 | }, { |
75 | 'url': 'http://www.bigbrothercanada.ca/video/1457812035894/', | |
76 | 'only_matching': True | |
77 | }, { | |
78 | 'url': 'https://www.bigbrothercanada.ca/video/big-brother-canada-704/1457812035894/', | |
79 | 'only_matching': True | |
df65a4a1 RA |
80 | }, { |
81 | 'url': 'https://www.seriesplus.com/emissions/dre-mary-mort-sur-ordonnance/videos/deux-coeurs-battant/SERP0055626330000200/', | |
82 | 'only_matching': True | |
83 | }, { | |
84 | 'url': 'https://www.disneychannel.ca/shows/gabby-duran-the-unsittables/video/crybaby-duran-clip/2f557eec-0588-11ea-ae2b-e2c6776b770e/', | |
85 | 'only_matching': True | |
c7d6f614 | 86 | }] |
df65a4a1 RA |
87 | _GEO_BYPASS = False |
88 | _SITE_MAP = { | |
89 | 'globaltv': 'series', | |
90 | 'etcanada': 'series', | |
91 | 'foodnetwork': 'food', | |
92 | 'bigbrothercanada': 'series', | |
93 | 'disneychannel': 'disneyen', | |
94 | 'disneylachaine': 'disneyfr', | |
c7d6f614 RA |
95 | } |
96 | ||
97 | def _real_extract(self, url): | |
5ad28e7f | 98 | domain, video_id = self._match_valid_url(url).groups() |
df65a4a1 RA |
99 | site = domain.split('.')[0] |
100 | path = self._SITE_MAP.get(site, site) | |
101 | if path != 'series': | |
102 | path = 'migration/' + path | |
103 | video = self._download_json( | |
104 | 'https://globalcontent.corusappservices.com/templates/%s/playlist/' % path, | |
105 | video_id, query={'byId': video_id}, | |
106 | headers={'Accept': 'application/json'})[0] | |
107 | title = video['title'] | |
108 | ||
109 | formats = [] | |
110 | for source in video.get('sources', []): | |
111 | smil_url = source.get('file') | |
112 | if not smil_url: | |
113 | continue | |
114 | source_type = source.get('type') | |
115 | note = 'Downloading%s smil file' % (' ' + source_type if source_type else '') | |
116 | resp = self._download_webpage( | |
117 | smil_url, video_id, note, fatal=False, | |
118 | headers=self.geo_verification_headers()) | |
119 | if not resp: | |
120 | continue | |
121 | error = self._parse_json(resp, video_id, fatal=False) | |
122 | if error: | |
123 | if error.get('exception') == 'GeoLocationBlocked': | |
124 | self.raise_geo_restricted(countries=['CA']) | |
125 | raise ExtractorError(error['description']) | |
126 | smil = self._parse_xml(resp, video_id, fatal=False) | |
127 | if smil is None: | |
128 | continue | |
129 | namespace = self._parse_smil_namespace(smil) | |
130 | formats.extend(self._parse_smil_formats( | |
131 | smil, smil_url, video_id, namespace)) | |
132 | if not formats and video.get('drm'): | |
b7da73eb | 133 | self.raise_no_formats('This video is DRM protected.', expected=True) |
df65a4a1 RA |
134 | self._sort_formats(formats) |
135 | ||
136 | subtitles = {} | |
137 | for track in video.get('tracks', []): | |
138 | track_url = track.get('file') | |
139 | if not track_url: | |
140 | continue | |
141 | lang = 'fr' if site in ('disneylachaine', 'seriesplus') else 'en' | |
142 | subtitles.setdefault(lang, []).append({'url': track_url}) | |
143 | ||
144 | metadata = video.get('metadata') or {} | |
145 | get_number = lambda x: int_or_none(video.get('pl1$' + x) or metadata.get(x + 'Number')) | |
146 | ||
147 | return { | |
148 | 'id': video_id, | |
149 | 'title': title, | |
150 | 'formats': formats, | |
151 | 'thumbnail': dict_get(video, ('defaultThumbnailUrl', 'thumbnail', 'image')), | |
152 | 'description': video.get('description'), | |
153 | 'timestamp': int_or_none(video.get('availableDate'), 1000), | |
154 | 'subtitles': subtitles, | |
155 | 'duration': float_or_none(metadata.get('duration')), | |
156 | 'series': dict_get(video, ('show', 'pl1$show')), | |
157 | 'season_number': get_number('season'), | |
158 | 'episode_number': get_number('episode'), | |
159 | } |