tenplay.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import base64
  2. import datetime as dt
  3. import functools
  4. import itertools
  5. from .common import InfoExtractor
  6. from ..networking import HEADRequest
  7. from ..utils import int_or_none, traverse_obj, urlencode_postdata, urljoin
  8. class TenPlayIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?10play\.com\.au/(?:[^/]+/)+(?P<id>tpv\d{6}[a-z]{5})'
  10. _NETRC_MACHINE = '10play'
  11. _TESTS = [{
  12. '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',
  13. 'info_dict': {
  14. 'id': '6226844312001',
  15. 'ext': 'mp4',
  16. 'title': 'Nathan Borg Is The First Aussie Actor With A Cochlear Implant To Join Neighbours',
  17. 'alt_title': 'Nathan Borg Is The First Aussie Actor With A Cochlear Implant To Join Neighbours',
  18. 'description': 'md5:a02d0199c901c2dd4c796f1e7dd0de43',
  19. 'duration': 186,
  20. 'season': 'Season 39',
  21. 'season_number': 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 = dt.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).url
  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_number': 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. }
  110. class TenPlaySeasonIE(InfoExtractor):
  111. _VALID_URL = r'https?://(?:www\.)?10play\.com\.au/(?P<show>[^/?#]+)/episodes/(?P<season>[^/?#]+)/?(?:$|[?#])'
  112. _TESTS = [{
  113. 'url': 'https://10play.com.au/masterchef/episodes/season-14',
  114. 'info_dict': {
  115. 'title': 'Season 14',
  116. 'id': 'MjMyOTIy',
  117. },
  118. 'playlist_mincount': 64,
  119. }, {
  120. 'url': 'https://10play.com.au/the-bold-and-the-beautiful-fast-tracked/episodes/season-2022',
  121. 'info_dict': {
  122. 'title': 'Season 2022',
  123. 'id': 'Mjc0OTIw',
  124. },
  125. 'playlist_mincount': 256,
  126. }]
  127. def _entries(self, load_more_url, display_id=None):
  128. skip_ids = []
  129. for page in itertools.count(1):
  130. episodes_carousel = self._download_json(
  131. load_more_url, display_id, query={'skipIds[]': skip_ids},
  132. note=f'Fetching episodes page {page}')
  133. episodes_chunk = episodes_carousel['items']
  134. skip_ids.extend(ep['id'] for ep in episodes_chunk)
  135. for ep in episodes_chunk:
  136. yield ep['cardLink']
  137. if not episodes_carousel['hasMore']:
  138. break
  139. def _real_extract(self, url):
  140. show, season = self._match_valid_url(url).group('show', 'season')
  141. season_info = self._download_json(
  142. f'https://10play.com.au/api/shows/{show}/episodes/{season}', f'{show}/{season}')
  143. episodes_carousel = traverse_obj(season_info, (
  144. 'content', 0, 'components', (
  145. lambda _, v: v['title'].lower() == 'episodes',
  146. (..., {dict}),
  147. )), get_all=False) or {}
  148. playlist_id = episodes_carousel['tpId']
  149. return self.playlist_from_matches(
  150. self._entries(urljoin(url, episodes_carousel['loadMoreUrl']), playlist_id),
  151. playlist_id, traverse_obj(season_info, ('content', 0, 'title', {str})),
  152. getter=functools.partial(urljoin, url))