[utils] Fix js_to_json
parent
07e764439a
commit
410f3e73ab
|
@ -44,6 +44,7 @@ from youtube_dl.utils import (
|
||||||
limit_length,
|
limit_length,
|
||||||
escape_rfc3986,
|
escape_rfc3986,
|
||||||
escape_url,
|
escape_url,
|
||||||
|
js_to_json,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -331,5 +332,14 @@ class TestUtil(unittest.TestCase):
|
||||||
)
|
)
|
||||||
self.assertEqual(escape_url('http://vimeo.com/56015672#at=0'), 'http://vimeo.com/56015672#at=0')
|
self.assertEqual(escape_url('http://vimeo.com/56015672#at=0'), 'http://vimeo.com/56015672#at=0')
|
||||||
|
|
||||||
|
def test_js_to_json(self):
|
||||||
|
inp = '''{
|
||||||
|
'clip':{'provider':'pseudo'}
|
||||||
|
}'''
|
||||||
|
self.assertEqual(js_to_json(inp), '''{
|
||||||
|
"clip":{"provider":"pseudo"}
|
||||||
|
}''')
|
||||||
|
json.loads(js_to_json(inp))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -673,6 +673,8 @@ class ExtractorError(Exception):
|
||||||
expected = True
|
expected = True
|
||||||
if video_id is not None:
|
if video_id is not None:
|
||||||
msg = video_id + ': ' + msg
|
msg = video_id + ': ' + msg
|
||||||
|
if cause:
|
||||||
|
msg += u' (caused by %r)' % cause
|
||||||
if not expected:
|
if not expected:
|
||||||
msg = msg + u'; please report this issue on https://yt-dl.org/bug . Be sure to call youtube-dl with the --verbose flag and include its complete output. Make sure you are using the latest version; type youtube-dl -U to update.'
|
msg = msg + u'; please report this issue on https://yt-dl.org/bug . Be sure to call youtube-dl with the --verbose flag and include its complete output. Make sure you are using the latest version; type youtube-dl -U to update.'
|
||||||
super(ExtractorError, self).__init__(msg)
|
super(ExtractorError, self).__init__(msg)
|
||||||
|
@ -1598,7 +1600,9 @@ def js_to_json(code):
|
||||||
([{,]\s*)
|
([{,]\s*)
|
||||||
("[^"]*"|\'[^\']*\'|[a-z0-9A-Z]+)
|
("[^"]*"|\'[^\']*\'|[a-z0-9A-Z]+)
|
||||||
(:\s*)
|
(:\s*)
|
||||||
([0-9.]+|true|false|"[^"]*"|\'[^\']*\'|\[|\{)
|
([0-9.]+|true|false|"[^"]*"|\'[^\']*\'|
|
||||||
|
(?=\[|\{)
|
||||||
|
)
|
||||||
''', fix_kv, code)
|
''', fix_kv, code)
|
||||||
res = re.sub(r',(\s*\])', lambda m: m.group(1), res)
|
res = re.sub(r',(\s*\])', lambda m: m.group(1), res)
|
||||||
return res
|
return res
|
||||||
|
|
Loading…
Reference in New Issue