2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
17 class STVPlayerIE(InfoExtractor
):
18 IE_NAME
= 'stv:player'
19 _VALID_URL
= r
'https?://player\.stv\.tv/(?P<type>episode|video)/(?P<id>[a-z0-9]{4})'
22 'url': 'https://player.stv.tv/video/4gwd/emmerdale/60-seconds-on-set-with-laura-norton/',
23 'md5': '5adf9439c31d554f8be0707c7abe7e0a',
25 'id': '5333973339001',
27 'upload_date': '20170301',
28 'title': '60 seconds on set with Laura Norton',
29 'description': "How many questions can Laura - a.k.a Kerry Wyatt - answer in 60 seconds? Let\'s find out!",
30 'timestamp': 1488388054,
31 'uploader_id': '1486976045',
33 'skip': 'this resource is unavailable outside of the UK',
36 'url': 'https://player.stv.tv/episode/4125/jennifer-saunders-memory-lane',
37 'only_matching': True,
39 BRIGHTCOVE_URL_TEMPLATE
= 'http://players.brightcove.net/1486976045/default_default/index.html?videoId=%s'
41 'episode': 'episodes',
45 def _real_extract(self
, url
):
46 ptype
, video_id
= re
.match(self
._VALID
_URL
, url
).groups()
48 webpage
= self
._download
_webpage
(url
, video_id
, fatal
=False) or ''
49 props
= (self
._parse
_json
(self
._search
_regex
(
50 r
'<script[^>]+id="__NEXT_DATA__"[^>]*>({.+?})</script>',
51 webpage
, 'next data', default
='{}'), video_id
,
52 fatal
=False) or {}).get('props') or {}
53 player_api_cache
= try_get(
54 props
, lambda x
: x
['initialReduxState']['playerApiCache']) or {}
56 api_path
, resp
= None, {}
57 for k
, v
in player_api_cache
.items():
58 if k
.startswith('/episodes/') or k
.startswith('/shortform/'):
62 episode_id
= str_or_none(try_get(
63 props
, lambda x
: x
['pageProps']['episodeId']))
64 api_path
= '/%s/%s' % (self
._PTYPE
_MAP
[ptype
], episode_id
or video_id
)
66 result
= resp
.get('results')
68 resp
= self
._download
_json
(
69 'https://player.api.stv.tv/v1' + api_path
, video_id
)
70 result
= resp
['results']
72 video
= result
['video']
73 video_id
= compat_str(video
['id'])
76 _subtitles
= result
.get('_subtitles') or {}
77 for ext
, sub_url
in _subtitles
.items():
78 subtitles
.setdefault('en', []).append({
79 'ext': 'vtt' if ext
== 'webvtt' else ext
,
83 programme
= result
.get('programme') or {}
86 '_type': 'url_transparent',
88 'url': smuggle_url(self
.BRIGHTCOVE_URL_TEMPLATE
% video_id
, {'geo_countries': ['GB']}
),
89 'description': result
.get('summary'),
90 'duration': float_or_none(video
.get('length'), 1000),
91 'subtitles': subtitles
,
92 'view_count': int_or_none(result
.get('views')),
93 'series': programme
.get('name') or programme
.get('shortName'),
94 'ie_key': 'BrightcoveNew',