dff44a4e2f4f5e4105def539c186dc630b411b34
[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/[^/]+/episodes/[^/]+/[^/]+/(?P<id>tpv\d{6}[a-z]{5})'
14     _TEST = {
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     BRIGHTCOVE_URL_TEMPLATE = 'https://players.brightcove.net/2199827728001/cN6vRtRQt_default/index.html?videoId=%s'
32
33     def _real_extract(self, url):
34         content_id = self._match_id(url)
35         data = self._download_json(
36             'https://10play.com.au/api/video/' + content_id, content_id)
37         video = data.get('video') or {}
38         metadata = data.get('metaData') or {}
39         brightcove_id = video.get('videoId') or metadata['showContentVideoId']
40         brightcove_url = smuggle_url(
41             self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id,
42             {'geo_countries': ['AU']})
43
44         return {
45             '_type': 'url_transparent',
46             'url': brightcove_url,
47             'id': content_id,
48             'title': video.get('title') or metadata.get('pageContentName') or metadata.get('showContentName'),
49             'description': video.get('description'),
50             'age_limit': parse_age_limit(video.get('showRatingClassification') or metadata.get('showProgramClassification')),
51             'series': metadata.get('showName'),
52             'season': metadata.get('showContentSeason'),
53             'timestamp': parse_iso8601(metadata.get('contentPublishDate') or metadata.get('pageContentPublishDate')),
54             'ie_key': 'BrightcoveNew',
55         }