]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/tenplay.py
[version] update
[yt-dlp.git] / yt_dlp / extractor / tenplay.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from datetime import datetime
5 import base64
6
7 from .common import InfoExtractor
8 from ..utils import (
9 HEADRequest,
10 urlencode_postdata,
11 )
12
13
14 class TenPlayIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?10play\.com\.au/(?:[^/]+/)+(?P<id>tpv\d{6}[a-z]{5})'
16 _NETRC_MACHINE = '10play'
17 _TESTS = [{
18 'url': 'https://10play.com.au/todd-sampsons-body-hack/episodes/season-4/episode-7/tpv200921kvngh',
19 'info_dict': {
20 'id': '6192880312001',
21 'ext': 'mp4',
22 'title': "Todd Sampson's Body Hack - S4 Ep. 2",
23 'description': 'md5:fa278820ad90f08ea187f9458316ac74',
24 'age_limit': 15,
25 'timestamp': 1600770600,
26 'upload_date': '20200922',
27 'uploader': 'Channel 10',
28 'uploader_id': '2199827728001'
29 },
30 'params': {
31 'skip_download': True,
32 }
33 }, {
34 'url': 'https://10play.com.au/how-to-stay-married/web-extras/season-1/terrys-talks-ep-1-embracing-change/tpv190915ylupc',
35 'only_matching': True,
36 }]
37 _GEO_BYPASS = False
38
39 _AUS_AGES = {
40 'G': 0,
41 'PG': 15,
42 'M': 15,
43 'MA': 15,
44 'MA15+': 15,
45 'R': 18,
46 'X': 18
47 }
48
49 def _get_bearer_token(self, video_id):
50 username, password = self._get_login_info()
51 if username is None or password is None:
52 self.raise_login_required('Your 10play account\'s details must be provided with --username and --password.')
53 _timestamp = datetime.now().strftime('%Y%m%d000000')
54 _auth_header = base64.b64encode(_timestamp.encode('ascii')).decode('ascii')
55 data = self._download_json('https://10play.com.au/api/user/auth', video_id, 'Getting bearer token', headers={
56 'X-Network-Ten-Auth': _auth_header,
57 }, data=urlencode_postdata({
58 'email': username,
59 'password': password,
60 }))
61 return 'Bearer ' + data['jwt']['accessToken']
62
63 def _real_extract(self, url):
64 content_id = self._match_id(url)
65 _token = self._get_bearer_token(content_id)
66 data = self._download_json(
67 'https://10play.com.au/api/v1/videos/' + content_id, content_id)
68 _video_url = self._download_json(
69 data.get('playbackApiEndpoint'), content_id, 'Downloading video JSON',
70 headers={'Authorization': _token}).get('source')
71 m3u8_url = self._request_webpage(HEADRequest(
72 _video_url), content_id).geturl()
73 if '10play-not-in-oz' in m3u8_url:
74 self.raise_geo_restricted(countries=['AU'])
75 formats = self._extract_m3u8_formats(m3u8_url, content_id, 'mp4')
76 self._sort_formats(formats)
77
78 return {
79 'formats': formats,
80 'id': data.get('altId') or content_id,
81 'title': data.get('title'),
82 'description': data.get('description'),
83 'age_limit': self._AUS_AGES.get(data.get('classification')),
84 'series': data.get('showName'),
85 'season': data.get('showContentSeason'),
86 'timestamp': data.get('published'),
87 'thumbnail': data.get('imageUrl'),
88 'uploader': 'Channel 10',
89 'uploader_id': '2199827728001',
90 }