From: Philipp Hagemeister Date: Thu, 13 Nov 2014 15:28:05 +0000 (+0100) Subject: [npo] Improve npo.nl (Fixes #4173) X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=609a61e3e6fffce3d45e845f33ae2c5fa2d432ac;p=youtube-dl.git [npo] Improve npo.nl (Fixes #4173) --- diff --git a/test/test_utils.py b/test/test_utils.py index a9649397f..edd95c3e3 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -284,6 +284,10 @@ class TestUtil(unittest.TestCase): d = json.loads(stripped) self.assertEqual(d, [{"id": "532cb", "x": 3}]) + stripped = strip_jsonp('parseMetadata({"STATUS":"OK"})\n\n\n//epc') + d = json.loads(stripped) + self.assertEqual(d, {'STATUS': 'OK'}) + def test_uppercase_escape(self): self.assertEqual(uppercase_escape('aä'), 'aä') self.assertEqual(uppercase_escape('\\U0001d550'), '𝕐') diff --git a/youtube_dl/extractor/npo.py b/youtube_dl/extractor/npo.py index f36d446d2..ce31694a5 100644 --- a/youtube_dl/extractor/npo.py +++ b/youtube_dl/extractor/npo.py @@ -7,6 +7,7 @@ from ..utils import ( unified_strdate, parse_duration, qualities, + strip_jsonp, url_basename, ) @@ -63,7 +64,7 @@ class NPOIE(InfoExtractor): 'http://e.omroep.nl/metadata/aflevering/%s' % video_id, video_id, # We have to remove the javascript callback - transform_source=lambda j: re.sub(r'parseMetadata\((.*?)\);\n//.*$', r'\1', j) + transform_source=strip_jsonp, ) token_page = self._download_webpage( 'http://ida.omroep.nl/npoplayer/i.js', diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 0b2ba39e2..5786fa699 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1331,7 +1331,8 @@ def parse_age_limit(s): def strip_jsonp(code): - return re.sub(r'(?s)^[a-zA-Z0-9_]+\s*\(\s*(.*)\);?\s*?\s*$', r'\1', code) + return re.sub( + r'(?s)^[a-zA-Z0-9_]+\s*\(\s*(.*)\);?\s*?(?://[^\n]*)*$', r'\1', code) def js_to_json(code):