[weboob] [PATCH 2/2] vimeo: Handle vp6 and vp8 codecs

François Revol revol at free.fr
Wed Sep 12 12:44:50 CEST 2012


Older videos aren't available as h264, so check the available
codecs and ask for the latest.

Signed-off-by: François Revol <revol at free.fr>
---
 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 efd4724..26cb869 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
-- 
1.7.10.4




More information about the weboob mailing list