2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
9 compat_urllib_parse_urlparse
19 class STVPlayerIE(InfoExtractor
):
20 IE_NAME
= 'stv:player'
21 _VALID_URL
= r
'https?://player\.stv\.tv/(?P<type>episode|video)/(?P<id>[a-z0-9]{4})'
23 'url': 'https://player.stv.tv/video/7srz/victoria/interview-with-the-cast-ahead-of-new-victoria/',
24 'md5': '2ad867d4afd641fa14187596e0fbc91b',
26 'id': '6016487034001',
28 'upload_date': '20190321',
29 'title': 'Interview with the cast ahead of new Victoria',
30 'description': 'Nell Hudson and Lily Travers tell us what to expect in the new season of Victoria.',
31 'timestamp': 1553179628,
32 'uploader_id': '1486976045',
34 'skip': 'this resource is unavailable outside of the UK',
36 _PUBLISHER_ID
= '1486976045'
38 'episode': 'episodes',
42 def _real_extract(self
, url
):
43 ptype
, video_id
= re
.match(self
._VALID
_URL
, url
).groups()
44 webpage
= self
._download
_webpage
(url
, video_id
)
46 qs
= compat_parse_qs(compat_urllib_parse_urlparse(self
._search
_regex
(
47 r
'itemprop="embedURL"[^>]+href="([^"]+)',
48 webpage
, 'embed URL', default
=None)).query
)
49 publisher_id
= qs
.get('publisherID', [None])[0] or self
._PUBLISHER
_ID
51 player_attr
= extract_attributes(self
._search
_regex
(
52 r
'(<[^>]+class="bcplayer"[^>]+>)', webpage
, 'player', default
=None)) or {}
55 duration
= ref_id
= series
= video_id
= None
56 api_ref_id
= player_attr
.get('data-player-api-refid')
58 resp
= self
._download
_json
(
59 'https://player.api.stv.tv/v1/%s/%s' % (self
._PTYPE
_MAP
[ptype
], api_ref_id
),
60 api_ref_id
, fatal
=False)
62 result
= resp
.get('results') or {}
63 video
= result
.get('video') or {}
64 video_id
= str_or_none(video
.get('id'))
65 ref_id
= video
.get('guid')
66 duration
= video
.get('length')
67 programme
= result
.get('programme') or {}
68 series
= programme
.get('name') or programme
.get('shortName')
70 _subtitles
= result
.get('_subtitles') or {}
71 for ext
, sub_url
in _subtitles
.items():
72 subtitles
.setdefault('en', []).append({
73 'ext': 'vtt' if ext
== 'webvtt' else ext
,
77 'description': result
.get('summary'),
78 'subtitles': subtitles
,
79 'view_count': int_or_none(result
.get('views')),
82 video_id
= qs
.get('videoId', [None])[0] or self
._search
_regex
(
83 r
'<link\s+itemprop="url"\s+href="(\d+)"',
84 webpage
, 'video id', default
=None) or 'ref:' + (ref_id
or player_attr
['data-refid'])
87 '_type': 'url_transparent',
88 'duration': float_or_none(duration
or player_attr
.get('data-duration'), 1000),
90 'ie_key': 'BrightcoveNew',
91 'series': series
or player_attr
.get('data-programme-name'),
92 'url': 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s' % (publisher_id
, video_id
),