]>
Commit | Line | Data |
---|---|---|
b73612a2 | 1 | from .common import InfoExtractor |
2 | from ..compat import compat_str | |
3 | from ..utils import ( | |
4 | smuggle_url, | |
5 | try_get, | |
6 | ) | |
7 | ||
8 | ||
9 | class PlayStuffIE(InfoExtractor): | |
10 | _VALID_URL = r'https?://(?:www\.)?play\.stuff\.co\.nz/details/(?P<id>[^/?#&]+)' | |
11 | _TESTS = [{ | |
12 | 'url': 'https://play.stuff.co.nz/details/608778ac1de1c4001a3fa09a', | |
13 | 'md5': 'c82d3669e5247c64bc382577843e5bd0', | |
14 | 'info_dict': { | |
15 | 'id': '6250584958001', | |
16 | 'ext': 'mp4', | |
17 | 'title': 'Episode 1: Rotorua/Mt Maunganui/Tauranga', | |
18 | 'description': 'md5:c154bafb9f0dd02d01fd4100fb1c1913', | |
19 | 'uploader_id': '6005208634001', | |
20 | 'timestamp': 1619491027, | |
21 | 'upload_date': '20210427', | |
22 | }, | |
23 | 'add_ie': ['BrightcoveNew'], | |
24 | }, { | |
25 | # geo restricted, bypassable | |
26 | 'url': 'https://play.stuff.co.nz/details/_6155660351001', | |
27 | 'only_matching': True, | |
28 | }] | |
29 | BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/%s_default/index.html?videoId=%s' | |
30 | ||
31 | def _real_extract(self, url): | |
32 | video_id = self._match_id(url) | |
33 | ||
34 | webpage = self._download_webpage(url, video_id) | |
35 | ||
36 | state = self._parse_json( | |
37 | self._search_regex( | |
38 | r'__INITIAL_STATE__\s*=\s*({.+?})\s*;', webpage, 'state'), | |
39 | video_id) | |
40 | ||
41 | account_id = try_get( | |
42 | state, lambda x: x['configurations']['accountId'], | |
43 | compat_str) or '6005208634001' | |
44 | player_id = try_get( | |
45 | state, lambda x: x['configurations']['playerId'], | |
46 | compat_str) or 'default' | |
47 | ||
48 | entries = [] | |
49 | for item_id, video in state['items'].items(): | |
50 | if not isinstance(video, dict): | |
51 | continue | |
52 | asset_id = try_get( | |
53 | video, lambda x: x['content']['attributes']['assetId'], | |
54 | compat_str) | |
55 | if not asset_id: | |
56 | continue | |
57 | entries.append(self.url_result( | |
58 | smuggle_url( | |
59 | self.BRIGHTCOVE_URL_TEMPLATE % (account_id, player_id, asset_id), | |
60 | {'geo_countries': ['NZ']}), | |
61 | 'BrightcoveNew', video_id)) | |
62 | ||
63 | return self.playlist_result(entries, video_id) |