mirror of https://github.com/yt-dlp/yt-dlp.git
parent
e3b42d8b1b
commit
3ee1194288
|
@ -1906,6 +1906,15 @@ jwplayer("mediaplayer").setup({"abouttext":"Visit Indie DB","aboutlink":"http:\/
|
||||||
expected_status=TEAPOT_RESPONSE_STATUS)
|
expected_status=TEAPOT_RESPONSE_STATUS)
|
||||||
self.assertEqual(content, TEAPOT_RESPONSE_BODY)
|
self.assertEqual(content, TEAPOT_RESPONSE_BODY)
|
||||||
|
|
||||||
|
def test_search_nextjs_data(self):
|
||||||
|
data = '<script id="__NEXT_DATA__" type="application/json">{"props":{}}</script>'
|
||||||
|
self.assertEqual(self.ie._search_nextjs_data(data, None), {'props': {}})
|
||||||
|
self.assertEqual(self.ie._search_nextjs_data('', None, fatal=False), {})
|
||||||
|
self.assertEqual(self.ie._search_nextjs_data('', None, default=None), None)
|
||||||
|
self.assertEqual(self.ie._search_nextjs_data('', None, default={}), {})
|
||||||
|
with self.assertRaises(DeprecationWarning):
|
||||||
|
self.assertEqual(self.ie._search_nextjs_data('', None, default='{}'), {})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -105,7 +105,7 @@ class AsobiStageIE(InfoExtractor):
|
||||||
video_type = {'archive': 'archives', 'player': 'broadcasts'}[type_]
|
video_type = {'archive': 'archives', 'player': 'broadcasts'}[type_]
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
event_data = traverse_obj(
|
event_data = traverse_obj(
|
||||||
self._search_nextjs_data(webpage, video_id, default='{}'),
|
self._search_nextjs_data(webpage, video_id, default={}),
|
||||||
('props', 'pageProps', 'eventCMSData', {
|
('props', 'pageProps', 'eventCMSData', {
|
||||||
'title': ('event_name', {str}),
|
'title': ('event_name', {str}),
|
||||||
'thumbnail': ('event_thumbnail_image', {url_or_none}),
|
'thumbnail': ('event_thumbnail_image', {url_or_none}),
|
||||||
|
|
|
@ -1738,12 +1738,16 @@ class InfoExtractor:
|
||||||
traverse_json_ld(json_ld)
|
traverse_json_ld(json_ld)
|
||||||
return filter_dict(info)
|
return filter_dict(info)
|
||||||
|
|
||||||
def _search_nextjs_data(self, webpage, video_id, *, transform_source=None, fatal=True, **kw):
|
def _search_nextjs_data(self, webpage, video_id, *, fatal=True, default=NO_DEFAULT, **kw):
|
||||||
return self._parse_json(
|
if default == '{}':
|
||||||
self._search_regex(
|
self._downloader.deprecation_warning('using `default=\'{}\'` is deprecated, use `default={}` instead')
|
||||||
r'(?s)<script[^>]+id=[\'"]__NEXT_DATA__[\'"][^>]*>([^<]+)</script>',
|
default = {}
|
||||||
webpage, 'next.js data', fatal=fatal, **kw),
|
if default is not NO_DEFAULT:
|
||||||
video_id, transform_source=transform_source, fatal=fatal)
|
fatal = False
|
||||||
|
|
||||||
|
return self._search_json(
|
||||||
|
r'<script[^>]+id=[\'"]__NEXT_DATA__[\'"][^>]*>', webpage, 'next.js data',
|
||||||
|
video_id, end_pattern='</script>', fatal=fatal, default=default, **kw)
|
||||||
|
|
||||||
def _search_nuxt_data(self, webpage, video_id, context_name='__NUXT__', *, fatal=True, traverse=('data', 0)):
|
def _search_nuxt_data(self, webpage, video_id, context_name='__NUXT__', *, fatal=True, traverse=('data', 0)):
|
||||||
"""Parses Nuxt.js metadata. This works as long as the function __NUXT__ invokes is a pure function"""
|
"""Parses Nuxt.js metadata. This works as long as the function __NUXT__ invokes is a pure function"""
|
||||||
|
|
|
@ -41,7 +41,7 @@ class STVPlayerIE(InfoExtractor):
|
||||||
ptype, video_id = self._match_valid_url(url).groups()
|
ptype, video_id = self._match_valid_url(url).groups()
|
||||||
|
|
||||||
webpage = self._download_webpage(url, video_id, fatal=False) or ''
|
webpage = self._download_webpage(url, video_id, fatal=False) or ''
|
||||||
props = self._search_nextjs_data(webpage, video_id, default='{}').get('props') or {}
|
props = self._search_nextjs_data(webpage, video_id, default={}).get('props') or {}
|
||||||
player_api_cache = try_get(
|
player_api_cache = try_get(
|
||||||
props, lambda x: x['initialReduxState']['playerApiCache']) or {}
|
props, lambda x: x['initialReduxState']['playerApiCache']) or {}
|
||||||
|
|
||||||
|
|
|
@ -776,7 +776,7 @@ class TikTokIE(TikTokBaseIE):
|
||||||
status = traverse_obj(sigi_data, ('VideoPage', 'statusCode', {int})) or 0
|
status = traverse_obj(sigi_data, ('VideoPage', 'statusCode', {int})) or 0
|
||||||
video_data = traverse_obj(sigi_data, ('ItemModule', video_id, {dict}))
|
video_data = traverse_obj(sigi_data, ('ItemModule', video_id, {dict}))
|
||||||
|
|
||||||
elif next_data := self._search_nextjs_data(webpage, video_id, default='{}'):
|
elif next_data := self._search_nextjs_data(webpage, video_id, default={}):
|
||||||
self.write_debug('Found next.js data')
|
self.write_debug('Found next.js data')
|
||||||
status = traverse_obj(next_data, ('props', 'pageProps', 'statusCode', {int})) or 0
|
status = traverse_obj(next_data, ('props', 'pageProps', 'statusCode', {int})) or 0
|
||||||
video_data = traverse_obj(next_data, ('props', 'pageProps', 'itemInfo', 'itemStruct', {dict}))
|
video_data = traverse_obj(next_data, ('props', 'pageProps', 'itemInfo', 'itemStruct', {dict}))
|
||||||
|
|
Loading…
Reference in New Issue