mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-27 06:10:38 +01:00
[utils] Recognize more patterns in strip_jsonp()
Used in Youku Show pages
This commit is contained in:
parent
59ed87cbd9
commit
5552c9eb0f
|
@ -1,6 +1,7 @@
|
||||||
version <unreleased>
|
version <unreleased>
|
||||||
|
|
||||||
Core
|
Core
|
||||||
|
+ [utils] strip_jsonp() can recognize more patterns
|
||||||
* [postprocessor/ffmpeg] Fix metadata filename handling on Python 2 (#13182)
|
* [postprocessor/ffmpeg] Fix metadata filename handling on Python 2 (#13182)
|
||||||
|
|
||||||
Extractors
|
Extractors
|
||||||
|
|
|
@ -678,6 +678,14 @@ class TestUtil(unittest.TestCase):
|
||||||
d = json.loads(stripped)
|
d = json.loads(stripped)
|
||||||
self.assertEqual(d, {'status': 'success'})
|
self.assertEqual(d, {'status': 'success'})
|
||||||
|
|
||||||
|
stripped = strip_jsonp('window.cb && window.cb({"status": "success"});')
|
||||||
|
d = json.loads(stripped)
|
||||||
|
self.assertEqual(d, {'status': 'success'})
|
||||||
|
|
||||||
|
stripped = strip_jsonp('window.cb && cb({"status": "success"});')
|
||||||
|
d = json.loads(stripped)
|
||||||
|
self.assertEqual(d, {'status': 'success'})
|
||||||
|
|
||||||
def test_uppercase_escape(self):
|
def test_uppercase_escape(self):
|
||||||
self.assertEqual(uppercase_escape('aä'), 'aä')
|
self.assertEqual(uppercase_escape('aä'), 'aä')
|
||||||
self.assertEqual(uppercase_escape('\\U0001d550'), '𝕐')
|
self.assertEqual(uppercase_escape('\\U0001d550'), '𝕐')
|
||||||
|
|
|
@ -2211,7 +2211,12 @@ def parse_age_limit(s):
|
||||||
|
|
||||||
def strip_jsonp(code):
|
def strip_jsonp(code):
|
||||||
return re.sub(
|
return re.sub(
|
||||||
r'(?s)^[a-zA-Z0-9_.$]+\s*\(\s*(.*)\);?\s*?(?://[^\n]*)*$', r'\1', code)
|
r'''(?sx)^
|
||||||
|
(?:window\.)?(?P<func_name>[a-zA-Z0-9_.$]+)
|
||||||
|
(?:\s*&&\s*(?P=func_name))?
|
||||||
|
\s*\(\s*(?P<callback_data>.*)\);?
|
||||||
|
\s*?(?://[^\n]*)*$''',
|
||||||
|
r'\g<callback_data>', code)
|
||||||
|
|
||||||
|
|
||||||
def js_to_json(code):
|
def js_to_json(code):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user