vimeo: Fix for no-embed videos
Some videos like http://vimeo.com/61275290 have restrictions on embedding, which makes the usual JSON url fail. So we first try to parse the JSON data directly from the script element in the page. Signed-off-by: François Revol <revol@free.fr>
This commit is contained in:
parent
df704f33d9
commit
1d0faa1af0
1 changed files with 17 additions and 4 deletions
|
|
@ -27,6 +27,7 @@ from urllib2 import HTTPError
|
||||||
from weboob.tools.browser import BasePage
|
from weboob.tools.browser import BasePage
|
||||||
from weboob.tools.json import json
|
from weboob.tools.json import json
|
||||||
|
|
||||||
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
from dateutil.parser import parse as parse_dt
|
from dateutil.parser import parse as parse_dt
|
||||||
|
|
||||||
|
|
@ -65,12 +66,24 @@ class VideoPage(BasePage):
|
||||||
if len(obj) > 0:
|
if len(obj) > 0:
|
||||||
v.thumbnail = Thumbnail(unicode(obj[0].attrib['content']))
|
v.thumbnail = Thumbnail(unicode(obj[0].attrib['content']))
|
||||||
|
|
||||||
# for the rest, use the JSON config descriptor
|
data = None
|
||||||
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)
|
# First try to find the JSON data in the page itself.
|
||||||
|
# it's the only location in case the video is not allowed to be embeded
|
||||||
|
for script in self.parser.select(self.document.getroot(), 'script'):
|
||||||
|
m = re.match('.* = {config:({.*}),assets:.*', unicode(script.text), re.DOTALL)
|
||||||
|
if m:
|
||||||
|
data = json.loads(m.group(1))
|
||||||
|
break
|
||||||
|
|
||||||
|
# Else fall back to the API
|
||||||
|
if data is None:
|
||||||
|
# for the rest, use the JSON config descriptor
|
||||||
|
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:
|
if data is None:
|
||||||
raise BrokenPageError('Unable to get JSON config for id: %r' % int(v.id))
|
raise BrokenPageError('Unable to get JSON config for id: %r' % int(v.id))
|
||||||
#print data
|
|
||||||
|
|
||||||
if v.title is None:
|
if v.title is None:
|
||||||
v.title = unicode(data['video']['title'])
|
v.title = unicode(data['video']['title'])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue