1 from .common
import InfoExtractor
10 class WimTVIE(InfoExtractor
):
12 _UUID_RE
= r
'[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}'
13 _VALID_URL
= rf
'''(?x:
14 https?://platform\.wim\.tv/
19 (?P<type>vod|live|cast)[=/]
20 (?P<id>{_UUID_RE}).*?)'''
21 _EMBED_REGEX
= [rf
'<iframe[^>]+src=["\'](?P<url>{_VALID_URL})']
24 'url': 'https://platform.wim.tv/embed/?vod=db29fb32-bade-47b6-a3a6-cb69fe80267a',
25 'md5': 'db29fb32-bade-47b6-a3a6-cb69fe80267a',
27 'id': 'db29fb32-bade-47b6-a3a6-cb69fe80267a',
29 'title': 'AMA SUPERCROSS 2020 - R2 ST. LOUIS',
31 'thumbnail': r
're:https?://.+?/thumbnail/.+?/720$',
34 'skip_download': True,
38 'url': 'https://platform.wim.tv/embed/?live=28e22c22-49db-40f3-8c37-8cbb0ff44556&autostart=true',
40 'id': '28e22c22-49db-40f3-8c37-8cbb0ff44556',
42 'title': 'Streaming MSmotorTV',
46 'skip_download': True,
49 'url': 'https://platform.wim.tv/#/webtv/automotornews/vod/422492b6-539e-474d-9c6b-68c9d5893365',
50 'only_matching': True,
52 'url': 'https://platform.wim.tv/#/webtv/renzoarborechannel/cast/f47e0d15-5b45-455e-bf0d-dba8ffa96365',
53 'only_matching': True,
56 def _real_initialize(self
):
58 self
._get
_player
_data
()
60 def _get_player_data(self
):
61 msg_id
= 'Player data'
65 'url': 'https://platform.wim.tv/common/libs/player/wimtv/wim-rest.js',
67 'regex': r
'appAuth = "(.+?)"',
68 'variable': 'app_auth',
71 'url': 'https://platform.wim.tv/common/config/endpointconfig.js',
73 'regex': r
'PRODUCTION_HOSTNAME_THUMB = "(.+?)"',
74 'variable': 'thumb_server',
76 'regex': r
'PRODUCTION_HOSTNAME_THUMB\s*\+\s*"(.+?)"',
77 'variable': 'thumb_server_path',
82 temp
= self
._download
_webpage
(data
['url'], msg_id
)
83 for var
in data
['vars']:
84 val
= self
._search
_regex
(var
['regex'], temp
, msg_id
)
86 raise ExtractorError('{} not found'.format(var
['variable']))
87 self
._player
[var
['variable']] = val
89 def _generate_token(self
):
90 json
= self
._download
_json
(
91 'https://platform.wim.tv/wimtv-server/oauth/token', 'Token generation',
92 headers
={'Authorization': 'Basic {}'.format(self
._player
['app_auth'])},
93 data
=urlencode_postdata({'grant_type': 'client_credentials'}))
94 token
= json
.get('access_token')
96 raise ExtractorError('access token not generated')
99 def _generate_thumbnail(self
, thumb_id
, width
='720'):
100 if not thumb_id
or not self
._player
.get('thumb_server'):
102 if not self
._player
.get('thumb_server_path'):
103 self
._player
['thumb_server_path'] = ''
104 return '{}{}/asset/thumbnail/{}/{}'.format(
105 self
._player
['thumb_server'],
106 self
._player
['thumb_server_path'],
109 def _real_extract(self
, url
):
110 urlc
= self
._match
_valid
_url
(url
).groupdict()
111 video_id
= urlc
['id']
112 stream_type
= is_live
= None
113 if urlc
['type'] in {'live', 'cast'}:
114 stream_type
= urlc
['type'] + '/channel'
119 token
= self
._generate
_token
()
120 json
= self
._download
_json
(
121 f
'https://platform.wim.tv/wimtv-server/api/public/{stream_type}/{video_id}/play',
123 'Authorization': f
'Bearer {token}',
124 'Content-Type': 'application/json',
128 for src
in json
.get('srcs') or []:
129 if src
.get('mimeType') == 'application/x-mpegurl':
131 self
._extract
_m
3u8_formats
(
132 src
.get('uniqueStreamer'), video_id
, 'mp4'))
133 if src
.get('mimeType') == 'video/flash':
136 'url': src
.get('uniqueStreamer'),
137 'ext': determine_ext(src
.get('uniqueStreamer'), 'flv'),
138 'rtmp_live': is_live
,
140 json
= json
.get('resource')
141 thumb
= self
._generate
_thumbnail
(json
.get('thumbnailId'))
145 'title': json
.get('title') or json
.get('name'),
146 'duration': parse_duration(json
.get('duration')),