1 from .common
import InfoExtractor
2 from ..compat
import compat_str
12 class STVPlayerIE(InfoExtractor
):
13 IE_NAME
= 'stv:player'
14 _VALID_URL
= r
'https?://player\.stv\.tv/(?P<type>episode|video)/(?P<id>[a-z0-9]{4})'
17 'url': 'https://player.stv.tv/video/4gwd/emmerdale/60-seconds-on-set-with-laura-norton/',
18 'md5': '5adf9439c31d554f8be0707c7abe7e0a',
20 'id': '5333973339001',
22 'upload_date': '20170301',
23 'title': '60 seconds on set with Laura Norton',
24 'description': "How many questions can Laura - a.k.a Kerry Wyatt - answer in 60 seconds? Let\'s find out!",
25 'timestamp': 1488388054,
26 'uploader_id': '1486976045',
28 'skip': 'this resource is unavailable outside of the UK',
31 'url': 'https://player.stv.tv/episode/4125/jennifer-saunders-memory-lane',
32 'only_matching': True,
34 BRIGHTCOVE_URL_TEMPLATE
= 'http://players.brightcove.net/1486976045/default_default/index.html?videoId=%s'
36 'episode': 'episodes',
40 def _real_extract(self
, url
):
41 ptype
, video_id
= self
._match
_valid
_url
(url
).groups()
43 webpage
= self
._download
_webpage
(url
, video_id
, fatal
=False) or ''
44 props
= self
._search
_nextjs
_data
(webpage
, video_id
, default
='{}').get('props') or {}
45 player_api_cache
= try_get(
46 props
, lambda x
: x
['initialReduxState']['playerApiCache']) or {}
48 api_path
, resp
= None, {}
49 for k
, v
in player_api_cache
.items():
50 if k
.startswith('/episodes/') or k
.startswith('/shortform/'):
54 episode_id
= str_or_none(try_get(
55 props
, lambda x
: x
['pageProps']['episodeId']))
56 api_path
= '/%s/%s' % (self
._PTYPE
_MAP
[ptype
], episode_id
or video_id
)
58 result
= resp
.get('results')
60 resp
= self
._download
_json
(
61 'https://player.api.stv.tv/v1' + api_path
, video_id
)
62 result
= resp
['results']
64 video
= result
['video']
65 video_id
= compat_str(video
['id'])
68 _subtitles
= result
.get('_subtitles') or {}
69 for ext
, sub_url
in _subtitles
.items():
70 subtitles
.setdefault('en', []).append({
71 'ext': 'vtt' if ext
== 'webvtt' else ext
,
75 programme
= result
.get('programme') or {}
76 if programme
.get('drmEnabled'):
77 self
.report_drm(video_id
)
80 '_type': 'url_transparent',
82 'url': smuggle_url(self
.BRIGHTCOVE_URL_TEMPLATE
% video_id
, {'geo_countries': ['GB']}),
83 'description': result
.get('summary'),
84 'duration': float_or_none(video
.get('length'), 1000),
85 'subtitles': subtitles
,
86 'view_count': int_or_none(result
.get('views')),
87 'series': programme
.get('name') or programme
.get('shortName'),
88 'ie_key': 'BrightcoveNew',