]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/tenplay.py
[adobepass] Add MSO Sling TV (#596)
[yt-dlp.git] / yt_dlp / extractor / tenplay.py
CommitLineData
dd90451f
RA
1# coding: utf-8
2from __future__ import unicode_literals
3
74e001af 4from datetime import datetime
5import base64
6
dd90451f
RA
7from .common import InfoExtractor
8from ..utils import (
29f7c58a 9 HEADRequest,
74e001af 10 urlencode_postdata,
dd90451f
RA
11)
12
13
14class 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,
44 'R': 18,
45 'X': 18
46 }
47
48 def _get_bearer_token(self, video_id):
49 username, password = self._get_login_info()
50 if username is None or password is None:
51 self.raise_login_required('Your 10play account\'s details must be provided with --username and --password.')
52 _timestamp = datetime.now().strftime('%Y%m%d000000')
53 _auth_header = base64.b64encode(_timestamp.encode('ascii')).decode('ascii')
54 data = self._download_json('https://10play.com.au/api/user/auth', video_id, 'Getting bearer token', headers={
55 'X-Network-Ten-Auth': _auth_header,
56 }, data=urlencode_postdata({
57 'email': username,
58 'password': password,
59 }))
60 return "Bearer " + data['jwt']['accessToken']
dd90451f
RA
61
62 def _real_extract(self, url):
63 content_id = self._match_id(url)
74e001af 64 _token = self._get_bearer_token(content_id)
dd90451f 65 data = self._download_json(
74e001af 66 'https://10play.com.au/api/v1/videos/' + content_id, content_id)
67 _video_url = self._download_json(
68 data.get('playbackApiEndpoint'), content_id, 'Downloading video JSON',
69 headers={'Authorization': _token}).get('source')
29f7c58a 70 m3u8_url = self._request_webpage(HEADRequest(
74e001af 71 _video_url), content_id).geturl()
29f7c58a 72 if '10play-not-in-oz' in m3u8_url:
73 self.raise_geo_restricted(countries=['AU'])
74e001af 74 formats = self._extract_m3u8_formats(m3u8_url, content_id, 'mp4')
29f7c58a 75 self._sort_formats(formats)
dd90451f
RA
76
77 return {
29f7c58a 78 'formats': formats,
74e001af 79 'id': data.get('altId') or content_id,
80 'title': data.get('title'),
81 'description': data.get('description'),
82 'age_limit': self._AUS_AGES[data.get('classification')],
83 'series': data.get('showName'),
84 'season': data.get('showContentSeason'),
85 'timestamp': data.get('published'),
86 'thumbnail': data.get('imageUrl'),
87 'uploader': 'Channel 10',
29f7c58a 88 'uploader_id': '2199827728001',
dd90451f 89 }