[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / stv.py
blobc489e4237cd7347f23cdbe96307267e5bf0ea1c2
1 from .common import InfoExtractor
2 from ..utils import (
3 float_or_none,
4 int_or_none,
5 smuggle_url,
6 str_or_none,
7 try_get,
11 class STVPlayerIE(InfoExtractor):
12 IE_NAME = 'stv:player'
13 _VALID_URL = r'https?://player\.stv\.tv/(?P<type>episode|video)/(?P<id>[a-z0-9]{4})'
14 _TESTS = [{
15 # shortform
16 'url': 'https://player.stv.tv/video/4gwd/emmerdale/60-seconds-on-set-with-laura-norton/',
17 'md5': '5adf9439c31d554f8be0707c7abe7e0a',
18 'info_dict': {
19 'id': '5333973339001',
20 'ext': 'mp4',
21 'upload_date': '20170301',
22 'title': '60 seconds on set with Laura Norton',
23 'description': "How many questions can Laura - a.k.a Kerry Wyatt - answer in 60 seconds? Let's find out!",
24 'timestamp': 1488388054,
25 'uploader_id': '1486976045',
27 'skip': 'this resource is unavailable outside of the UK',
28 }, {
29 # episodes
30 'url': 'https://player.stv.tv/episode/4125/jennifer-saunders-memory-lane',
31 'only_matching': True,
33 BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/1486976045/default_default/index.html?videoId=%s'
34 _PTYPE_MAP = {
35 'episode': 'episodes',
36 'video': 'shortform',
39 def _real_extract(self, url):
40 ptype, video_id = self._match_valid_url(url).groups()
42 webpage = self._download_webpage(url, video_id, fatal=False) or ''
43 props = self._search_nextjs_data(webpage, video_id, default={}).get('props') or {}
44 player_api_cache = try_get(
45 props, lambda x: x['initialReduxState']['playerApiCache']) or {}
47 api_path, resp = None, {}
48 for k, v in player_api_cache.items():
49 if k.startswith(('/episodes/', '/shortform/')):
50 api_path, resp = k, v
51 break
52 else:
53 episode_id = str_or_none(try_get(
54 props, lambda x: x['pageProps']['episodeId']))
55 api_path = f'/{self._PTYPE_MAP[ptype]}/{episode_id or video_id}'
57 result = resp.get('results')
58 if not result:
59 resp = self._download_json(
60 'https://player.api.stv.tv/v1' + api_path, video_id)
61 result = resp['results']
63 video = result['video']
64 video_id = str(video['id'])
66 subtitles = {}
67 _subtitles = result.get('_subtitles') or {}
68 for ext, sub_url in _subtitles.items():
69 subtitles.setdefault('en', []).append({
70 'ext': 'vtt' if ext == 'webvtt' else ext,
71 'url': sub_url,
74 programme = result.get('programme') or {}
75 if programme.get('drmEnabled'):
76 self.report_drm(video_id)
78 return {
79 '_type': 'url_transparent',
80 'id': video_id,
81 'url': smuggle_url(self.BRIGHTCOVE_URL_TEMPLATE % video_id, {'geo_countries': ['GB']}),
82 'description': result.get('summary'),
83 'duration': float_or_none(video.get('length'), 1000),
84 'subtitles': subtitles,
85 'view_count': int_or_none(result.get('views')),
86 'series': programme.get('name') or programme.get('shortName'),
87 'ie_key': 'BrightcoveNew',