]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/ninenow.py
[extractor] Better error message for DRM (#729)
[yt-dlp.git] / yt_dlp / extractor / ninenow.py
CommitLineData
38e0f16a
RA
1# coding: utf-8
2from __future__ import unicode_literals
3
4from .common import InfoExtractor
5from ..compat import compat_str
6from ..utils import (
832f9d52 7 ExtractorError,
38e0f16a
RA
8 int_or_none,
9 float_or_none,
832f9d52 10 smuggle_url,
38e0f16a
RA
11)
12
13
14class NineNowIE(InfoExtractor):
15 IE_NAME = '9now.com.au'
16 _VALID_URL = r'https?://(?:www\.)?9now\.com\.au/(?:[^/]+/){2}(?P<id>[^/?#]+)'
832f9d52 17 _GEO_COUNTRIES = ['AU']
38e0f16a
RA
18 _TESTS = [{
19 # clip
20 'url': 'https://www.9now.com.au/afl-footy-show/2016/clip-ciql02091000g0hp5oktrnytc',
21 'md5': '17cf47d63ec9323e562c9957a968b565',
22 'info_dict': {
23 'id': '16801',
24 'ext': 'mp4',
25 'title': 'St. Kilda\'s Joey Montagna on the potential for a player\'s strike',
26 'description': 'Is a boycott of the NAB Cup "on the table"?',
27 'uploader_id': '4460760524001',
28 'upload_date': '20160713',
29 'timestamp': 1468421266,
30 },
31 'skip': 'Only available in Australia',
32 }, {
33 # episode
34 'url': 'https://www.9now.com.au/afl-footy-show/2016/episode-19',
35 'only_matching': True,
36 }, {
37 # DRM protected
342f0c36 38 'url': 'https://www.9now.com.au/andrew-marrs-history-of-the-world/season-1/episode-1',
38e0f16a
RA
39 'only_matching': True,
40 }]
41 BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/4460760524001/default_default/index.html?videoId=%s'
42
43 def _real_extract(self, url):
44 display_id = self._match_id(url)
45 webpage = self._download_webpage(url, display_id)
46 page_data = self._parse_json(self._search_regex(
47 r'window\.__data\s*=\s*({.*?});', webpage,
6fd26a7d
S
48 'page data', default='{}'), display_id, fatal=False)
49 if not page_data:
50 page_data = self._parse_json(self._parse_json(self._search_regex(
51 r'window\.__data\s*=\s*JSON\.parse\s*\(\s*(".+?")\s*\)\s*;',
52 webpage, 'page data'), display_id), display_id)
56c0ead4
S
53
54 for kind in ('episode', 'clip'):
55 current_key = page_data.get(kind, {}).get(
56 'current%sKey' % kind.capitalize())
57 if not current_key:
58 continue
59 cache = page_data.get(kind, {}).get('%sCache' % kind, {})
60 if not cache:
61 continue
62 common_data = (cache.get(current_key) or list(cache.values())[0])[kind]
63 break
64 else:
65 raise ExtractorError('Unable to find video data')
66
38e0f16a
RA
67 video_data = common_data['video']
68
38e0f16a
RA
69 brightcove_id = video_data.get('brightcoveId') or 'ref:' + video_data['referenceId']
70 video_id = compat_str(video_data.get('id') or brightcove_id)
88acdbc2 71
72 if not self.get_param('allow_unplayable_formats') and video_data.get('drm'):
73 self.report_drm(video_id)
74
38e0f16a
RA
75 title = common_data['name']
76
77 thumbnails = [{
78 'id': thumbnail_id,
79 'url': thumbnail_url,
80 'width': int_or_none(thumbnail_id[1:])
81 } for thumbnail_id, thumbnail_url in common_data.get('image', {}).get('sizes', {}).items()]
82
83 return {
84 '_type': 'url_transparent',
832f9d52
S
85 'url': smuggle_url(
86 self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id,
87 {'geo_countries': self._GEO_COUNTRIES}),
38e0f16a
RA
88 'id': video_id,
89 'title': title,
90 'description': common_data.get('description'),
91 'duration': float_or_none(video_data.get('duration'), 1000),
92 'thumbnails': thumbnails,
93 'ie_key': 'BrightcoveNew',
94 }