7 from .common
import InfoExtractor
8 from ..dependencies
import Cryptodome
21 class WrestleUniverseBaseIE(InfoExtractor
):
22 _NETRC_MACHINE
= 'wrestleuniverse'
23 _VALID_URL_TMPL
= r
'https?://(?:www\.)?wrestle-universe\.com/(?:(?P<lang>\w{2})/)?%s/(?P<id>\w+)'
24 _API_HOST
= 'api.wrestle-universe.com'
30 _LOGIN_QUERY
= {'key': 'AIzaSyCaRPBsDQYVDUWWBXjsTrHESi2r_F3RAdA'}
33 'Content-Type': 'application/json',
34 'X-Client-Version': 'Chrome/JsCore/9.9.4/FirebaseCore-web',
35 'X-Firebase-gmpid': '1:307308870738:web:820f38fe5150c8976e338b',
36 'Referer': 'https://www.wrestle-universe.com/',
37 'Origin': 'https://www.wrestle-universe.com',
42 if not self
._REAL
_TOKEN
or not self
._TOKEN
_EXPIRY
:
43 token
= try_call(lambda: self
._get
_cookies
('https://www.wrestle-universe.com/')['token'].value
)
44 if not token
and not self
._REFRESH
_TOKEN
:
45 self
.raise_login_required()
48 if not self
._REAL
_TOKEN
or self
._TOKEN
_EXPIRY
<= int(time
.time()):
49 if not self
._REFRESH
_TOKEN
:
51 'Expired token. Refresh your cookies in browser and try again', expected
=True)
54 return self
._REAL
_TOKEN
57 def _TOKEN(self
, value
):
58 self
._REAL
_TOKEN
= value
60 expiry
= traverse_obj(value
, ({jwt_decode_hs256}
, 'exp', {int_or_none}
))
62 raise ExtractorError('There was a problem with the auth token')
63 self
._TOKEN
_EXPIRY
= expiry
65 def _perform_login(self
, username
, password
):
66 login
= self
._download
_json
(
67 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword', None,
68 'Logging in', query
=self
._LOGIN
_QUERY
, headers
=self
._LOGIN
_HEADERS
, data
=json
.dumps({
69 'returnSecureToken': True,
72 }, separators
=(',', ':')).encode(), expected_status
=400)
73 token
= traverse_obj(login
, ('idToken', {str}
))
76 f
'Unable to log in: {traverse_obj(login, ("error", "message"))}', expected
=True)
77 self
._REFRESH
_TOKEN
= traverse_obj(login
, ('refreshToken', {str}
))
78 if not self
._REFRESH
_TOKEN
:
79 self
.report_warning('No refresh token was granted')
82 def _real_initialize(self
):
86 self
._DEVICE
_ID
= self
._configuration
_arg
('device_id', [None], ie_key
=self
._NETRC
_MACHINE
)[0]
87 if not self
._DEVICE
_ID
:
88 self
._DEVICE
_ID
= self
.cache
.load(self
._NETRC
_MACHINE
, 'device_id')
91 self
._DEVICE
_ID
= str(uuid
.uuid4())
93 self
.cache
.store(self
._NETRC
_MACHINE
, 'device_id', self
._DEVICE
_ID
)
95 def _refresh_token(self
):
96 refresh
= self
._download
_json
(
97 'https://securetoken.googleapis.com/v1/token', None, 'Refreshing token',
98 query
=self
._LOGIN
_QUERY
, data
=urlencode_postdata({
99 'grant_type': 'refresh_token',
100 'refresh_token': self
._REFRESH
_TOKEN
,
102 **self
._LOGIN
_HEADERS
,
103 'Content-Type': 'application/x-www-form-urlencoded',
105 if traverse_obj(refresh
, ('refresh_token', {str}
)):
106 self
._REFRESH
_TOKEN
= refresh
['refresh_token']
107 token
= traverse_obj(refresh
, 'access_token', 'id_token', expected_type
=str)
109 raise ExtractorError('No auth token returned from refresh request')
112 def _call_api(self
, video_id
, param
='', msg
='API', auth
=True, data
=None, query
={}, fatal
=True):
113 headers
= {'CA-CID': ''}
115 headers
['Content-Type'] = 'application/json;charset=utf-8'
116 data
= json
.dumps(data
, separators
=(',', ':')).encode()
117 if auth
and self
._TOKEN
:
118 headers
['Authorization'] = f
'Bearer {self._TOKEN}'
119 return self
._download
_json
(
120 f
'https://{self._API_HOST}/v1/{self._API_PATH}/{video_id}{param}', video_id
,
121 note
=f
'Downloading {msg} JSON', errnote
=f
'Failed to download {msg} JSON',
122 data
=data
, headers
=headers
, query
=query
, fatal
=fatal
)
124 def _call_encrypted_api(self
, video_id
, param
='', msg
='API', data
={}, query={}
, fatal
=True):
125 if not Cryptodome
.RSA
:
126 raise ExtractorError('pycryptodomex not found. Please install', expected
=True)
127 private_key
= Cryptodome
.RSA
.generate(2048)
128 cipher
= Cryptodome
.PKCS1_OAEP
.new(private_key
, hashAlgo
=Cryptodome
.SHA1
)
134 return cipher
.decrypt(base64
.b64decode(data
)).decode()
135 except (ValueError, binascii
.Error
) as e
:
136 raise ExtractorError(f
'Could not decrypt data: {e}')
138 token
= base64
.b64encode(private_key
.public_key().export_key('DER')).decode()
139 api_json
= self
._call
_api
(video_id
, param
, msg
, data
={
140 'deviceId': self
._DEVICE
_ID
,
143 }, query
=query
, fatal
=fatal
)
144 return api_json
, decrypt
146 def _download_metadata(self
, url
, video_id
, lang
, props_keys
):
147 metadata
= self
._call
_api
(video_id
, msg
='metadata', query
={'al': lang or 'ja'}
, auth
=False, fatal
=False)
149 webpage
= self
._download
_webpage
(url
, video_id
)
150 nextjs_data
= self
._search
_nextjs
_data
(webpage
, video_id
)
151 metadata
= traverse_obj(nextjs_data
, (
152 'props', 'pageProps', *variadic(props_keys
, (str, bytes, dict, set)), {dict}
)) or {}
155 def _get_formats(self
, data
, path
, video_id
=None):
156 hls_url
= traverse_obj(data
, path
, get_all
=False)
157 if not hls_url
and not data
.get('canWatch'):
158 self
.raise_no_formats(
159 'This account does not have access to the requested content', expected
=True)
161 self
.raise_no_formats('No supported formats found')
162 return self
._extract
_m
3u8_formats
(hls_url
, video_id
, 'mp4', m3u8_id
='hls', live
=True)
165 class WrestleUniverseVODIE(WrestleUniverseBaseIE
):
166 _VALID_URL
= WrestleUniverseBaseIE
._VALID
_URL
_TMPL
% 'videos'
168 'url': 'https://www.wrestle-universe.com/en/videos/dp8mpjmcKfxzUhEHM2uFws',
170 'id': 'dp8mpjmcKfxzUhEHM2uFws',
172 'title': 'The 3rd “Futari wa Princess” Max Heart Tournament',
173 'description': 'md5:318d5061e944797fbbb81d5c7dd00bf5',
174 'location': '埼玉・春日部ふれあいキューブ',
177 'timestamp': 1674979200,
178 'upload_date': '20230129',
179 'thumbnail': 'https://image.asset.wrestle-universe.com/8FjD67P8rZc446RBQs5RBN/8FjD67P8rZc446RBQs5RBN',
180 'chapters': 'count:7',
184 'skip_download': 'm3u8',
188 _API_PATH
= 'videoEpisodes'
190 def _real_extract(self
, url
):
191 lang
, video_id
= self
._match
_valid
_url
(url
).group('lang', 'id')
192 metadata
= self
._download
_metadata
(url
, video_id
, lang
, 'videoEpisodeFallbackData')
193 video_data
= self
._call
_api
(video_id
, ':watch', 'watch', data
={
194 # 'deviceId' is required if ignoreDeviceRestriction is False
195 'ignoreDeviceRestriction': True,
200 'formats': self
._get
_formats
(video_data
, (
201 (('protocolHls', 'url'), ('chromecastUrls', ...)), {url_or_none}
), video_id
),
202 **traverse_obj(metadata
, {
203 'title': ('displayName', {str}
),
204 'description': ('description', {str}
),
205 'channel': ('labels', 'group', {str}
),
206 'location': ('labels', 'venue', {str}
),
207 'timestamp': ('watchStartTime', {int_or_none}
),
208 'thumbnail': ('keyVisualUrl', {url_or_none}
),
209 'cast': ('casts', ..., 'displayName', {str}
),
210 'duration': ('duration', {int}
),
211 'chapters': ('videoChapters', lambda _
, v
: isinstance(v
.get('start'), int), {
212 'title': ('displayName', {str}
),
213 'start_time': ('start', {int}
),
214 'end_time': ('end', {int}
),
220 class WrestleUniversePPVIE(WrestleUniverseBaseIE
):
221 _VALID_URL
= WrestleUniverseBaseIE
._VALID
_URL
_TMPL
% 'lives'
223 'note': 'HLS AES-128 key obtained via API',
224 'url': 'https://www.wrestle-universe.com/en/lives/buH9ibbfhdJAY4GKZcEuJX',
226 'id': 'buH9ibbfhdJAY4GKZcEuJX',
228 'title': '【PPV】Beyond the origins, into the future',
229 'description': 'md5:9a872db68cd09be4a1e35a3ee8b0bdfc',
231 'location': '東京・Twin Box AKIHABARA',
233 'timestamp': 1675076400,
234 'upload_date': '20230130',
235 'thumbnail': 'https://image.asset.wrestle-universe.com/rJs2m7cBaLXrwCcxMdQGRM/rJs2m7cBaLXrwCcxMdQGRM',
236 'thumbnails': 'count:3',
238 'key': '5633184acd6e43f1f1ac71c6447a4186',
239 'iv': '5bac71beb33197d5600337ce86de7862',
243 'skip_download': 'm3u8',
245 'skip': 'No longer available',
247 'note': 'unencrypted HLS',
248 'url': 'https://www.wrestle-universe.com/en/lives/wUG8hP5iApC63jbtQzhVVx',
250 'id': 'wUG8hP5iApC63jbtQzhVVx',
252 'title': 'GRAND PRINCESS \'22',
253 'description': 'md5:e4f43d0d4262de3952ff34831bc99858',
255 'location': '東京・両国国技館',
257 'timestamp': 1647665400,
258 'upload_date': '20220319',
259 'thumbnail': 'https://image.asset.wrestle-universe.com/i8jxSTCHPfdAKD4zN41Psx/i8jxSTCHPfdAKD4zN41Psx',
260 'thumbnails': 'count:3',
263 'skip_download': 'm3u8',
269 def _real_extract(self
, url
):
270 lang
, video_id
= self
._match
_valid
_url
(url
).group('lang', 'id')
271 metadata
= self
._download
_metadata
(url
, video_id
, lang
, 'eventFallbackData')
275 **traverse_obj(metadata
, {
276 'title': ('displayName', {str}
),
277 'description': ('description', {str}
),
278 'channel': ('labels', 'group', {str}
),
279 'location': ('labels', 'venue', {str}
),
280 'timestamp': ('startTime', {int_or_none}
),
281 'thumbnails': (('keyVisualUrl', 'alterKeyVisualUrl', 'heroKeyVisualUrl'), {'url': {url_or_none}
}),
285 ended_time
= traverse_obj(metadata
, ('endedTime', {int_or_none}
))
286 if info
.get('timestamp') and ended_time
:
287 info
['duration'] = ended_time
- info
['timestamp']
289 video_data
, decrypt
= self
._call
_encrypted
_api
(
290 video_id
, ':watchArchive', 'watch archive', data
={'method': 1}
)
291 info
['formats'] = self
._get
_formats
(video_data
, (
292 ('hls', None), ('urls', 'chromecastUrls'), ..., {url_or_none}
), video_id
)
293 for f
in info
['formats']:
294 # bitrates are exaggerated in PPV playlists, so avoid wrong/huge filesize_approx values
296 f
['tbr'] = int(f
['tbr'] / 2.5)
298 hls_aes_key
= traverse_obj(video_data
, ('hls', 'key', {decrypt}
))
302 'iv': traverse_obj(video_data
, ('hls', 'iv', {decrypt}
)),
304 elif traverse_obj(video_data
, ('hls', 'encryptType', {int}
)):
305 self
.report_warning('HLS AES-128 key was not found in API response')