]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/itv.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 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
_m
3u8_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': 'https://www.itv.com/btcc/articles/btcc-2019-brands-hatch-gp-race-action',
158 'id': 'btcc-2019-brands-hatch-gp-race-action',
159 'title': 'BTCC 2019: Brands Hatch GP race action',
161 'playlist_count': 12,
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
)
170 json_map
= try_get(self
._parse
_json
(self
._html
_search
_regex
(
171 '(?s)<script[^>]+id=[\'"]__NEXT_DATA__[^>]*>([^<]+)</script>', webpage
, 'json_map'), playlist_id
),
172 lambda x
: x
['props']['pageProps']['article']['body']['content']) or []
174 # Discard empty objects
176 for video
in json_map
:
177 if video
['data'].get('id'):
178 video_ids
.append(video
['data']['id'])
182 smuggle_url(self
.BRIGHTCOVE_URL_TEMPLATE
% video_id
, {
183 # ITV does not like some GB IP ranges, so here are some
184 # IP blocks it accepts
186 '193.113.0.0/16', '54.36.162.0/23', '159.65.16.0/21'
190 ie
=BrightcoveNewIE
.ie_key(), video_id
=video_id
)
191 for video_id
in video_ids
]
193 title
= self
._og
_search
_title
(webpage
, fatal
=False)
195 return self
.playlist_result(entries
, playlist_id
, title
)