mirror of
https://github.com/maubot/rss.git
synced 2025-02-14 14:02:04 -05:00
Add support for JSON feed version 1.1
This commit is contained in:
parent
f96b2202b0
commit
334acf141e
@ -151,9 +151,8 @@ class RSSBot(Plugin):
|
||||
elif url is not None:
|
||||
raise ValueError("Only one of feed or url must be set")
|
||||
resp = await self.http.get(feed.url)
|
||||
# No need to check for vendor prefixes and such, the JSON feed spec requires
|
||||
# the mime type to be application/json
|
||||
if resp.headers["Content-Type"].startswith("application/json"):
|
||||
ct = resp.headers["Content-Type"].split(";")[0].strip()
|
||||
if ct == "application/json" or ct == "application/feed+json":
|
||||
return await self._parse_json(feed, resp)
|
||||
else:
|
||||
return await self._parse_rss(feed, resp)
|
||||
@ -162,7 +161,8 @@ class RSSBot(Plugin):
|
||||
async def _parse_json(cls, feed: Feed, resp: aiohttp.ClientResponse
|
||||
) -> Tuple[Feed, Iterable[Entry]]:
|
||||
content = await resp.json()
|
||||
if content["version"] != "https://jsonfeed.org/version/1":
|
||||
if content["version"] not in ("https://jsonfeed.org/version/1",
|
||||
"https://jsonfeed.org/version/1.1"):
|
||||
raise ValueError("Unsupported JSON feed version")
|
||||
if not isinstance(content["items"], list):
|
||||
raise ValueError("Feed is not a valid JSON feed (items is not a list)")
|
||||
|
Loading…
x
Reference in New Issue
Block a user