]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..compat import compat_str | |
3 | from ..utils import ( | |
4 | float_or_none, | |
5 | int_or_none, | |
6 | smuggle_url, | |
7 | str_or_none, | |
8 | try_get, | |
9 | ) | |
10 | ||
11 | ||
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})' | |
15 | _TESTS = [{ | |
16 | # shortform | |
17 | 'url': 'https://player.stv.tv/video/4gwd/emmerdale/60-seconds-on-set-with-laura-norton/', | |
18 | 'md5': '5adf9439c31d554f8be0707c7abe7e0a', | |
19 | 'info_dict': { | |
20 | 'id': '5333973339001', | |
21 | 'ext': 'mp4', | |
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', | |
27 | }, | |
28 | 'skip': 'this resource is unavailable outside of the UK', | |
29 | }, { | |
30 | # episodes | |
31 | 'url': 'https://player.stv.tv/episode/4125/jennifer-saunders-memory-lane', | |
32 | 'only_matching': True, | |
33 | }] | |
34 | BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/1486976045/default_default/index.html?videoId=%s' | |
35 | _PTYPE_MAP = { | |
36 | 'episode': 'episodes', | |
37 | 'video': 'shortform', | |
38 | } | |
39 | ||
40 | def _real_extract(self, url): | |
41 | ptype, video_id = self._match_valid_url(url).groups() | |
42 | ||
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 {} | |
47 | ||
48 | api_path, resp = None, {} | |
49 | for k, v in player_api_cache.items(): | |
50 | if k.startswith('/episodes/') or k.startswith('/shortform/'): | |
51 | api_path, resp = k, v | |
52 | break | |
53 | else: | |
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) | |
57 | ||
58 | result = resp.get('results') | |
59 | if not result: | |
60 | resp = self._download_json( | |
61 | 'https://player.api.stv.tv/v1' + api_path, video_id) | |
62 | result = resp['results'] | |
63 | ||
64 | video = result['video'] | |
65 | video_id = compat_str(video['id']) | |
66 | ||
67 | subtitles = {} | |
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, | |
72 | 'url': sub_url, | |
73 | }) | |
74 | ||
75 | programme = result.get('programme') or {} | |
76 | if programme.get('drmEnabled'): | |
77 | self.report_drm(video_id) | |
78 | ||
79 | return { | |
80 | '_type': 'url_transparent', | |
81 | 'id': video_id, | |
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', | |
89 | } |