7 from .common
import InfoExtractor
8 from ..dependencies
import Cryptodome
22 class WrestleUniverseBaseIE(InfoExtractor
):
23 _NETRC_MACHINE
= 'wrestleuniverse'
24 _VALID_URL_TMPL
= r
'https?://(?:www\.)?wrestle-universe\.com/(?:(?P<lang>\w{2})/)?%s/(?P<id>\w+)'
25 _API_HOST
= 'api.wrestle-universe.com'
31 _LOGIN_QUERY
= {'key': 'AIzaSyCaRPBsDQYVDUWWBXjsTrHESi2r_F3RAdA'}
34 'Content-Type': 'application/json',
35 'X-Client-Version': 'Chrome/JsCore/9.9.4/FirebaseCore-web',
36 'X-Firebase-gmpid': '1:307308870738:web:820f38fe5150c8976e338b',
37 'Referer': 'https://www.wrestle-universe.com/',
38 'Origin': 'https://www.wrestle-universe.com',
43 if not self
._REAL
_TOKEN
or not self
._TOKEN
_EXPIRY
:
44 token
= try_call(lambda: self
._get
_cookies
('https://www.wrestle-universe.com/')['token'].value
)
45 if not token
and not self
._REFRESH
_TOKEN
:
46 self
.raise_login_required()
49 if not self
._REAL
_TOKEN
or self
._TOKEN
_EXPIRY
<= int(time
.time()):
50 if not self
._REFRESH
_TOKEN
:
52 'Expired token. Refresh your cookies in browser and try again', expected
=True)
55 return self
._REAL
_TOKEN
58 def _TOKEN(self
, value
):
59 self
._REAL
_TOKEN
= value
61 expiry
= traverse_obj(value
, ({jwt_decode_hs256}
, 'exp', {int_or_none}
))
63 raise ExtractorError('There was a problem with the auth token')
64 self
._TOKEN
_EXPIRY
= expiry
66 def _perform_login(self
, username
, password
):
67 login
= self
._download
_json
(
68 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword', None,
69 'Logging in', query
=self
._LOGIN
_QUERY
, headers
=self
._LOGIN
_HEADERS
, data
=json
.dumps({
70 'returnSecureToken': True,
73 }, separators
=(',', ':')).encode(), expected_status
=400)
74 token
= traverse_obj(login
, ('idToken', {str}
))
77 f
'Unable to log in: {traverse_obj(login, ("error", "message"))}', expected
=True)
78 self
._REFRESH
_TOKEN
= traverse_obj(login
, ('refreshToken', {str}
))
79 if not self
._REFRESH
_TOKEN
:
80 self
.report_warning('No refresh token was granted')
83 def _real_initialize(self
):
87 self
._DEVICE
_ID
= self
._configuration
_arg
('device_id', [None], ie_key
=self
._NETRC
_MACHINE
)[0]
88 if not self
._DEVICE
_ID
:
89 self
._DEVICE
_ID
= self
.cache
.load(self
._NETRC
_MACHINE
, 'device_id')
92 self
._DEVICE
_ID
= str(uuid
.uuid4())
94 self
.cache
.store(self
._NETRC
_MACHINE
, 'device_id', self
._DEVICE
_ID
)
96 def _refresh_token(self
):
97 refresh
= self
._download
_json
(
98 'https://securetoken.googleapis.com/v1/token', None, 'Refreshing token',
99 query
=self
._LOGIN
_QUERY
, data
=urlencode_postdata({
100 'grant_type': 'refresh_token',
101 'refresh_token': self
._REFRESH
_TOKEN
,
103 **self
._LOGIN
_HEADERS
,
104 'Content-Type': 'application/x-www-form-urlencoded',
106 if traverse_obj(refresh
, ('refresh_token', {str}
)):
107 self
._REFRESH
_TOKEN
= refresh
['refresh_token']
108 token
= traverse_obj(refresh
, 'access_token', 'id_token', expected_type
=str)
110 raise ExtractorError('No auth token returned from refresh request')
113 def _call_api(self
, video_id
, param
='', msg
='API', auth
=True, data
=None, query
={}, fatal
=True):
114 headers
= {'CA-CID': ''}
116 headers
['Content-Type'] = 'application/json;charset=utf-8'
117 data
= json
.dumps(data
, separators
=(',', ':')).encode()
118 if auth
and self
._TOKEN
:
119 headers
['Authorization'] = f
'Bearer {self._TOKEN}'
120 return self
._download
_json
(
121 f
'https://{self._API_HOST}/v1/{self._API_PATH}/{video_id}{param}', video_id
,
122 note
=f
'Downloading {msg} JSON', errnote
=f
'Failed to download {msg} JSON',
123 data
=data
, headers
=headers
, query
=query
, fatal
=fatal
)
125 def _call_encrypted_api(self
, video_id
, param
='', msg
='API', data
={}, query
={}, fatal
=True):
126 if not Cryptodome
.RSA
:
127 raise ExtractorError('pycryptodomex not found. Please install', expected
=True)
128 private_key
= Cryptodome
.RSA
.generate(2048)
129 cipher
= Cryptodome
.PKCS1_OAEP
.new(private_key
, hashAlgo
=Cryptodome
.SHA1
)
135 return cipher
.decrypt(base64
.b64decode(data
)).decode()
136 except (ValueError, binascii
.Error
) as e
:
137 raise ExtractorError(f
'Could not decrypt data: {e}')
139 token
= base64
.b64encode(private_key
.public_key().export_key('DER')).decode()
140 api_json
= self
._call
_api
(video_id
, param
, msg
, data
={
141 'deviceId': self
._DEVICE
_ID
,
144 }, query
=query
, fatal
=fatal
)
145 return api_json
, decrypt
147 def _download_metadata(self
, url
, video_id
, lang
, props_keys
):
148 metadata
= self
._call
_api
(video_id
, msg
='metadata', query
={'al': lang
or 'ja'}, auth
=False, fatal
=False)
150 webpage
= self
._download
_webpage
(url
, video_id
)
151 nextjs_data
= self
._search
_nextjs
_data
(webpage
, video_id
, fatal
=False)
152 metadata
= traverse_obj(nextjs_data
, (
153 'props', 'pageProps', *variadic(props_keys
, (str, bytes
, dict, set)), {dict}
)) or {}
156 def _get_formats(self
, data
, path
, video_id
=None):
157 hls_url
= traverse_obj(data
, path
, get_all
=False)
158 if not hls_url
and not data
.get('canWatch'):
159 self
.raise_no_formats(
160 'This account does not have access to the requested content', expected
=True)
162 self
.raise_no_formats('No supported formats found')
163 return self
._extract
_m
3u8_formats
(hls_url
, video_id
, 'mp4', m3u8_id
='hls', live
=True)
166 class WrestleUniverseVODIE(WrestleUniverseBaseIE
):
167 _VALID_URL
= WrestleUniverseBaseIE
._VALID
_URL
_TMPL
% 'videos'
169 'url': 'https://www.wrestle-universe.com/en/videos/dp8mpjmcKfxzUhEHM2uFws',
171 'id': 'dp8mpjmcKfxzUhEHM2uFws',
173 'title': 'The 3rd “Futari wa Princess” Max Heart Tournament',
174 'description': 'md5:318d5061e944797fbbb81d5c7dd00bf5',
175 'location': '埼玉・春日部ふれあいキューブ',
178 'timestamp': 1674979200,
179 'upload_date': '20230129',
180 'thumbnail': 'https://image.asset.wrestle-universe.com/8FjD67P8rZc446RBQs5RBN/8FjD67P8rZc446RBQs5RBN',
181 'chapters': 'count:7',
185 'skip_download': 'm3u8',
189 _API_PATH
= 'videoEpisodes'
191 def _real_extract(self
, url
):
192 lang
, video_id
= self
._match
_valid
_url
(url
).group('lang', 'id')
193 metadata
= self
._download
_metadata
(url
, video_id
, lang
, 'videoEpisodeFallbackData')
194 video_data
= self
._call
_api
(video_id
, ':watch', 'watch', data
={'deviceId': self
._DEVICE
_ID
})
198 'formats': self
._get
_formats
(video_data
, ('protocolHls', 'url', {url_or_none}
), video_id
),
199 **traverse_obj(metadata
, {
200 'title': ('displayName', {str}
),
201 'description': ('description', {str}
),
202 'channel': ('labels', 'group', {str}
),
203 'location': ('labels', 'venue', {str}
),
204 'timestamp': ('watchStartTime', {int_or_none}
),
205 'thumbnail': ('keyVisualUrl', {url_or_none}
),
206 'cast': ('casts', ..., 'displayName', {str}
),
207 'duration': ('duration', {int}
),
208 'chapters': ('videoChapters', lambda _
, v
: isinstance(v
.get('start'), int), {
209 'title': ('displayName', {str}
),
210 'start_time': ('start', {int}
),
211 'end_time': ('end', {int}
),
217 class WrestleUniversePPVIE(WrestleUniverseBaseIE
):
218 _VALID_URL
= WrestleUniverseBaseIE
._VALID
_URL
_TMPL
% 'lives'
220 'note': 'HLS AES-128 key obtained via API',
221 'url': 'https://www.wrestle-universe.com/en/lives/buH9ibbfhdJAY4GKZcEuJX',
223 'id': 'buH9ibbfhdJAY4GKZcEuJX',
225 'title': '【PPV】Beyond the origins, into the future',
226 'description': 'md5:9a872db68cd09be4a1e35a3ee8b0bdfc',
228 'location': '東京・Twin Box AKIHABARA',
230 'timestamp': 1675076400,
231 'upload_date': '20230130',
232 'thumbnail': 'https://image.asset.wrestle-universe.com/rJs2m7cBaLXrwCcxMdQGRM/rJs2m7cBaLXrwCcxMdQGRM',
233 'thumbnails': 'count:3',
235 'key': '5633184acd6e43f1f1ac71c6447a4186',
236 'iv': '5bac71beb33197d5600337ce86de7862',
240 'skip_download': 'm3u8',
242 'skip': 'No longer available',
244 'note': 'unencrypted HLS',
245 'url': 'https://www.wrestle-universe.com/en/lives/wUG8hP5iApC63jbtQzhVVx',
247 'id': 'wUG8hP5iApC63jbtQzhVVx',
249 'title': 'GRAND PRINCESS \'22',
250 'description': 'md5:e4f43d0d4262de3952ff34831bc99858',
252 'location': '東京・両国国技館',
254 'timestamp': 1647665400,
255 'upload_date': '20220319',
256 'thumbnail': 'https://image.asset.wrestle-universe.com/i8jxSTCHPfdAKD4zN41Psx/i8jxSTCHPfdAKD4zN41Psx',
257 'thumbnails': 'count:3',
260 'skip_download': 'm3u8',
263 'note': 'manifest provides live-a (partial) and live-b (full) streams',
264 'url': 'https://www.wrestle-universe.com/en/lives/umc99R9XsexXrxr9VjTo9g',
265 'only_matching': True,
270 def _real_extract(self
, url
):
271 lang
, video_id
= self
._match
_valid
_url
(url
).group('lang', 'id')
272 metadata
= self
._download
_metadata
(url
, video_id
, lang
, 'eventFallbackData')
276 **traverse_obj(metadata
, {
277 'title': ('displayName', {str}
),
278 'description': ('description', {str}
),
279 'channel': ('labels', 'group', {str}
),
280 'location': ('labels', 'venue', {str}
),
281 'timestamp': ('startTime', {int_or_none}
),
282 'thumbnails': (('keyVisualUrl', 'alterKeyVisualUrl', 'heroKeyVisualUrl'), {'url': {url_or_none}
}),
286 ended_time
= traverse_obj(metadata
, ('endedTime', {int_or_none}
))
287 if info
.get('timestamp') and ended_time
:
288 info
['duration'] = ended_time
- info
['timestamp']
290 video_data
, decrypt
= self
._call
_encrypted
_api
(
291 video_id
, ':watchArchive', 'watch archive', data
={'method': 1})
292 # 'chromecastUrls' can be only partial videos, avoid
293 info
['formats'] = self
._get
_formats
(video_data
, ('hls', (('urls', ...), 'url'), {url_or_none}
), video_id
)
294 for f
in info
['formats']:
295 # bitrates are exaggerated in PPV playlists, so avoid wrong/huge filesize_approx values
297 f
['tbr'] = int(f
['tbr'] / 2.5)
298 # prefer variants with the same basename as the master playlist to avoid partial streams
299 f
['format_id'] = url_basename(f
['url']).partition('.')[0]
300 if not f
['format_id'].startswith(url_basename(f
['manifest_url']).partition('.')[0]):
301 f
['preference'] = -10
303 hls_aes_key
= traverse_obj(video_data
, ('hls', 'key', {decrypt}
))
307 'iv': traverse_obj(video_data
, ('hls', 'iv', {decrypt}
)),
309 elif traverse_obj(video_data
, ('hls', 'encryptType', {int}
)):
310 self
.report_warning('HLS AES-128 key was not found in API response')