cleanup pylint errors and py2/3 issues
This commit is contained in:
parent
4e7898ae57
commit
77f8876fca
20 changed files with 232 additions and 197 deletions
|
|
@ -6,13 +6,16 @@ from . import cache
|
|||
from .text import find_re
|
||||
from .utils import json, ET
|
||||
|
||||
|
||||
def get_embed_code(url, maxwidth=None, maxheight=None):
|
||||
embed = {}
|
||||
header = cache.get_headers(url)
|
||||
if header.get('content-type', '').startswith('text/html'):
|
||||
html = cache.read_url(url)
|
||||
json_oembed = filter(lambda l: 'json+oembed' in l, re.compile('<link.*?>').findall(html))
|
||||
xml_oembed = filter(lambda l: 'xml+oembed' in l, re.compile('<link.*?>').findall(html))
|
||||
links = re.compile('<link.*?>').findall(html)
|
||||
json_oembed = [l for l in links if 'json+oembed' in l]
|
||||
xml_oembed = [l for l in links if 'xml+oembed' in l]
|
||||
|
||||
if json_oembed:
|
||||
oembed_url = find_re(json_oembed[0], 'href="(.*?)"')
|
||||
if maxwidth:
|
||||
|
|
@ -21,7 +24,7 @@ def get_embed_code(url, maxwidth=None, maxheight=None):
|
|||
oembed_url += '&maxheight=%d' % maxheight
|
||||
embed = json.loads(cache.read_url(oembed_url))
|
||||
elif xml_oembed:
|
||||
oembed_url = find_re(json_oembed[0], 'href="(.*?)"')
|
||||
oembed_url = find_re(xml_oembed[0], 'href="(.*?)"')
|
||||
if maxwidth:
|
||||
oembed_url += '&maxwidth=%d' % maxwidth
|
||||
if maxheight:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue