deactivate non existing channels on reindex

This commit is contained in:
simon 2022-07-12 11:41:03 +07:00
parent 8cca09e0ac
commit 91bccfd057
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 17 additions and 0 deletions

View File

@ -37,6 +37,9 @@ class ChannelScraper:
"""main method to return channel dict"""
self.get_soup()
self._extract_yt_json()
if self._is_deactivated():
return False
self._parse_channel_main()
self._parse_channel_meta()
return self.json_data
@ -68,6 +71,16 @@ class ChannelScraper:
json_raw = script_content.rstrip(";</script>")
self.yt_json = json.loads(json_raw)
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
return False
def _parse_channel_main(self):
"""extract maintab values from scraped channel json data"""
main_tab = self.yt_json["header"]["c4TabbedHeaderRenderer"]

View File

@ -195,6 +195,10 @@ class Reindex:
subscribed = channel.json_data["channel_subscribed"]
overwrites = channel.json_data.get("channel_overwrites", False)
channel.get_from_youtube()
if not channel.json_data:
channel.deactivate()
return
channel.json_data["channel_subscribed"] = subscribed
if overwrites:
channel.json_data["channel_overwrites"] = overwrites