7 from .common
import InfoExtractor
8 from ..dependencies
import Cryptodome
20 class WrestleUniverseBaseIE(InfoExtractor
):
21 _NETRC_MACHINE
= 'wrestleuniverse'
22 _VALID_URL_TMPL
= r
'https?://(?:www\.)?wrestle-universe\.com/(?:(?P<lang>\w{2})/)?%s/(?P<id>\w+)'
28 _LOGIN_QUERY
= {'key': 'AIzaSyCaRPBsDQYVDUWWBXjsTrHESi2r_F3RAdA'}
31 'Content-Type': 'application/json',
32 'X-Client-Version': 'Chrome/JsCore/9.9.4/FirebaseCore-web',
33 'X-Firebase-gmpid': '1:307308870738:web:820f38fe5150c8976e338b',
34 'Referer': 'https://www.wrestle-universe.com/',
35 'Origin': 'https://www.wrestle-universe.com',
40 if not self
._REAL
_TOKEN
or not self
._TOKEN
_EXPIRY
:
41 token
= try_call(lambda: self
._get
_cookies
('https://www.wrestle-universe.com/')['token'].value
)
42 if not token
and not self
._REFRESH
_TOKEN
:
43 self
.raise_login_required()
44 self
._REAL
_TOKEN
= token
46 if not self
._REAL
_TOKEN
or self
._TOKEN
_EXPIRY
<= int(time
.time()):
47 if not self
._REFRESH
_TOKEN
:
49 'Expired token. Refresh your cookies in browser and try again', expected
=True)
52 return self
._REAL
_TOKEN
55 def _TOKEN(self
, value
):
56 self
._REAL
_TOKEN
= value
58 expiry
= traverse_obj(value
, ({jwt_decode_hs256}
, 'exp', {int_or_none}
))
60 raise ExtractorError('There was a problem with the auth token')
61 self
._TOKEN
_EXPIRY
= expiry
63 def _perform_login(self
, username
, password
):
64 login
= self
._download
_json
(
65 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword', None,
66 'Logging in', query
=self
._LOGIN
_QUERY
, headers
=self
._LOGIN
_HEADERS
, data
=json
.dumps({
67 'returnSecureToken': True,
70 }, separators
=(',', ':')).encode())
71 self
._REFRESH
_TOKEN
= traverse_obj(login
, ('refreshToken', {str}
))
72 if not self
._REFRESH
_TOKEN
:
73 self
.report_warning('No refresh token was granted')
74 self
._TOKEN
= traverse_obj(login
, ('idToken', {str}
))
76 def _real_initialize(self
):
77 if WrestleUniverseBaseIE
._DEVICE
_ID
:
80 WrestleUniverseBaseIE
._DEVICE
_ID
= self
._configuration
_arg
('device_id', [None], ie_key
='WrestleUniverse')[0]
81 if not WrestleUniverseBaseIE
._DEVICE
_ID
:
82 WrestleUniverseBaseIE
._DEVICE
_ID
= self
.cache
.load(self
._NETRC
_MACHINE
, 'device_id')
83 if WrestleUniverseBaseIE
._DEVICE
_ID
:
85 WrestleUniverseBaseIE
._DEVICE
_ID
= str(uuid
.uuid4())
87 self
.cache
.store(self
._NETRC
_MACHINE
, 'device_id', WrestleUniverseBaseIE
._DEVICE
_ID
)
89 def _refresh_token(self
):
90 refresh
= self
._download
_json
(
91 'https://securetoken.googleapis.com/v1/token', None, 'Refreshing token',
92 query
=self
._LOGIN
_QUERY
, data
=urlencode_postdata({
93 'grant_type': 'refresh_token',
94 'refresh_token': self
._REFRESH
_TOKEN
,
96 **self
._LOGIN
_HEADERS
,
97 'Content-Type': 'application/x-www-form-urlencoded',
99 if traverse_obj(refresh
, ('refresh_token', {str}
)):
100 self
._REFRESH
_TOKEN
= refresh
['refresh_token']
101 token
= traverse_obj(refresh
, 'access_token', 'id_token', expected_type
=str)
103 raise ExtractorError('No auth token returned from refresh request')
106 def _call_api(self
, video_id
, param
='', msg
='API', auth
=True, data
=None, query
={}, fatal
=True):
107 headers
= {'CA-CID': ''}
109 headers
['Content-Type'] = 'application/json;charset=utf-8'
110 data
= json
.dumps(data
, separators
=(',', ':')).encode()
112 headers
['Authorization'] = f
'Bearer {self._TOKEN}'
113 return self
._download
_json
(
114 f
'https://api.wrestle-universe.com/v1/{self._API_PATH}/{video_id}{param}', video_id
,
115 note
=f
'Downloading {msg} JSON', errnote
=f
'Failed to download {msg} JSON',
116 data
=data
, headers
=headers
, query
=query
, fatal
=fatal
)
118 def _call_encrypted_api(self
, video_id
, param
='', msg
='API', data
={}, query={}
, fatal
=True):
119 if not Cryptodome
.RSA
:
120 raise ExtractorError('pycryptodomex not found. Please install', expected
=True)
121 private_key
= Cryptodome
.RSA
.generate(2048)
122 cipher
= Cryptodome
.PKCS1_OAEP
.new(private_key
, hashAlgo
=Cryptodome
.SHA1
)
128 return cipher
.decrypt(base64
.b64decode(data
)).decode()
129 except (ValueError, binascii
.Error
) as e
:
130 raise ExtractorError(f
'Could not decrypt data: {e}')
132 token
= base64
.b64encode(private_key
.public_key().export_key('DER')).decode()
133 api_json
= self
._call
_api
(video_id
, param
, msg
, data
={
134 'deviceId': self
._DEVICE
_ID
,
137 }, query
=query
, fatal
=fatal
)
138 return api_json
, decrypt
140 def _download_metadata(self
, url
, video_id
, lang
, props_key
):
141 metadata
= self
._call
_api
(video_id
, msg
='metadata', query
={'al': lang or 'ja'}
, auth
=False, fatal
=False)
143 webpage
= self
._download
_webpage
(url
, video_id
)
144 nextjs_data
= self
._search
_nextjs
_data
(webpage
, video_id
)
145 metadata
= traverse_obj(nextjs_data
, ('props', 'pageProps', props_key
, {dict}
)) or {}
148 def _get_formats(self
, data
, path
, video_id
=None):
149 hls_url
= traverse_obj(data
, path
, get_all
=False)
150 if not hls_url
and not data
.get('canWatch'):
151 self
.raise_no_formats(
152 'This account does not have access to the requested content', expected
=True)
154 self
.raise_no_formats('No supported formats found')
155 return self
._extract
_m
3u8_formats
(hls_url
, video_id
, 'mp4', m3u8_id
='hls', live
=True)
158 class WrestleUniverseVODIE(WrestleUniverseBaseIE
):
159 _VALID_URL
= WrestleUniverseBaseIE
._VALID
_URL
_TMPL
% 'videos'
161 'url': 'https://www.wrestle-universe.com/en/videos/dp8mpjmcKfxzUhEHM2uFws',
163 'id': 'dp8mpjmcKfxzUhEHM2uFws',
165 'title': 'The 3rd “Futari wa Princess” Max Heart Tournament',
166 'description': 'md5:318d5061e944797fbbb81d5c7dd00bf5',
167 'location': '埼玉・春日部ふれあいキューブ',
170 'timestamp': 1674979200,
171 'upload_date': '20230129',
172 'thumbnail': 'https://image.asset.wrestle-universe.com/8FjD67P8rZc446RBQs5RBN/8FjD67P8rZc446RBQs5RBN',
173 'chapters': 'count:7',
177 'skip_download': 'm3u8',
181 _API_PATH
= 'videoEpisodes'
183 def _real_extract(self
, url
):
184 lang
, video_id
= self
._match
_valid
_url
(url
).group('lang', 'id')
185 metadata
= self
._download
_metadata
(url
, video_id
, lang
, 'videoEpisodeFallbackData')
186 video_data
= self
._call
_api
(video_id
, ':watch', 'watch', data
={
187 # 'deviceId' is required if ignoreDeviceRestriction is False
188 'ignoreDeviceRestriction': True,
193 'formats': self
._get
_formats
(video_data
, (
194 (('protocolHls', 'url'), ('chromecastUrls', ...)), {url_or_none}
), video_id
),
195 **traverse_obj(metadata
, {
196 'title': ('displayName', {str}
),
197 'description': ('description', {str}
),
198 'channel': ('labels', 'group', {str}
),
199 'location': ('labels', 'venue', {str}
),
200 'timestamp': ('watchStartTime', {int_or_none}
),
201 'thumbnail': ('keyVisualUrl', {url_or_none}
),
202 'cast': ('casts', ..., 'displayName', {str}
),
203 'duration': ('duration', {int}
),
204 'chapters': ('videoChapters', lambda _
, v
: isinstance(v
.get('start'), int), {
205 'title': ('displayName', {str}
),
206 'start_time': ('start', {int}
),
207 'end_time': ('end', {int}
),
213 class WrestleUniversePPVIE(WrestleUniverseBaseIE
):
214 _VALID_URL
= WrestleUniverseBaseIE
._VALID
_URL
_TMPL
% 'lives'
216 'note': 'HLS AES-128 key obtained via API',
217 'url': 'https://www.wrestle-universe.com/en/lives/buH9ibbfhdJAY4GKZcEuJX',
219 'id': 'buH9ibbfhdJAY4GKZcEuJX',
221 'title': '【PPV】Beyond the origins, into the future',
222 'description': 'md5:9a872db68cd09be4a1e35a3ee8b0bdfc',
224 'location': '東京・Twin Box AKIHABARA',
226 'timestamp': 1675076400,
227 'upload_date': '20230130',
228 'thumbnail': 'https://image.asset.wrestle-universe.com/rJs2m7cBaLXrwCcxMdQGRM/rJs2m7cBaLXrwCcxMdQGRM',
229 'thumbnails': 'count:3',
231 'key': '5633184acd6e43f1f1ac71c6447a4186',
232 'iv': '5bac71beb33197d5600337ce86de7862',
236 'skip_download': 'm3u8',
238 'skip': 'No longer available',
240 'note': 'unencrypted HLS',
241 'url': 'https://www.wrestle-universe.com/en/lives/wUG8hP5iApC63jbtQzhVVx',
243 'id': 'wUG8hP5iApC63jbtQzhVVx',
245 'title': 'GRAND PRINCESS \'22',
246 'description': 'md5:e4f43d0d4262de3952ff34831bc99858',
248 'location': '東京・両国国技館',
250 'timestamp': 1647665400,
251 'upload_date': '20220319',
252 'thumbnail': 'https://image.asset.wrestle-universe.com/i8jxSTCHPfdAKD4zN41Psx/i8jxSTCHPfdAKD4zN41Psx',
253 'thumbnails': 'count:3',
256 'skip_download': 'm3u8',
262 def _real_extract(self
, url
):
263 lang
, video_id
= self
._match
_valid
_url
(url
).group('lang', 'id')
264 metadata
= self
._download
_metadata
(url
, video_id
, lang
, 'eventFallbackData')
268 **traverse_obj(metadata
, {
269 'title': ('displayName', {str}
),
270 'description': ('description', {str}
),
271 'channel': ('labels', 'group', {str}
),
272 'location': ('labels', 'venue', {str}
),
273 'timestamp': ('startTime', {int_or_none}
),
274 'thumbnails': (('keyVisualUrl', 'alterKeyVisualUrl', 'heroKeyVisualUrl'), {'url': {url_or_none}
}),
278 ended_time
= traverse_obj(metadata
, ('endedTime', {int_or_none}
))
279 if info
.get('timestamp') and ended_time
:
280 info
['duration'] = ended_time
- info
['timestamp']
282 video_data
, decrypt
= self
._call
_encrypted
_api
(
283 video_id
, ':watchArchive', 'watch archive', data
={'method': 1}
)
284 info
['formats'] = self
._get
_formats
(video_data
, (
285 ('hls', None), ('urls', 'chromecastUrls'), ..., {url_or_none}
), video_id
)
286 for f
in info
['formats']:
287 # bitrates are exaggerated in PPV playlists, so avoid wrong/huge filesize_approx values
289 f
['tbr'] = int(f
['tbr'] / 2.5)
291 hls_aes_key
= traverse_obj(video_data
, ('hls', 'key', {decrypt}
))
295 'iv': traverse_obj(video_data
, ('hls', 'iv', {decrypt}
)),
297 elif traverse_obj(video_data
, ('hls', 'encryptType', {int}
)):
298 self
.report_warning('HLS AES-128 key was not found in API response')