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