From 57b0a88a2e4af22ed6003a9b79f4ca7711317a9e Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sun, 2 May 2021 01:20:53 +1200 Subject: [PATCH] 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. --- extractors/channel.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/extractors/channel.py b/extractors/channel.py index 151d211..fb8ccea 100644 --- a/extractors/channel.py +++ b/extractors/channel.py @@ -22,6 +22,16 @@ def extract_channel(ucid): r.raise_for_status() 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 {} channel_metadata = yt_initial_data["metadata"]["channelMetadataRenderer"] @@ -146,7 +156,7 @@ def extract_channel_latest(ucid): if r.status_code == 404: cherrypy.response.status = 404 return { - "error": "Channel does not exist.", + "error": "This channel does not exist.", "identifier": "NOT_FOUND" }