1
0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2024-11-21 23:27:29 +00:00

Gracefully fail on feed fetch for invalid channel

This commit is contained in:
Cadence Ember 2020-12-06 15:39:28 +13:00
parent 554cd8cc3a
commit 10f8009101
No known key found for this signature in database
GPG Key ID: BC1C2C61CF521B17

View File

@ -127,7 +127,13 @@ def extract_channel_latest(ucid):
return channel_latest_cache[ucid] return channel_latest_cache[ucid]
with requests.get("https://www.youtube.com/feeds/videos.xml?channel_id={}".format(ucid)) as r: with requests.get("https://www.youtube.com/feeds/videos.xml?channel_id={}".format(ucid)) as r:
r.raise_for_status() if r.status_code == 404:
cherrypy.response.status = 404
return {
"error": "Channel does not exist.",
"identifier": "NOT_FOUND"
}
feed = ET.fromstring(r.content) feed = ET.fromstring(r.content)
author_container = feed.find("{http://www.w3.org/2005/Atom}author") author_container = feed.find("{http://www.w3.org/2005/Atom}author")
author = author_container.find("{http://www.w3.org/2005/Atom}name").text author = author_container.find("{http://www.w3.org/2005/Atom}name").text
@ -171,8 +177,8 @@ def extract_channel_latest(ucid):
"error": "YouTube did not provide published dates for any feed items. This is usually temporary - refresh in a few minutes.", "error": "YouTube did not provide published dates for any feed items. This is usually temporary - refresh in a few minutes.",
"identifier": "PUBLISHED_DATES_NOT_PROVIDED" "identifier": "PUBLISHED_DATES_NOT_PROVIDED"
} }
else:
with channel_latest_cache_lock:
channel_latest_cache[ucid] = results
return results with channel_latest_cache_lock:
channel_latest_cache[ucid] = results
return results