Commit e89da8aa authored by ntome's avatar ntome Committed by Romain Bignon

[vimeo] fix and port to python3

parent 86356bc0
Pipeline #1116 failed with stages
in 62 minutes and 9 seconds
......@@ -18,10 +18,13 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from base64 import b64encode
from weboob.browser import PagesBrowser, URL
from weboob.browser.exceptions import HTTPNotFound
from weboob.capabilities.base import NotAvailable
from weboob.tools.compat import urljoin, quote_plus
from .pages import VideoJsonPage, CategoriesPage, ListPage, APIPage, XMLAPIPage
import time
......@@ -77,15 +80,14 @@ class VimeoBrowser(PagesBrowser):
if self.method == u'hls':
streams = []
for item in self.read_url(video.url):
if not item.startswith('#'):
item = item.decode('ascii')
if not item.startswith('#') and item.strip():
streams.append(item)
if streams:
streams.reverse()
url = streams[self.quality] if self.quality < len(streams) else streams[0]
if url.startswith('..'):
video.url = urljoin(video.url, url)
else:
video.url = url
video.url = urljoin(video.url, url)
else:
video.url = NotAvailable
return video
......@@ -139,10 +141,6 @@ class VimeoBrowser(PagesBrowser):
def _create_authorization(self, url, method, params=None):
def _percent_encode(s):
if isinstance(s, unicode):
s = s.encode('utf-8')
pass
result = quote_plus(s).replace('+', '%20').replace('*', '%2A').replace('%7E', '~')
# the implementation of the app has a bug. someone double escaped the '@' so we have to correct this
# on our end.
......@@ -151,8 +149,12 @@ class VimeoBrowser(PagesBrowser):
def _compute_signature(s):
key = _percent_encode(self.CONSUMER_SECRET) + '&' + _percent_encode('')
key = key.encode('ascii')
s = s.encode('ascii')
a = hmac.new(key, s, sha1)
return a.digest().encode("base64").rstrip('\n')
sig = b64encode(a.digest()).decode('ascii')
sig = sig.rstrip('\n')
return sig
def _normalize_parameters(_params):
sorted_keys = sorted(_params.keys())
......
......@@ -45,7 +45,7 @@ class VimeoModule(Module, CapVideo, CapCollection):
SORTBY = ['relevance', 'rating', 'views', 'time']
quality_choice = OrderedDict([(k, v) for k, v in sorted(
{u'0': u'hight', u'1': u'medium', u'2': u'low'}.iteritems())])
{u'0': u'high', u'1': u'medium', u'2': u'low'}.items())])
method_choice = [u'hls', u'progressive']
......
......@@ -26,7 +26,7 @@ from weboob.exceptions import ParseError
from weboob.browser.elements import ItemElement, ListElement, method, DictElement
from weboob.browser.pages import HTMLPage, pagination, JsonPage, XMLPage
from weboob.browser.filters.standard import Regexp, Env, CleanText, DateTime, Duration, Field, BrowserURL
from weboob.browser.filters.html import Attr, Link, XPath
from weboob.browser.filters.html import Attr, Link
from weboob.browser.filters.json import Dict
import re
......@@ -99,14 +99,18 @@ class VideoJsonPage(JsonPage):
# Choosen method is not available, we choose an other one
method = self.obj._method
if method not in data['request']['files']:
method = data['request']['files'].keys()[0]
method = list(data['request']['files'].keys())[0]
streams = data['request']['files'][method]
if not streams:
raise ValueError('There is no url available for id: %r' % (int(Field('id')(self))))
# stream is single for hls, just return the url
stream = streams['url'] if method == 'hls' else None
stream = None
if method == 'hls':
if 'url' in streams:
stream = streams['url']
else:
stream = streams['cdns'][streams['default_cdn']]['url']
# ...but a list for progressive
# we assume the list is sorted by quality with best first
......@@ -116,8 +120,6 @@ class VideoJsonPage(JsonPage):
return stream
obj_ext = Regexp(Field('url'), '.*\.(.*)\?.*$', '\\1')
class CategoriesPage(HTMLPage):
@method
......@@ -168,7 +170,7 @@ class XMLAPIPage(XMLPage):
class fill_video_infos(VimeoItem):
def __init__(self, *args, **kwargs):
super(VimeoItem, self).__init__(*args, **kwargs)
self.el = XPath('/rsp/video')(self.el)[0]
self.el = self.el.xpath('/rsp/video')[0]
@pagination
@method
......
......@@ -91,6 +91,7 @@ supertoinette/
tumblr/
tvsubtitles/
twitter/
vimeo/
vlille/
wordreference/
xhamster/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment