From 2be0682393aa6e4e2627401c035ef9cbd0b1015f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 12 Sep 2012 12:44:50 +0200 Subject: [PATCH] vimeo: Handle vp6 and vp8 codecs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Older videos aren't available as h264, so check the available codecs and ask for the latest. Signed-off-by: François Revol Signed-off-by: Romain Bignon --- modules/vimeo/pages.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/vimeo/pages.py b/modules/vimeo/pages.py index efd4724f..26cb869e 100644 --- a/modules/vimeo/pages.py +++ b/modules/vimeo/pages.py @@ -72,7 +72,7 @@ class VideoPage(BasePage): json_data = self.browser.openurl('http://%s/config/%s?type=%s&referrer=%s' % ("player.vimeo.com", int(v.id), "html5_desktop_local", "")) data = json.load(json_data) if data is None: - raise BrokenPageError('Unable to get JSON config for id: %r' % v.id) + raise BrokenPageError('Unable to get JSON config for id: %r' % int(v.id)) #print data if v.title is None: @@ -81,12 +81,23 @@ class VideoPage(BasePage): v.thumbnail = Thumbnail(unicode(data['video']['thumbnail'])) v.duration = datetime.timedelta(seconds=int(data['video']['duration'])) - # use highest quality + # determine available codec and quality + # use highest quality possible quality = 'sd' - if 'hd' in data['video']['files']['h264']: + codec = None + if 'vp6' in data['video']['files']: + codec = 'vp6' + if 'vp8' in data['video']['files']: + codec = 'vp8' + if 'h264' in data['video']['files']: + codec = 'h264' + if not codec: + raise BrokenPageError('Unable to detect available codec for id: %r' % int(v.id)) + + if 'hd' in data['video']['files'][codec]: quality = 'hd' - v.url = unicode("http://player.vimeo.com/play_redirect?quality=%s&codecs=h264&clip_id=%d&time=%s&sig=%s&type=html5_desktop_local" % (quality, int(v.id), data['request']['timestamp'] , data['request']['signature'])) + v.url = unicode("http://player.vimeo.com/play_redirect?quality=%s&codecs=%s&clip_id=%d&time=%s&sig=%s&type=html5_desktop_local" % (quality, codec, int(v.id), data['request']['timestamp'] , data['request']['signature'])) # attempt to determine the redirected URL to pass it instead # since the target server doesn't check for User-Agent, unlike