From a6dd9278600aad57ec0b629c2d352b8fa09e87e2 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 6 Sep 2022 23:12:49 +0700 Subject: [PATCH] fix channel extraction to catch all alerts, #312 --- tubearchivist/home/src/index/channel.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tubearchivist/home/src/index/channel.py b/tubearchivist/home/src/index/channel.py index 34e4adc7..520b1669 100644 --- a/tubearchivist/home/src/index/channel.py +++ b/tubearchivist/home/src/index/channel.py @@ -73,13 +73,14 @@ class ChannelScraper: def _is_deactivated(self): """check if channel is deactivated""" - alert_text = "This channel does not exist." alerts = self.yt_json.get("alerts") - if alerts and alert_text in str(alerts): - print(f"{self.channel_id}: {alert_text}") - return True + if not alerts: + return False - return False + for alert in alerts: + alert_text = alert["alertRenderer"]["text"]["simpleText"] + print(f"{self.channel_id}: failed to extract, {alert_text}") + return True def _parse_channel_main(self): """extract maintab values from scraped channel json data""" @@ -226,8 +227,8 @@ class YoutubeChannel(YouTubeItem): self.json_data.update( { - "channel_subs": content["channel_follower_count"], - "channel_description": content["description"], + "channel_subs": content.get("channel_follower_count", 0), + "channel_description": content.get("description", False), } )