tenplay.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. from datetime import datetime
  2. import base64
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. HEADRequest,
  6. int_or_none,
  7. urlencode_postdata,
  8. )
  9. class TenPlayIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?10play\.com\.au/(?:[^/]+/)+(?P<id>tpv\d{6}[a-z]{5})'
  11. _NETRC_MACHINE = '10play'
  12. _TESTS = [{
  13. 'url': 'https://10play.com.au/neighbours/web-extras/season-39/nathan-borg-is-the-first-aussie-actor-with-a-cochlear-implant-to-join-neighbours/tpv210128qupwd',
  14. 'info_dict': {
  15. 'id': '6226844312001',
  16. 'ext': 'mp4',
  17. 'title': 'Nathan Borg Is The First Aussie Actor With A Cochlear Implant To Join Neighbours',
  18. 'alt_title': 'Nathan Borg Is The First Aussie Actor With A Cochlear Implant To Join Neighbours',
  19. 'description': 'md5:a02d0199c901c2dd4c796f1e7dd0de43',
  20. 'duration': 186,
  21. 'season': 39,
  22. 'series': 'Neighbours',
  23. 'thumbnail': r're:https://.*\.jpg',
  24. 'uploader': 'Channel 10',
  25. 'age_limit': 15,
  26. 'timestamp': 1611810000,
  27. 'upload_date': '20210128',
  28. 'uploader_id': '2199827728001',
  29. },
  30. 'params': {
  31. 'skip_download': True,
  32. },
  33. 'skip': 'Only available in Australia',
  34. }, {
  35. 'url': 'https://10play.com.au/todd-sampsons-body-hack/episodes/season-4/episode-7/tpv200921kvngh',
  36. 'info_dict': {
  37. 'id': '6192880312001',
  38. 'ext': 'mp4',
  39. 'title': "Todd Sampson's Body Hack - S4 Ep. 2",
  40. 'description': 'md5:fa278820ad90f08ea187f9458316ac74',
  41. 'age_limit': 15,
  42. 'timestamp': 1600770600,
  43. 'upload_date': '20200922',
  44. 'uploader': 'Channel 10',
  45. 'uploader_id': '2199827728001'
  46. },
  47. 'params': {
  48. 'skip_download': True,
  49. }
  50. }, {
  51. 'url': 'https://10play.com.au/how-to-stay-married/web-extras/season-1/terrys-talks-ep-1-embracing-change/tpv190915ylupc',
  52. 'only_matching': True,
  53. }]
  54. _GEO_BYPASS = False
  55. _AUS_AGES = {
  56. 'G': 0,
  57. 'PG': 15,
  58. 'M': 15,
  59. 'MA': 15,
  60. 'MA15+': 15,
  61. 'R': 18,
  62. 'X': 18
  63. }
  64. def _get_bearer_token(self, video_id):
  65. username, password = self._get_login_info()
  66. if username is None or password is None:
  67. self.raise_login_required('Your 10play account\'s details must be provided with --username and --password.')
  68. _timestamp = datetime.now().strftime('%Y%m%d000000')
  69. _auth_header = base64.b64encode(_timestamp.encode('ascii')).decode('ascii')
  70. data = self._download_json('https://10play.com.au/api/user/auth', video_id, 'Getting bearer token', headers={
  71. 'X-Network-Ten-Auth': _auth_header,
  72. }, data=urlencode_postdata({
  73. 'email': username,
  74. 'password': password,
  75. }))
  76. return 'Bearer ' + data['jwt']['accessToken']
  77. def _real_extract(self, url):
  78. content_id = self._match_id(url)
  79. data = self._download_json(
  80. 'https://10play.com.au/api/v1/videos/' + content_id, content_id)
  81. headers = {}
  82. if data.get('memberGated') is True:
  83. _token = self._get_bearer_token(content_id)
  84. headers = {'Authorization': _token}
  85. _video_url = self._download_json(
  86. data.get('playbackApiEndpoint'), content_id, 'Downloading video JSON',
  87. headers=headers).get('source')
  88. m3u8_url = self._request_webpage(HEADRequest(
  89. _video_url), content_id).geturl()
  90. if '10play-not-in-oz' in m3u8_url:
  91. self.raise_geo_restricted(countries=['AU'])
  92. formats = self._extract_m3u8_formats(m3u8_url, content_id, 'mp4')
  93. return {
  94. 'formats': formats,
  95. 'subtitles': {'en': [{'url': data.get('captionUrl')}]} if data.get('captionUrl') else None,
  96. 'id': data.get('altId') or content_id,
  97. 'duration': data.get('duration'),
  98. 'title': data.get('subtitle'),
  99. 'alt_title': data.get('title'),
  100. 'description': data.get('description'),
  101. 'age_limit': self._AUS_AGES.get(data.get('classification')),
  102. 'series': data.get('tvShow'),
  103. 'season': int_or_none(data.get('season')),
  104. 'episode_number': int_or_none(data.get('episode')),
  105. 'timestamp': data.get('published'),
  106. 'thumbnail': data.get('imageUrl'),
  107. 'uploader': 'Channel 10',
  108. 'uploader_id': '2199827728001',
  109. }