]>
Commit | Line | Data |
---|---|---|
dd90451f RA |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
74e001af | 4 | from datetime import datetime |
5 | import base64 | |
6 | ||
dd90451f RA |
7 | from .common import InfoExtractor |
8 | from ..utils import ( | |
29f7c58a | 9 | HEADRequest, |
74e001af | 10 | urlencode_postdata, |
dd90451f RA |
11 | ) |
12 | ||
13 | ||
14 | class TenPlayIE(InfoExtractor): | |
c97f5e93 | 15 | _VALID_URL = r'https?://(?:www\.)?10play\.com\.au/(?:[^/]+/)+(?P<id>tpv\d{6}[a-z]{5})' |
74e001af | 16 | _NETRC_MACHINE = '10play' |
c97f5e93 | 17 | _TESTS = [{ |
74e001af | 18 | 'url': 'https://10play.com.au/todd-sampsons-body-hack/episodes/season-4/episode-7/tpv200921kvngh', |
dd90451f | 19 | 'info_dict': { |
74e001af | 20 | 'id': '6192880312001', |
dd90451f | 21 | 'ext': 'mp4', |
74e001af | 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' | |
dd90451f RA |
29 | }, |
30 | 'params': { | |
dd90451f RA |
31 | 'skip_download': True, |
32 | } | |
c97f5e93 S |
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 | }] | |
29f7c58a | 37 | _GEO_BYPASS = False |
74e001af | 38 | |
39 | _AUS_AGES = { | |
40 | 'G': 0, | |
41 | 'PG': 15, | |
42 | 'M': 15, | |
43 | 'MA': 15, | |
1bd3639f | 44 | 'MA15+': 15, |
74e001af | 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 | })) | |
9222c381 | 61 | return 'Bearer ' + data['jwt']['accessToken'] |
dd90451f RA |
62 | |
63 | def _real_extract(self, url): | |
64 | content_id = self._match_id(url) | |
74e001af | 65 | _token = self._get_bearer_token(content_id) |
dd90451f | 66 | data = self._download_json( |
74e001af | 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') | |
29f7c58a | 71 | m3u8_url = self._request_webpage(HEADRequest( |
74e001af | 72 | _video_url), content_id).geturl() |
29f7c58a | 73 | if '10play-not-in-oz' in m3u8_url: |
74 | self.raise_geo_restricted(countries=['AU']) | |
74e001af | 75 | formats = self._extract_m3u8_formats(m3u8_url, content_id, 'mp4') |
29f7c58a | 76 | self._sort_formats(formats) |
dd90451f RA |
77 | |
78 | return { | |
29f7c58a | 79 | 'formats': formats, |
74e001af | 80 | 'id': data.get('altId') or content_id, |
81 | 'title': data.get('title'), | |
82 | 'description': data.get('description'), | |
1bd3639f | 83 | 'age_limit': self._AUS_AGES.get(data.get('classification')), |
74e001af | 84 | 'series': data.get('showName'), |
85 | 'season': data.get('showContentSeason'), | |
86 | 'timestamp': data.get('published'), | |
87 | 'thumbnail': data.get('imageUrl'), | |
88 | 'uploader': 'Channel 10', | |
29f7c58a | 89 | 'uploader_id': '2199827728001', |
dd90451f | 90 | } |