2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
15 class WimTVIE(InfoExtractor
):
17 _UUID_RE
= r
'[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}'
19 https?://platform.wim.tv/
24 (?P<type>vod|live|cast)[=/]
25 (?P<id>%s).*?''' % _UUID_RE
28 'url': 'https://platform.wim.tv/embed/?vod=db29fb32-bade-47b6-a3a6-cb69fe80267a',
29 'md5': 'db29fb32-bade-47b6-a3a6-cb69fe80267a',
31 'id': 'db29fb32-bade-47b6-a3a6-cb69fe80267a',
33 'title': 'AMA SUPERCROSS 2020 - R2 ST. LOUIS',
35 'thumbnail': r
're:https?://.+?/thumbnail/.+?/720$'
38 'skip_download': True,
42 'url': 'https://platform.wim.tv/embed/?live=28e22c22-49db-40f3-8c37-8cbb0ff44556&autostart=true',
44 'id': '28e22c22-49db-40f3-8c37-8cbb0ff44556',
46 'title': 'Streaming MSmotorTV',
50 'skip_download': True,
53 'url': 'https://platform.wim.tv/#/webtv/automotornews/vod/422492b6-539e-474d-9c6b-68c9d5893365',
54 'only_matching': True,
56 'url': 'https://platform.wim.tv/#/webtv/renzoarborechannel/cast/f47e0d15-5b45-455e-bf0d-dba8ffa96365',
57 'only_matching': True,
61 def _extract_urls(webpage
):
64 for mobj
in re
.finditer(
65 r
'<iframe[^>]+src=["\'](?P
<url
>%s)' % WimTVIE._VALID_URL,
68 def _real_initialize(self):
70 self._get_player_data()
72 def _get_player_data(self):
73 msg_id = 'Player data
'
77 'url
': 'https
://platform
.wim
.tv
/common
/libs
/player
/wimtv
/wim
-rest
.js
',
79 'regex
': r'appAuth
= "(.+?)"',
80 'variable
': 'app_auth
',
83 'url
': 'https
://platform
.wim
.tv
/common
/config
/endpointconfig
.js
',
85 'regex
': r'PRODUCTION_HOSTNAME_THUMB
= "(.+?)"',
86 'variable
': 'thumb_server
',
88 'regex
': r'PRODUCTION_HOSTNAME_THUMB\s
*\
+\s
*"(.+?)"',
89 'variable
': 'thumb_server_path
',
94 temp = self._download_webpage(data['url
'], msg_id)
95 for var in data['vars']:
96 val = self._search_regex(var['regex
'], temp, msg_id)
98 raise ExtractorError('%s not found
' % var['variable
'])
99 self._player[var['variable
']] = val
101 def _generate_token(self):
102 json = self._download_json(
103 'https
://platform
.wim
.tv
/wimtv
-server
/oauth
/token
', 'Token generation
',
104 headers={'Authorization': 'Basic %s' % self._player['app_auth']},
105 data=urlencode_postdata({'grant_type': 'client_credentials'}))
106 token = json.get('access_token
')
108 raise ExtractorError('access token
not generated
')
111 def _generate_thumbnail(self, thumb_id, width='720'):
112 if not thumb_id or not self._player.get('thumb_server
'):
114 if not self._player.get('thumb_server_path
'):
115 self._player['thumb_server_path
'] = ''
116 return '%s%s/asset
/thumbnail
/%s/%s' % (
117 self._player['thumb_server
'],
118 self._player['thumb_server_path
'],
121 def _real_extract(self, url):
122 urlc = self._match_valid_url(url).groupdict()
123 video_id = urlc['id']
124 stream_type = is_live = None
125 if urlc['type'] in {'live', 'cast'}:
126 stream_type = urlc['type'] + '/channel
'
131 token = self._generate_token()
132 json = self._download_json(
133 'https
://platform
.wim
.tv
/wimtv
-server
/api
/public
/%s/%s/play
' % (
134 stream_type, video_id), video_id,
135 headers={'Authorization
': 'Bearer
%s' % token,
136 'Content
-Type
': 'application
/json
'},
137 data=bytes('{}', 'utf
-8'))
140 for src in json.get('srcs
') or []:
141 if src.get('mimeType
') == 'application
/x
-mpegurl
':
143 self._extract_m3u8_formats(
144 src.get('uniqueStreamer
'), video_id, 'mp4
'))
145 if src.get('mimeType
') == 'video
/flash
':
148 'url
': src.get('uniqueStreamer
'),
149 'ext
': determine_ext(src.get('uniqueStreamer
'), 'flv
'),
150 'rtmp_live
': is_live,
152 json = json.get('resource
')
153 thumb = self._generate_thumbnail(json.get('thumbnailId
'))
154 self._sort_formats(formats)
158 'title
': json.get('title
') or json.get('name
'),
159 'duration
': parse_duration(json.get('duration
')),