2 from __future__
import unicode_literals
5 import xml
.etree
.ElementTree
as etree
8 from .common
import InfoExtractor
11 compat_etree_register_namespace
,
25 class ITVIE(InfoExtractor
):
26 _VALID_URL
= r
'https?://(?:www\.)?itv\.com/hub/[^/]+/(?P<id>[0-9a-zA-Z]+)'
28 'url': 'http://www.itv.com/hub/mr-bean-animated-series/2a2936a0053',
32 'title': 'Home Movie',
36 'skip_download': True,
40 def _real_extract(self
, url
):
41 video_id
= self
._match
_id
(url
)
42 webpage
= self
._download
_webpage
(url
, video_id
)
43 params
= extract_attributes(self
._search
_regex
(
44 r
'(?s)(<[^>]+id="video"[^>]*>)', webpage
, 'params'))
47 'soapenv': 'http://schemas.xmlsoap.org/soap/envelope/',
48 'tem': 'http://tempuri.org/',
49 'itv': 'http://schemas.datacontract.org/2004/07/Itv.BB.Mercury.Common.Types',
50 'com': 'http://schemas.itv.com/2009/05/Common',
52 for ns
, full_ns
in ns_map
.items():
53 compat_etree_register_namespace(ns
, full_ns
)
56 return xpath_with_ns(name
, ns_map
)
58 def _add_sub_element(element
, name
):
59 return etree
.SubElement(element
, _add_ns(name
))
61 req_env
= etree
.Element(_add_ns('soapenv:Envelope'))
62 _add_sub_element(req_env
, 'soapenv:Header')
63 body
= _add_sub_element(req_env
, 'soapenv:Body')
64 get_playlist
= _add_sub_element(body
, ('tem:GetPlaylist'))
65 request
= _add_sub_element(get_playlist
, 'tem:request')
66 _add_sub_element(request
, 'itv:ProductionId').text
= params
['data-video-id']
67 _add_sub_element(request
, 'itv:RequestGuid').text
= compat_str(uuid
.uuid4()).upper()
68 vodcrid
= _add_sub_element(request
, 'itv:Vodcrid')
69 _add_sub_element(vodcrid
, 'com:Id')
70 _add_sub_element(request
, 'itv:Partition')
71 user_info
= _add_sub_element(get_playlist
, 'tem:userInfo')
72 _add_sub_element(user_info
, 'itv:Broadcaster').text
= 'Itv'
73 _add_sub_element(user_info
, 'itv:DM')
74 _add_sub_element(user_info
, 'itv:RevenueScienceValue')
75 _add_sub_element(user_info
, 'itv:SessionId')
76 _add_sub_element(user_info
, 'itv:SsoToken')
77 _add_sub_element(user_info
, 'itv:UserToken')
78 site_info
= _add_sub_element(get_playlist
, 'tem:siteInfo')
79 _add_sub_element(site_info
, 'itv:AdvertisingRestriction').text
= 'None'
80 _add_sub_element(site_info
, 'itv:AdvertisingSite').text
= 'ITV'
81 _add_sub_element(site_info
, 'itv:AdvertisingType').text
= 'Any'
82 _add_sub_element(site_info
, 'itv:Area').text
= 'ITVPLAYER.VIDEO'
83 _add_sub_element(site_info
, 'itv:Category')
84 _add_sub_element(site_info
, 'itv:Platform').text
= 'DotCom'
85 _add_sub_element(site_info
, 'itv:Site').text
= 'ItvCom'
86 device_info
= _add_sub_element(get_playlist
, 'tem:deviceInfo')
87 _add_sub_element(device_info
, 'itv:ScreenSize').text
= 'Big'
88 player_info
= _add_sub_element(get_playlist
, 'tem:playerInfo')
89 _add_sub_element(player_info
, 'itv:Version').text
= '2'
91 headers
= self
.geo_verification_headers()
93 'Content-Type': 'text/xml; charset=utf-8',
94 'SOAPAction': 'http://tempuri.org/PlaylistService/GetPlaylist',
96 resp_env
= self
._download
_xml
(
97 params
['data-playlist-url'], video_id
,
98 headers
=headers
, data
=etree
.tostring(req_env
))
99 playlist
= xpath_element(resp_env
, './/Playlist')
101 fault_string
= xpath_text(resp_env
, './/faultstring')
102 raise ExtractorError('%s said: %s' % (self
.IE_NAME
, fault_string
))
103 title
= xpath_text(playlist
, 'EpisodeTitle', fatal
=True)
104 video_element
= xpath_element(playlist
, 'VideoEntries/Video', fatal
=True)
105 media_files
= xpath_element(video_element
, 'MediaFiles', fatal
=True)
106 rtmp_url
= media_files
.attrib
['base']
109 for media_file
in media_files
.findall('MediaFile'):
110 play_path
= xpath_text(media_file
, 'URL')
113 tbr
= int_or_none(media_file
.get('bitrate'), 1000)
115 'format_id': 'rtmp' + ('-%d' % tbr
if tbr
else ''),
117 'play_path': play_path
,
122 ios_playlist_url
= params
.get('data-video-playlist')
123 hmac
= params
.get('data-video-hmac')
124 if ios_playlist_url
and hmac
:
125 headers
= self
.geo_verification_headers()
127 'Accept': 'application/vnd.itv.vod.playlist.v2+json',
128 'Content-Type': 'application/json',
129 'hmac': hmac
.upper(),
131 ios_playlist
= self
._download
_json
(
132 ios_playlist_url
, video_id
, data
=json
.dumps({
139 'manufacturer': 'Apple',
151 'variantAvailability': {
153 'min': ['hls', 'aes'],
154 'max': ['hls', 'aes']
156 'platformTag': 'mobile'
158 }).encode(), headers
=headers
, fatal
=False)
160 video_data
= ios_playlist
.get('Playlist', {}).get('Video', {})
161 ios_base_url
= video_data
.get('Base')
162 for media_file
in video_data
.get('MediaFiles', []):
163 href
= media_file
.get('Href')
167 href
= ios_base_url
+ href
168 ext
= determine_ext(href
)
170 formats
.extend(self
._extract
_m
3u8_formats
(href
, video_id
, 'mp4', m3u8_id
='hls', fatal
=False))
175 self
._sort
_formats
(formats
)
178 for caption_url
in video_element
.findall('ClosedCaptioningURIs/URL'):
179 if not caption_url
.text
:
181 ext
= determine_ext(caption_url
.text
, 'ttml')
182 subtitles
.setdefault('en', []).append({
183 'url': caption_url
.text
,
184 'ext': 'ttml' if ext
== 'xml' else ext
,
191 'subtitles': subtitles
,
192 'episode_title': title
,
193 'episode_number': int_or_none(xpath_text(playlist
, 'EpisodeNumber')),
194 'series': xpath_text(playlist
, 'ProgrammeTitle'),
195 'duartion': parse_duration(xpath_text(playlist
, 'Duration')),