mirror of
https://git.sr.ht/~cadence/NewLeaf
synced 2024-11-25 00:47:29 +00:00
Detect channels that do not exist
If error alerts exist, they will be logged. But it is reasonable to assume that not all errors will be fatal, so we don't necessarily quit parsing if we find one. This also normalises the text error of the /latest response for a missing channel, without changing its identifier.
This commit is contained in:
parent
50a4b7af45
commit
57b0a88a2e
@ -22,6 +22,16 @@ def extract_channel(ucid):
|
|||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
yt_initial_data = extract_yt_initial_data(r.content.decode("utf8"))
|
yt_initial_data = extract_yt_initial_data(r.content.decode("utf8"))
|
||||||
|
|
||||||
|
for alert in yt_initial_data.get("alerts", []):
|
||||||
|
alert_text = combine_runs(alert["alertRenderer"]["text"])
|
||||||
|
if alert_text == "This channel does not exist.":
|
||||||
|
return {
|
||||||
|
"error": alert_text,
|
||||||
|
"identifier": "NOT_FOUND"
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
print("Seen alert text '{}'".format(alert_text))
|
||||||
|
|
||||||
header = yt_initial_data["header"]["c4TabbedHeaderRenderer"] if "c4TabbedHeaderRenderer" in yt_initial_data["header"] else {}
|
header = yt_initial_data["header"]["c4TabbedHeaderRenderer"] if "c4TabbedHeaderRenderer" in yt_initial_data["header"] else {}
|
||||||
channel_metadata = yt_initial_data["metadata"]["channelMetadataRenderer"]
|
channel_metadata = yt_initial_data["metadata"]["channelMetadataRenderer"]
|
||||||
|
|
||||||
@ -146,7 +156,7 @@ def extract_channel_latest(ucid):
|
|||||||
if r.status_code == 404:
|
if r.status_code == 404:
|
||||||
cherrypy.response.status = 404
|
cherrypy.response.status = 404
|
||||||
return {
|
return {
|
||||||
"error": "Channel does not exist.",
|
"error": "This channel does not exist.",
|
||||||
"identifier": "NOT_FOUND"
|
"identifier": "NOT_FOUND"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user