support more XML feed types; support relative path to XML feed
This commit is contained in:
parent
85f1e9bc96
commit
8ba82c6373
2 changed files with 23 additions and 9 deletions
|
@ -2,9 +2,12 @@ import bleach
|
||||||
from .extensions import db
|
from .extensions import db
|
||||||
|
|
||||||
|
|
||||||
bleach.ALLOWED_TAGS += ['a', 'img', 'p', 'br', 'marquee', 'blink']
|
bleach.ALLOWED_TAGS += ['a', 'img', 'p', 'br', 'marquee', 'blink',
|
||||||
|
'audio', 'video']
|
||||||
bleach.ALLOWED_ATTRIBUTES.update({
|
bleach.ALLOWED_ATTRIBUTES.update({
|
||||||
'img': ['src', 'alt', 'title']
|
'img': ['src', 'alt', 'title'],
|
||||||
|
'audio': ['preload', 'controls', 'src'],
|
||||||
|
'video': ['preload', 'controls', 'src'],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -171,15 +171,22 @@ def find_possible_feeds(origin):
|
||||||
resp = requests.get(origin)
|
resp = requests.get(origin)
|
||||||
|
|
||||||
feeds = []
|
feeds = []
|
||||||
|
|
||||||
xml_feed_types = [
|
xml_feed_types = [
|
||||||
'application/rss+xml',
|
'application/rss+xml',
|
||||||
'application/atom+xml',
|
'application/atom+xml',
|
||||||
'application/rdf+xml',
|
'application/rdf+xml',
|
||||||
|
'application/xml',
|
||||||
|
]
|
||||||
|
xml_mime_types = xml_feed_types + [
|
||||||
|
'text/xml',
|
||||||
|
'text/rss+xml',
|
||||||
|
'text/atom+xml',
|
||||||
]
|
]
|
||||||
|
|
||||||
content_type = resp.headers['content-type']
|
content_type = resp.headers['content-type']
|
||||||
content_type = content_type.split(';', 1)[0].strip()
|
content_type = content_type.split(';', 1)[0].strip()
|
||||||
if content_type in xml_feed_types:
|
if content_type in xml_mime_types:
|
||||||
feeds.append({
|
feeds.append({
|
||||||
'origin': origin,
|
'origin': origin,
|
||||||
'feed': origin,
|
'feed': origin,
|
||||||
|
@ -191,15 +198,19 @@ def find_possible_feeds(origin):
|
||||||
soup = bs4.BeautifulSoup(resp.text)
|
soup = bs4.BeautifulSoup(resp.text)
|
||||||
for link in soup.find_all('link', {'rel': 'alternate'}):
|
for link in soup.find_all('link', {'rel': 'alternate'}):
|
||||||
if link.get('type') in xml_feed_types:
|
if link.get('type') in xml_feed_types:
|
||||||
|
feed_url = urllib.parse.urljoin(origin, link.get('href'))
|
||||||
feeds.append({
|
feeds.append({
|
||||||
'origin': origin,
|
'origin': origin,
|
||||||
'feed': link.get('href'),
|
'feed': feed_url,
|
||||||
'type': 'xml',
|
'type': 'xml',
|
||||||
})
|
})
|
||||||
feeds.append({
|
|
||||||
'origin': origin,
|
hfeed = mf2util.interpret_feed(mf2py.parse(doc=resp.text), origin)
|
||||||
'feed': origin,
|
if hfeed.get('entries'):
|
||||||
'type': 'html',
|
feeds.append({
|
||||||
})
|
'origin': origin,
|
||||||
|
'feed': origin,
|
||||||
|
'type': 'html',
|
||||||
|
})
|
||||||
|
|
||||||
return feeds
|
return feeds
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue