logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

tennistv.py (3945B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. unified_timestamp,
  8. )
  9. class TennisTVIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?tennistv\.com/videos/(?P<id>[-a-z0-9]+)'
  11. _TEST = {
  12. 'url': 'https://www.tennistv.com/videos/indian-wells-2018-verdasco-fritz',
  13. 'info_dict': {
  14. 'id': 'indian-wells-2018-verdasco-fritz',
  15. 'ext': 'mp4',
  16. 'title': 'Fernando Verdasco v Taylor Fritz',
  17. 'description': 're:^After his stunning victory.{174}$',
  18. 'thumbnail': 'https://atp-prod.akamaized.net/api/images/v1/images/112831/landscape/1242/0',
  19. 'timestamp': 1521017381,
  20. 'upload_date': '20180314',
  21. },
  22. 'params': {
  23. 'skip_download': True,
  24. },
  25. 'skip': 'Requires email and password of a subscribed account',
  26. }
  27. _NETRC_MACHINE = 'tennistv'
  28. def _login(self):
  29. username, password = self._get_login_info()
  30. if not username or not password:
  31. raise ExtractorError('No login info available, needed for using %s.' % self.IE_NAME, expected=True)
  32. login_form = {
  33. 'Email': username,
  34. 'Password': password,
  35. }
  36. login_json = json.dumps(login_form).encode('utf-8')
  37. headers = {
  38. 'content-type': 'application/json',
  39. 'Referer': 'https://www.tennistv.com/login',
  40. 'Origin': 'https://www.tennistv.com',
  41. }
  42. login_result = self._download_json(
  43. 'https://www.tennistv.com/api/users/v1/login', None,
  44. note='Logging in',
  45. errnote='Login failed (wrong password?)',
  46. headers=headers,
  47. data=login_json)
  48. if login_result['error']['errorCode']:
  49. raise ExtractorError('Login failed, %s said: %r' % (self.IE_NAME, login_result['error']['errorMessage']))
  50. if login_result['entitlement'] != 'SUBSCRIBED':
  51. self.report_warning('%s may not be subscribed to %s.' % (username, self.IE_NAME))
  52. self._session_token = login_result['sessionToken']
  53. def _real_initialize(self):
  54. self._login()
  55. def _real_extract(self, url):
  56. video_id = self._match_id(url)
  57. webpage = self._download_webpage(url, video_id)
  58. internal_id = self._search_regex(r'video=([0-9]+)', webpage, 'internal video id')
  59. headers = {
  60. 'Origin': 'https://www.tennistv.com',
  61. 'authorization': 'ATP %s' % self._session_token,
  62. 'content-type': 'application/json',
  63. 'Referer': url,
  64. }
  65. check_data = {
  66. 'videoID': internal_id,
  67. 'VideoUrlType': 'HLSV3',
  68. }
  69. check_json = json.dumps(check_data).encode('utf-8')
  70. check_result = self._download_json(
  71. 'https://www.tennistv.com/api/users/v1/entitlementchecknondiva',
  72. video_id, note='Checking video authorization', headers=headers, data=check_json)
  73. formats = self._extract_m3u8_formats(check_result['contentUrl'], video_id, ext='mp4')
  74. vdata_url = 'https://www.tennistv.com/api/channels/v1/de/none/video/%s' % video_id
  75. vdata = self._download_json(vdata_url, video_id)
  76. timestamp = unified_timestamp(vdata['timestamp'])
  77. thumbnail = vdata['video']['thumbnailUrl']
  78. description = vdata['displayText']['description']
  79. title = vdata['video']['title']
  80. series = vdata['tour']
  81. venue = vdata['displayText']['venue']
  82. round_str = vdata['seo']['round']
  83. return {
  84. 'id': video_id,
  85. 'title': title,
  86. 'description': description,
  87. 'formats': formats,
  88. 'thumbnail': thumbnail,
  89. 'timestamp': timestamp,
  90. 'series': series,
  91. 'season': venue,
  92. 'episode': round_str,
  93. }