mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-06-28 01:18:30 +00:00
[test:InfoExtractor] improve _search_nuxt_json
test
Authored by: bashonly
This commit is contained in:
parent
4c2e4840d3
commit
8578e78719
@ -1948,11 +1948,10 @@ def test_search_nextjs_data(self):
|
|||||||
self.assertEqual(self.ie._search_nextjs_data('', None, default='{}'), {})
|
self.assertEqual(self.ie._search_nextjs_data('', None, default='{}'), {})
|
||||||
|
|
||||||
def test_search_nuxt_json(self):
|
def test_search_nuxt_json(self):
|
||||||
HTML = '''
|
HTML_TMPL = '<script data-ssr="true" id="__NUXT_DATA__" type="application/json">[{}]</script>'
|
||||||
<script data-ssr="true" id="__NUXT_DATA__" type="application/json">
|
VALID_DATA = '''
|
||||||
[
|
|
||||||
["ShallowReactive",1],
|
["ShallowReactive",1],
|
||||||
{"data":2,"state":21,"once":25,"_errors":28},
|
{"data":2,"state":21,"once":25,"_errors":28,"_server_errors":30},
|
||||||
["ShallowReactive",3],
|
["ShallowReactive",3],
|
||||||
{"$abcdef123456":4},
|
{"$abcdef123456":4},
|
||||||
{"podcast":5,"activeEpisodeData":7},
|
{"podcast":5,"activeEpisodeData":7},
|
||||||
@ -1960,7 +1959,7 @@ def test_search_nuxt_json(self):
|
|||||||
{"title":10,"id":11},
|
{"title":10,"id":11},
|
||||||
["Reactive",8],
|
["Reactive",8],
|
||||||
{"episode":9,"creators":18,"empty_list":20},
|
{"episode":9,"creators":18,"empty_list":20},
|
||||||
{"title":12,"id":13},
|
{"title":12,"id":13,"refs":34,"empty_refs":35},
|
||||||
"Series Title",
|
"Series Title",
|
||||||
"podcast-id-01",
|
"podcast-id-01",
|
||||||
"Episode Title",
|
"Episode Title",
|
||||||
@ -1980,9 +1979,22 @@ def test_search_nuxt_json(self):
|
|||||||
["Reactive",27],
|
["Reactive",27],
|
||||||
["Map"],
|
["Map"],
|
||||||
["ShallowReactive",29],
|
["ShallowReactive",29],
|
||||||
{}
|
{},
|
||||||
]
|
["NuxtError",31],
|
||||||
</script>'''
|
{"status":32,"message":33},
|
||||||
|
503,
|
||||||
|
"Service Unavailable",
|
||||||
|
[36,37],
|
||||||
|
[38,39],
|
||||||
|
["Ref",40],
|
||||||
|
["ShallowRef",41],
|
||||||
|
["EmptyRef",42],
|
||||||
|
["EmptyShallowRef",43],
|
||||||
|
"ref",
|
||||||
|
"shallow_ref",
|
||||||
|
"{\\"ref\\":1}",
|
||||||
|
"{\\"shallow_ref\\":2}"
|
||||||
|
'''
|
||||||
PAYLOAD = {
|
PAYLOAD = {
|
||||||
'data': {
|
'data': {
|
||||||
'$abcdef123456': {
|
'$abcdef123456': {
|
||||||
@ -1997,6 +2009,8 @@ def test_search_nuxt_json(self):
|
|||||||
'episode': {
|
'episode': {
|
||||||
'title': 'Episode Title',
|
'title': 'Episode Title',
|
||||||
'id': 'episode-id-99',
|
'id': 'episode-id-99',
|
||||||
|
'refs': ['ref', 'shallow_ref'],
|
||||||
|
'empty_refs': [{'ref': 1}, {'shallow_ref': 2}],
|
||||||
},
|
},
|
||||||
'creators': ['Podcast Creator'],
|
'creators': ['Podcast Creator'],
|
||||||
'empty_list': [],
|
'empty_list': [],
|
||||||
@ -2013,20 +2027,43 @@ def test_search_nuxt_json(self):
|
|||||||
},
|
},
|
||||||
'once': [],
|
'once': [],
|
||||||
'_errors': {},
|
'_errors': {},
|
||||||
|
'_server_errors': {
|
||||||
|
'status': 503,
|
||||||
|
'message': 'Service Unavailable',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
BAD_HTML = '''
|
INVALID_LIST = [
|
||||||
<script data-ssr="true" id="__NUXT_DATA__" type="application/json">
|
'''
|
||||||
[
|
{"data":1},
|
||||||
["ShallowReactive",1],
|
{"invalid_raw_list":2},
|
||||||
{"data":2},
|
|
||||||
{"improper_raw_list":3},
|
|
||||||
[15,16,17]
|
[15,16,17]
|
||||||
|
''',
|
||||||
|
'''
|
||||||
|
{"data":1},
|
||||||
|
["EmptyRef",2],
|
||||||
|
"not valid JSON"
|
||||||
|
''',
|
||||||
|
'''
|
||||||
|
{"data":1},
|
||||||
|
["EmptyShallowRef",2],
|
||||||
|
"not valid JSON"
|
||||||
|
''',
|
||||||
|
'''
|
||||||
|
{"data":1},
|
||||||
|
["unsupported",2],
|
||||||
|
{}
|
||||||
|
''',
|
||||||
]
|
]
|
||||||
</script>'''
|
DEFAULT = {'default': 'works'}
|
||||||
|
|
||||||
self.assertEqual(self.ie._search_nuxt_json(HTML, 'id'), PAYLOAD)
|
self.assertEqual(self.ie._search_nuxt_json(HTML_TMPL.format(VALID_DATA), None), PAYLOAD)
|
||||||
self.assertEqual(self.ie._search_nuxt_json('', None, fatal=False), {})
|
self.assertEqual(self.ie._search_nuxt_json('', None, fatal=False), {})
|
||||||
self.assertEqual(self.ie._search_nuxt_json(BAD_HTML, None, default={}), {})
|
self.assertEqual(self.ie._search_nuxt_json('', None, default=DEFAULT), DEFAULT)
|
||||||
|
self.assertEqual(self.ie._search_nuxt_json(HTML_TMPL.format(INVALID_LIST[0]), None, fatal=False), {})
|
||||||
|
for invalid_data in INVALID_LIST[1:]:
|
||||||
|
self.assertEqual(
|
||||||
|
self.ie._search_nuxt_json(HTML_TMPL.format(invalid_data), None, default=DEFAULT),
|
||||||
|
DEFAULT)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user