2 from __future__ import unicode_literals
7 from .common import InfoExtractor
8 from .brightcove import BrightcoveNewIE
22 class ITVIE(InfoExtractor):
23 _VALID_URL = r'https?://(?:www\.)?itv\.com/hub/[^/]+/(?P<id>[0-9a-zA-Z]+)'
24 _GEO_COUNTRIES = ['GB']
26 'url': 'https://www.itv.com/hub/liar/2a4547a0012',
30 'title': 'Liar - Series 2 - Episode 6',
31 'description': 'md5:d0f91536569dec79ea184f0a44cca089',
38 'skip_download': True,
41 # unavailable via data-playlist-url
42 'url': 'https://www.itv.com/hub/through-the-keyhole/2a2271a0033',
43 'only_matching': True,
46 'url': 'https://www.itv.com/hub/james-martins-saturday-morning/2a5159a0034',
47 'only_matching': True,
50 'url': 'https://www.itv.com/hub/whos-doing-the-dishes/2a2898a0024',
51 'only_matching': True,
54 def _real_extract(self, url):
55 video_id = self._match_id(url)
56 webpage = self._download_webpage(url, video_id)
57 params = extract_attributes(self._search_regex(
58 r'(?s)(<[^>]+id="video"[^>]*>)', webpage, 'params'))
60 ios_playlist_url = params.get('data-video-playlist') or params['data-video-id']
61 hmac = params['data-video-hmac']
62 headers = self.geo_verification_headers()
64 'Accept': 'application/vnd.itv.vod.playlist.v2+json',
65 'Content-Type': 'application/json',
68 ios_playlist = self._download_json(
69 ios_playlist_url, video_id, data=json.dumps({
76 'manufacturer': 'Safari',
88 'variantAvailability': {
90 'min': ['hls', 'aes', 'outband-webvtt'],
91 'max': ['hls', 'aes', 'outband-webvtt']
93 'platformTag': 'dotcom'
95 }).encode(), headers=headers)
96 video_data = ios_playlist['Playlist']['Video']
97 ios_base_url = video_data.get('Base')
100 for media_file in (video_data.get('MediaFiles') or []):
101 href = media_file.get('Href')
105 href = ios_base_url + href
106 ext = determine_ext(href)
108 formats.extend(self._extract_m3u8_formats(
109 href, video_id, 'mp4', entry_protocol='m3u8_native',
110 m3u8_id='hls', fatal=False))
115 self._sort_formats(formats)
118 subs = video_data.get('Subtitles') or []
120 if not isinstance(sub, dict):
122 href = url_or_none(sub.get('Href'))
125 subtitles.setdefault('en', []).append({
127 'ext': determine_ext(href, 'vtt'),
130 info = self._search_json_ld(webpage, video_id, default={})
132 json_ld = self._parse_json(self._search_regex(
133 JSON_LD_RE, webpage, 'JSON-LD', '{}',
134 group='json_ld'), video_id, fatal=False)
135 if json_ld and json_ld.get('@type') == 'BreadcrumbList':
136 for ile in (json_ld.get('itemListElement:') or []):
137 item = ile.get('item:') or {}
138 if item.get('@type') == 'TVEpisode':
139 item['@context'] = 'http://schema.org'
140 info = self._json_ld(item, video_id, fatal=False) or {}
145 'title': self._html_search_meta(['og:title', 'twitter:title'], webpage),
147 'subtitles': subtitles,
148 'duration': parse_duration(video_data.get('Duration')),
149 'description': clean_html(get_element_by_class('episode-info__synopsis', webpage)),
153 class ITVBTCCIE(InfoExtractor):
154 _VALID_URL = r'https?://(?:www\.)?itv\.com/btcc/(?:[^/]+/)*(?P<id>[^/?#&]+)'
156 'url': 'http://www.itv.com/btcc/races/btcc-2018-all-the-action-from-brands-hatch',
158 'id': 'btcc-2018-all-the-action-from-brands-hatch',
159 'title': 'BTCC 2018: All the action from Brands Hatch',
161 'playlist_mincount': 9,
163 BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/1582188683001/HkiHLnNRx_default/index.html?videoId=%s'
165 def _real_extract(self, url):
166 playlist_id = self._match_id(url)
168 webpage = self._download_webpage(url, playlist_id)
172 smuggle_url(self.BRIGHTCOVE_URL_TEMPLATE % video_id, {
173 # ITV does not like some GB IP ranges, so here are some
174 # IP blocks it accepts
176 '193.113.0.0/16', '54.36.162.0/23', '159.65.16.0/21'
180 ie=BrightcoveNewIE.ie_key(), video_id=video_id)
181 for video_id in re.findall(r'data-video-id=["\'](\d+)', webpage)]
183 title = self._og_search_title(webpage, fatal=False)
185 return self.playlist_result(entries, playlist_id, title)