[tenplay] Relax _VALID_URL (closes #25001)
[youtube-dl] / youtube_dl / extractor / tenplay.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     parse_age_limit,
7     parse_iso8601,
8     smuggle_url,
9 )
10
11
12 class TenPlayIE(InfoExtractor):
13     _VALID_URL = r'https?://(?:www\.)?10play\.com\.au/(?:[^/]+/)+(?P<id>tpv\d{6}[a-z]{5})'
14     _TESTS = [{
15         'url': 'https://10play.com.au/masterchef/episodes/season-1/masterchef-s1-ep-1/tpv190718kwzga',
16         'info_dict': {
17             'id': '6060533435001',
18             'ext': 'mp4',
19             'title': 'MasterChef - S1 Ep. 1',
20             'description': 'md5:4fe7b78e28af8f2d900cd20d900ef95c',
21             'age_limit': 10,
22             'timestamp': 1240828200,
23             'upload_date': '20090427',
24             'uploader_id': '2199827728001',
25         },
26         'params': {
27             'format': 'bestvideo',
28             'skip_download': True,
29         }
30     }, {
31         'url': 'https://10play.com.au/how-to-stay-married/web-extras/season-1/terrys-talks-ep-1-embracing-change/tpv190915ylupc',
32         'only_matching': True,
33     }]
34     BRIGHTCOVE_URL_TEMPLATE = 'https://players.brightcove.net/2199827728001/cN6vRtRQt_default/index.html?videoId=%s'
35
36     def _real_extract(self, url):
37         content_id = self._match_id(url)
38         data = self._download_json(
39             'https://10play.com.au/api/video/' + content_id, content_id)
40         video = data.get('video') or {}
41         metadata = data.get('metaData') or {}
42         brightcove_id = video.get('videoId') or metadata['showContentVideoId']
43         brightcove_url = smuggle_url(
44             self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id,
45             {'geo_countries': ['AU']})
46
47         return {
48             '_type': 'url_transparent',
49             'url': brightcove_url,
50             'id': content_id,
51             'title': video.get('title') or metadata.get('pageContentName') or metadata.get('showContentName'),
52             'description': video.get('description'),
53             'age_limit': parse_age_limit(video.get('showRatingClassification') or metadata.get('showProgramClassification')),
54             'series': metadata.get('showName'),
55             'season': metadata.get('showContentSeason'),
56             'timestamp': parse_iso8601(metadata.get('contentPublishDate') or metadata.get('pageContentPublishDate')),
57             'ie_key': 'BrightcoveNew',
58         }