]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tennistv.py
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
  14 class TennisTVIE(InfoExtractor
): 
  15     _VALID_URL 
= r
'https?://(?:www\.)?tennistv\.com/videos/(?P<id>[-a-z0-9]+)' 
  17         'url': 'https://www.tennistv.com/videos/indian-wells-2018-verdasco-fritz', 
  19             'id': 'indian-wells-2018-verdasco-fritz', 
  21             'title': 'Fernando Verdasco v Taylor Fritz', 
  22             'description': 're:^After his stunning victory.{174}$', 
  23             'thumbnail': 'https://atp-prod.akamaized.net/api/images/v1/images/112831/landscape/1242/0', 
  24             'timestamp': 1521017381, 
  25             'upload_date': '20180314', 
  28             'skip_download': True, 
  30         'skip': 'Requires email and password of a subscribed account', 
  32     _NETRC_MACHINE 
= 'tennistv' 
  35         username
, password 
= self
._get
_login
_info
() 
  36         if not username 
or not password
: 
  37             raise ExtractorError('No login info available, needed for using %s.' % self
.IE_NAME
, expected
=True) 
  43         login_json 
= json
.dumps(login_form
).encode('utf-8') 
  45             'content-type': 'application/json', 
  46             'Referer': 'https://www.tennistv.com/login', 
  47             'Origin': 'https://www.tennistv.com', 
  50         login_result 
= self
._download
_json
( 
  51             'https://www.tennistv.com/api/users/v1/login', None, 
  53             errnote
='Login failed (wrong password?)', 
  57         if login_result
['error']['errorCode']: 
  58             raise ExtractorError('Login failed, %s said: %r' % (self
.IE_NAME
, login_result
['error']['errorMessage'])) 
  60         if login_result
['entitlement'] != 'SUBSCRIBED': 
  61             self
.report_warning('%s may not be subscribed to %s.' % (username
, self
.IE_NAME
)) 
  63         self
._session
_token 
= login_result
['sessionToken'] 
  65     def _real_initialize(self
): 
  68     def _real_extract(self
, url
): 
  69         video_id 
= self
._match
_id
(url
) 
  70         webpage 
= self
._download
_webpage
(url
, video_id
) 
  72         internal_id 
= self
._search
_regex
(r
'video=([0-9]+)', webpage
, 'internal video id') 
  75             'Origin': 'https://www.tennistv.com', 
  76             'authorization': 'ATP %s' % self
._session
_token
, 
  77             'content-type': 'application/json', 
  81             'videoID': internal_id
, 
  82             'VideoUrlType': 'HLSV3', 
  84         check_json 
= json
.dumps(check_data
).encode('utf-8') 
  85         check_result 
= self
._download
_json
( 
  86             'https://www.tennistv.com/api/users/v1/entitlementchecknondiva', 
  87             video_id
, note
='Checking video authorization', headers
=headers
, data
=check_json
) 
  88         formats 
= self
._extract
_m
3u8_formats
(check_result
['contentUrl'], video_id
, ext
='mp4') 
  90         vdata_url 
= 'https://www.tennistv.com/api/channels/v1/de/none/video/%s' % video_id
 
  91         vdata 
= self
._download
_json
(vdata_url
, video_id
) 
  93         timestamp 
= unified_timestamp(vdata
['timestamp']) 
  94         thumbnail 
= vdata
['video']['thumbnailUrl'] 
  95         description 
= vdata
['displayText']['description'] 
  96         title 
= vdata
['video']['title'] 
  98         series 
= vdata
['tour'] 
  99         venue 
= vdata
['displayText']['venue'] 
 100         round_str 
= vdata
['seo']['round'] 
 105             'description': description
, 
 107             'thumbnail': thumbnail
, 
 108             'timestamp': timestamp
, 
 111             'episode': round_str
,