youtube: Fix crash with weird characters

This commit is contained in:
Laurent Bachelier 2013-07-21 01:53:33 +02:00
commit 5a548e1e8c
2 changed files with 15 additions and 0 deletions

View file

@ -19,6 +19,7 @@
from urlparse import parse_qsl
import re
from weboob.capabilities.base import UserError
from weboob.tools.browser import BasePage, BrokenPageError, BrowserIncorrectPassword
@ -137,6 +138,9 @@ class VideoPage(BaseYoutubePage):
continue
sub = text[pos+len(pattern):].rstrip(';\n')
# json spec only allows \u - convert other escape sequences
sub = re.sub(r'\\x([a-f0-9]{2})', r'\u\1', sub)
sub = re.sub(r'\\U([a-f0-9]{4})([a-f0-9]{4})', r'\u\1\u\2', sub)
a = json.loads(sub)
for part in a['args']['url_encoded_fmt_stream_map'].split(','):

View file

@ -37,3 +37,14 @@ class YoutubeTest(BackendTest):
def test_latest(self):
l = list(self.backend.iter_resources([BaseVideo], [u'latest']))
assert len(l) > 0
def test_drm(self):
v = self.backend.get_video('http://youtu.be/UxxajLWwzqY')
self.backend.fillobj(v, ('url',))
assert len(v.url)
self.backend.browser.openurl(v.url)
def test_weirdchars(self):
v = self.backend.get_video('https://www.youtube.com/watch?v=BaW_jenozKc')
self.backend.fillobj(v, ('title', 'url',))
assert unicode(v.title)