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