Compare commits

..

No commits in common. "389f903005bc4cd18b05e6164bf1427b3c9acd5d" and "142b58c696262bc671a8b57d112c88a93f1b23cd" have entirely different histories.

3 changed files with 13 additions and 10 deletions

View File

@ -1200,12 +1200,6 @@ class TestUtil(unittest.TestCase):
self.assertEqual(js_to_json('`${name}"${name}"`', {'name': '5'}), '"5\\"5\\""') self.assertEqual(js_to_json('`${name}"${name}"`', {'name': '5'}), '"5\\"5\\""')
self.assertEqual(js_to_json('`${name}`', {}), '"name"') self.assertEqual(js_to_json('`${name}`', {}), '"name"')
def test_js_to_json_map_array_constructors(self):
self.assertEqual(json.loads(js_to_json('new Map([["a", 5]])')), {'a': 5})
self.assertEqual(json.loads(js_to_json('Array(5, 10)')), [5, 10])
self.assertEqual(json.loads(js_to_json('new Array(15,5)')), [15, 5])
self.assertEqual(json.loads(js_to_json('new Map([Array(5, 10),new Array(15,5)])')), {'5': 10, '15': 5})
def test_extract_attributes(self): def test_extract_attributes(self):
self.assertEqual(extract_attributes('<e x="y">'), {'x': 'y'}) self.assertEqual(extract_attributes('<e x="y">'), {'x': 'y'})
self.assertEqual(extract_attributes("<e x='y'>"), {'x': 'y'}) self.assertEqual(extract_attributes("<e x='y'>"), {'x': 'y'})

View File

@ -139,9 +139,11 @@ class IPrimaIE(InfoExtractor):
nuxt_data, (..., 'content', 'additionals', 'videoPlayId', {str}), get_all=False) nuxt_data, (..., 'content', 'additionals', 'videoPlayId', {str}), get_all=False)
if not video_id: if not video_id:
nuxt_data = self._search_json( nuxt_data = self._parse_json(
r'<script[^>]+\bid=["\']__NUXT_DATA__["\'][^>]*>', self._search_regex(
webpage, 'nuxt data', None, end_pattern=r'</script>', contains_pattern=r'(?s:.+?)') r'(?s)<script[^>]+\bid=["\']__NUXT_DATA__["\'][^>]+>(.+?)</script>',
webpage, 'nuxt data'),
'nuxt data')
video_id = traverse_obj(nuxt_data, lambda _, v: re.fullmatch(r'p\d+', v), get_all=False) video_id = traverse_obj(nuxt_data, lambda _, v: re.fullmatch(r'p\d+', v), get_all=False)

View File

@ -3234,8 +3234,15 @@ def js_to_json(code, vars={}, *, strict=False):
def create_map(mobj): def create_map(mobj):
return json.dumps(dict(json.loads(js_to_json(mobj.group(1) or '[]', vars=vars)))) return json.dumps(dict(json.loads(js_to_json(mobj.group(1) or '[]', vars=vars))))
code = re.sub(r'(?:new\s+)?Array\((.*?)\)', r'[\g<1>]', code) def create_array(mobj):
return mobj.group(1) + js_to_json(f'[{mobj.group(2)}]', vars=vars) + mobj.group(3)
code = re.sub(r'new Map\((\[.*?\])?\)', create_map, code) code = re.sub(r'new Map\((\[.*?\])?\)', create_map, code)
while True:
old_code = code
code = re.sub(r'^(.*?)(?:new\s+)?Array\((.*?)\)(.*?)$', create_array, old_code)
if old_code == code:
break
if not strict: if not strict:
code = re.sub(r'new Date\((".+")\)', r'\g<1>', code) code = re.sub(r'new Date\((".+")\)', r'\g<1>', code)
code = re.sub(r'new \w+\((.*?)\)', lambda m: json.dumps(m.group(0)), code) code = re.sub(r'new \w+\((.*?)\)', lambda m: json.dumps(m.group(0)), code)