detect if video is forbidden and raise an appropriated exception

This commit is contained in:
Romain Bignon 2013-03-28 17:29:43 +01:00
commit 7f81f261a1

View file

@ -125,4 +125,9 @@ class VideoPage(BaseYoutubePage):
ext = self.FORMAT_EXTENSIONS.get(format, 'flv')
return url, ext
# check errors only here, in case the video url is available though
error = self.document.xpath('//h1[@id="unavailable-message"]')
if len(error) > 0:
raise ForbiddenVideo(unicode(error[0].text).strip())
raise BrokenPageError('Unable to find file URL')