2019-04-07 11:39:48 +00:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
2019-11-02 17:13:31 +00:00
|
|
|
compat_str,
|
2019-04-07 11:39:48 +00:00
|
|
|
float_or_none,
|
|
|
|
int_or_none,
|
2021-01-08 16:14:50 +00:00
|
|
|
smuggle_url,
|
|
|
|
str_or_none,
|
|
|
|
try_get,
|
2019-04-07 11:39:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class STVPlayerIE(InfoExtractor):
|
|
|
|
IE_NAME = 'stv:player'
|
|
|
|
_VALID_URL = r'https?://player\.stv\.tv/(?P<type>episode|video)/(?P<id>[a-z0-9]{4})'
|
2021-01-08 16:14:50 +00:00
|
|
|
_TESTS = [{
|
|
|
|
# shortform
|
2019-11-02 17:13:31 +00:00
|
|
|
'url': 'https://player.stv.tv/video/4gwd/emmerdale/60-seconds-on-set-with-laura-norton/',
|
|
|
|
'md5': '5adf9439c31d554f8be0707c7abe7e0a',
|
2019-04-07 11:39:48 +00:00
|
|
|
'info_dict': {
|
2019-11-02 17:13:31 +00:00
|
|
|
'id': '5333973339001',
|
2019-04-07 11:39:48 +00:00
|
|
|
'ext': 'mp4',
|
2019-11-02 17:13:31 +00:00
|
|
|
'upload_date': '20170301',
|
|
|
|
'title': '60 seconds on set with Laura Norton',
|
|
|
|
'description': "How many questions can Laura - a.k.a Kerry Wyatt - answer in 60 seconds? Let\'s find out!",
|
|
|
|
'timestamp': 1488388054,
|
2019-04-07 11:39:48 +00:00
|
|
|
'uploader_id': '1486976045',
|
|
|
|
},
|
|
|
|
'skip': 'this resource is unavailable outside of the UK',
|
2021-01-08 16:14:50 +00:00
|
|
|
}, {
|
|
|
|
# episodes
|
|
|
|
'url': 'https://player.stv.tv/episode/4125/jennifer-saunders-memory-lane',
|
|
|
|
'only_matching': True,
|
|
|
|
}]
|
2019-11-02 17:13:31 +00:00
|
|
|
BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/1486976045/default_default/index.html?videoId=%s'
|
2019-04-07 11:39:48 +00:00
|
|
|
_PTYPE_MAP = {
|
|
|
|
'episode': 'episodes',
|
|
|
|
'video': 'shortform',
|
|
|
|
}
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-08-19 01:41:24 +00:00
|
|
|
ptype, video_id = self._match_valid_url(url).groups()
|
2019-04-07 11:39:48 +00:00
|
|
|
|
2021-01-08 16:14:50 +00:00
|
|
|
webpage = self._download_webpage(url, video_id, fatal=False) or ''
|
|
|
|
props = (self._parse_json(self._search_regex(
|
|
|
|
r'<script[^>]+id="__NEXT_DATA__"[^>]*>({.+?})</script>',
|
|
|
|
webpage, 'next data', default='{}'), video_id,
|
|
|
|
fatal=False) or {}).get('props') or {}
|
|
|
|
player_api_cache = try_get(
|
|
|
|
props, lambda x: x['initialReduxState']['playerApiCache']) or {}
|
|
|
|
|
|
|
|
api_path, resp = None, {}
|
|
|
|
for k, v in player_api_cache.items():
|
|
|
|
if k.startswith('/episodes/') or k.startswith('/shortform/'):
|
|
|
|
api_path, resp = k, v
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
episode_id = str_or_none(try_get(
|
|
|
|
props, lambda x: x['pageProps']['episodeId']))
|
|
|
|
api_path = '/%s/%s' % (self._PTYPE_MAP[ptype], episode_id or video_id)
|
|
|
|
|
|
|
|
result = resp.get('results')
|
|
|
|
if not result:
|
|
|
|
resp = self._download_json(
|
|
|
|
'https://player.api.stv.tv/v1' + api_path, video_id)
|
|
|
|
result = resp['results']
|
|
|
|
|
2019-11-02 17:13:31 +00:00
|
|
|
video = result['video']
|
|
|
|
video_id = compat_str(video['id'])
|
2019-04-07 11:39:48 +00:00
|
|
|
|
2019-11-02 17:13:31 +00:00
|
|
|
subtitles = {}
|
|
|
|
_subtitles = result.get('_subtitles') or {}
|
|
|
|
for ext, sub_url in _subtitles.items():
|
|
|
|
subtitles.setdefault('en', []).append({
|
|
|
|
'ext': 'vtt' if ext == 'webvtt' else ext,
|
|
|
|
'url': sub_url,
|
|
|
|
})
|
2019-04-07 11:39:48 +00:00
|
|
|
|
2019-11-02 17:13:31 +00:00
|
|
|
programme = result.get('programme') or {}
|
2019-04-07 11:39:48 +00:00
|
|
|
|
2019-11-02 17:13:31 +00:00
|
|
|
return {
|
2019-04-07 11:39:48 +00:00
|
|
|
'_type': 'url_transparent',
|
|
|
|
'id': video_id,
|
2021-01-08 16:14:50 +00:00
|
|
|
'url': smuggle_url(self.BRIGHTCOVE_URL_TEMPLATE % video_id, {'geo_countries': ['GB']}),
|
2019-11-02 17:13:31 +00:00
|
|
|
'description': result.get('summary'),
|
|
|
|
'duration': float_or_none(video.get('length'), 1000),
|
|
|
|
'subtitles': subtitles,
|
|
|
|
'view_count': int_or_none(result.get('views')),
|
|
|
|
'series': programme.get('name') or programme.get('shortName'),
|
2019-04-07 11:39:48 +00:00
|
|
|
'ie_key': 'BrightcoveNew',
|
2019-11-02 17:13:31 +00:00
|
|
|
}
|